在Windows中以原生方式调整亮度

时间:2016-06-07 13:30:29

标签: c# c++ windows winapi brightness

我想知道在Windows中调整亮度的原生方法是什么?

原生,我的意思是在Windows 8,8.1和10的左上角也显示亮度叠加的方法,就好像已按下特殊亮度键一样。

我在互联网上寻找这个,但是一些有效的解决方案,调整亮度,但没有显示叠加。任何的想法?有什么像

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

会关闭显示器,但是对于亮度,可以使用C ++吗?还是C#?感谢。

更新:这是示例代码。

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总是在终端写入0。

GetMonitorCapabilities失败,错误-1071241854(0xC0262582:&#34;在I2C总线上向设备传输数据时发生错误。&#34; )。然后我的电脑上的亮度键如何工作?

0 个答案:

没有答案