I am trying to set the brightness on a Windows 10 machine. The display doesn't seem to support setMonitorBrightness
, and setDeviceGammaRamp
alters the gamma, white point etc, so I would try not to use it.
I am trying to get this to work using IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
control. When I get the monitor handle using CreateFile()
, I check if the handle is invalid and it is fine. But I get ERROR_INVALID_HANDLE
(error 6) when I call DeviceIoControl()
with IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
.
typedef struct _DISPLAY_BRIGHTNESS {
UCHAR ucDisplayPolicy;
UCHAR ucACBrightness;
UCHAR ucDCBrightness;
} DISPLAY_BRIGHTNESS, *PDISPLAY_BRIGHTNESS;
DISPLAY_BRIGHTNESS _displayBrightness;
_displayBrightness.ucDisplayPolicy = 0;
_displayBrightness.ucACBrightness = 0; //for testing purposes
_displayBrightness.ucDCBrightness = 0;
DWORD ret = NULL;
OVERLAPPED olp;
DWORD nOutBufferSize = sizeof(_displayBrightness);
HANDLE h = CreateFile(L"\\\\.\\LCD",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0, NULL);
if (h == INVALID_HANDLE_VALUE) {
//Does not reach here
return false;
}
if (!DeviceIoControl(h, IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS, (DISPLAY_BRIGHTNESS *)&_displayBrightness, nOutBufferSize, NULL, 0, &ret, &olp))
{
// GetLastError() returns error code 6 - Invalid handle
return false;
}
Also, should I be using CreateFile()
to get the monitor handle, or can I call MonitorFromWindow(nullptr, MONITOR_DEFAULTTOPRIMARY)
instead?