繁体   English   中英

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

[英]How can I change the “Dim the display” and “Dimming display brightness” setting (Windows) from wihin my application?

我的应用程序已经能够设置显示器应关闭的超时时间,以及设置全部时间,并且通常还可以设置当前亮度。 Windows具有一项附加功能,该功能可在一段时间后使显示变暗(高级电源使用方案设置中的“在之后变暗显示”和“显示变暗亮度”)。

有谁知道如何在我的应用程序(它是C / C ++应用程序)中查询/设置“之后的调暗显示”和“显示调暗亮度”设置-如果可能的话,可以使用“纯” Windows API?

非常感谢。 您的Willi K.

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

#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...
}

当系统处于“开机状态”(例如笔记本电脑)时,此代码示例将更改设置。 要在系统“使用交流电源”时进行设置,只需将PowerWrite DC ValueIndex()替换为PowerWrite AC ValueIndex()。

暂无
暂无

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

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