I was wondering what is the native way to adjust the brightness in Windows?
By native, I mean the method that also displays the brightness overlay in the top left corner in Windows 8, 8.1, and 10, as if the special brightness keys have been pressed.
I was looking all over the Internet for this, but some solutions that do work, adjust the brightness, but no overlay is shown. Any idea? Is there something like
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
which turns off the monitor, but for brightness, that can be used from C++? Or C#? Thanks.
Update: here is the sample code.
HMONITOR hMonitor = NULL;
DWORD cPhysicalMonitors;
LPPHYSICAL_MONITOR pPhysicalMonitors = NULL;
// Get the monitor handle.
hMonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY);
// Get the number of physical monitors.
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(
hMonitor,
&cPhysicalMonitors
);
if (bSuccess)
{
// Allocate the array of PHYSICAL_MONITOR structures.
pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(
cPhysicalMonitors * sizeof(PHYSICAL_MONITOR));
if (pPhysicalMonitors != NULL)
{
// Get the array.
bSuccess = GetPhysicalMonitorsFromHMONITOR(
hMonitor, cPhysicalMonitors, pPhysicalMonitors);
// Use the monitor handles (not shown).
DWORD pdwMinimumBrightness = 0;
DWORD pdwCurrentBrightness = 0;
DWORD pdwMaximumBrightness = 0;
DWORD dwMonitorCapabilities = 0;
DWORD dwSupportedColorTemperatures = 0;
bSuccess = GetMonitorCapabilities(pPhysicalMonitors, &dwMonitorCapabilities, &dwSupportedColorTemperatures);
cout << bSuccess << endl;
// Close the monitor handles.
bSuccess = DestroyPhysicalMonitors(
cPhysicalMonitors,
pPhysicalMonitors);
// Free the array.
free(pPhysicalMonitors);
}
}
cout << bSuccess
always writes 0 in terminal.
GetMonitorCapabilities
fails with error -1071241854 (0xC0262582: "An error occurred while transmitting data to the device on the I2C bus."). Then how do the brightness keys on my computer work?
User contributions licensed under CC BY-SA 3.0