简体   繁体   English

尝试打开显示设备句柄以使用C ++在Windows XP上更改亮度

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

I am trying to write a C++/WinAPI code to change a monitor brightness. 我正在尝试编写C ++ / WinAPI代码来更改监视器的亮度。 The code must be compatible with Windows XP so I can't use APIs like SetMonitorBrightness. 该代码必须与Windows XP兼容,因此我不能使用SetMonitorBrightness之类的API。 So I thought to try out IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS but I can't seem to even get a device handle. 所以我想尝试一下IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS,但是我什至看不到设备句柄。

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. 我尝试了GENERIC_READ,GENERIC_WRITE和FILE_SHARE_READ,FILE_SHARE_WRITE标志的各种组合,但是在调用CreateFile时总是收到错误代码2。

So what am I doing wrong here? 那我在做什么错呢?

You know that not all devices support this API, right? 您知道并非所有设备都支持此API,对吗? 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. 您的另一台计算机(运行Windows 7的计算机)可能不支持它,因此使用\\\\\\\\.\\\\LCD调用CreateHandle不会给您带来任何帮助。 It has nothing to do with the operating system and everything to do with the hardware and/or the video drivers. 它与操作系统无关,与硬件和/或视频驱动程序无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM