Trying to open display device handle to change brightness on Windows XP using C++

瘦欲@ 提交于 2019-12-02 17:54:03

问题


I am trying to write a C++/WinAPI code to change a monitor brightness. The code must be compatible with Windows XP so I can't use APIs like SetMonitorBrightness. So I thought to try out IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS but I can't seem to even get a device handle.

HANDLE hDevice = ::CreateFile(_T("\\\\.\\LCD"),
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    NULL,
    OPEN_EXISTING,
    0, NULL);
if(hDevice != INVALID_HANDLE_VALUE)
{
    //Do work here

    ::CloseHandle(hDevice);
}
else
{
    nOSErr = ::GetLastError();
    //Get code 2
}

I tried various combinations of GENERIC_READ, GENERIC_WRITE and FILE_SHARE_READ, FILE_SHARE_WRITE flags but I always get error code 2 when CreateFile is called.

So what am I doing wrong here?


回答1:


You know that not all devices support this API, right? Your laptop probably supports it because it allows software adjustment of its screen brightness, perhaps even with function keys on the keyboard. Your other machine (the one running Windows 7) probably doesn't support it, so calling CreateHandle with \\\\.\\LCD doesn't get you anything useful. It has nothing to do with the operating system and everything to do with the hardware and/or the video drivers.



来源:https://stackoverflow.com/questions/11874615/trying-to-open-display-device-handle-to-change-brightness-on-windows-xp-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!