如何从我的应用程序中更改“调暗显示”和“调暗显示亮度”设置(Windows)?

时间:2018-03-11 16:16:19

标签: c++ c windows winapi

我的应用程序已经能够设置关闭显示时的超时,以及设置全部,以及一般设置当前亮度。 Windows还有一项功能可在一段时间后使显示屏变暗(高级电源方案设置中的“显示屏后面的显示屏变暗”和“显示调光亮度”)。

有没有人知道如何在我的应用程序(它的C / C ++应用程序)中查询/设置选项“Dim display after”和“Display dimming brightness”设置 - 如果可能的话,使用“纯”Windows API? / p>

以前非常感谢。 你的Willi K。

1 个答案:

答案 0 :(得分:0)

罗恩指出我正确的方向。下面的代码示例显示,应用程序如何控制背光应调暗到特定亮度级别(为了使代码更容易理解,省略了错误检查等)。

#include <iniitguid.h>    // Seems to be uncluded before Windows.h for some reason...
#include <windows.h>
#include <powrprof.h>

static const GUID GuidPwrVideoIf = GUID_VIDEO_SUBGROUP;
static const GUID GuidPwrDimTimeout = GUID_VIDEO_DIM_TIMEOUT;
static const GUID GuidPwrDimBrightness = GUID_DEVICE_POWER_POLICY_VIDEO_DIM_BRIGHTNESS;

void setBacklightDimming(DWORD timeOut, DWORD dimmedBrightness)
{
    DWORD ret;
    GUID *pGuidPwrActiveSheme;    

    // Attach to the active power scheme
    ret = PowerGetActiveScheme(NULL, &pGuidPwrActiveSheme);

    // Set the timeout that will elapse before the display will dim
    ret = PowerWriteDCValueIndex(NULL, pGuidPwrActiveSheme, &GuidPwrVideoIf, &GuidPwrDimTimeout, timeOut);

    // Set the dimmed brightness level
    PowerWriteDCValueIndex(NULL, pGuidPwrActiveSheme, &GuidPwrVideoIf, &GuidPwrDimBrightness, dimmedBrightness);

    // Apply the new setings immediately
    retVal = PowerSetActiveScheme(NULL, pGuidPwrActiveSheme);

    // Go on with whatever you want to do...
}

此代码示例在系统“On battary”(例如笔记本电脑)时更改设置。要在系统处于“交流电源”时设置设置,只需用PowerWrite AC ValueIndex()替换PowerWrite DC ValueIndex()。