我试图通过Windows API获取/设置显示器的亮度级别.我已经尝试过低级监视器配置功能和高级监视器配置功能,但它们似乎都在同一个地方出现故障.在这两种情况下,我都没有问题获得HMONITOR句柄并从HMONITOR获取物理监视器句柄,但是一旦我尝试查询DDC/CI功能,我就会收到错误说" An error occurred while transmitting data to the device on the I2C bus."
导致此错误的特定函数是高级函数的GetMonitorCapabilities和低级函数的GetCapabilitiesStringLength.它们都会导致同样的错误.
这让我相信可能我的显示器不支持DDC/CI,但我知道我的笔记本电脑的显示器亮度可以通过控制面板进行更改,因此必须通过软件以某种方式进行控制.我也可以成功地使用WMI类在PowerShell脚本中得到/上描述设置亮度此页面.我读过的大多数内容都表明大多数现代笔记本电脑屏幕都支持DDC/CI.
有没有办法找出导致此错误的原因或获取有关它的更多信息?我目前正在Windows 7的Visual Studio 2013中使用C++.如果我不能使用当前的方法,我可能在我的C++程序中使用WMI,但我想我会先问这里.
这是我目前的代码:
#include "stdafx.h"
#include <windows.h>
#include <highlevelmonitorconfigurationapi.h>
#include <lowlevelmonitorconfigurationapi.h>
#include <physicalmonitorenumerationapi.h>
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD minBrightness, curBrightness, maxBrightness;
HWND curWin = GetConsoleWindow();
if (curWin == NULL) {
std::cout << "Problem getting a handle to the window." << std::endl;
return 1;
} …Run Code Online (Sandbox Code Playgroud)