[英]How can I change the “Dim the display” and “Dimming display brightness” setting (Windows) from wihin my application?
My application is already able to set the timeout when display should turn off, as well as setting the all over, and also to set the current brightness in general. 我的应用程序已经能够设置显示器应关闭的超时时间,以及设置全部时间,并且通常还可以设置当前亮度。 Windows has an additional feature that dims the display after some time (the "Dim the display after" and "Display dimming brightness" in the advanced power scheme settings). Windows具有一项附加功能,该功能可在一段时间后使显示变暗(高级电源使用方案设置中的“在之后变暗显示”和“显示变暗亮度”)。
Does anybody knows how I can query/set the options "Dim display after" and "Display dimming brightness" settings from within my application (its a C/C++ application)- if possible by using "pure" Windows API? 有谁知道如何在我的应用程序(它是C / C ++应用程序)中查询/设置“之后的调暗显示”和“显示调暗亮度”设置-如果可能的话,可以使用“纯” Windows API?
Have much thanks in before. 非常感谢。 Yours Willi K. 您的Willi K.
Ron pointed me in the right direction. 罗恩向我指出了正确的方向。 Following code expample shows, how an application can control when the backlight should dim to a specific brightness level (error checking etc. has been omitted in order to make code more easy to understand). 以下代码示例显示,应用程序如何控制背光何时应调暗至特定的亮度级别(已省略了错误检查等,以使代码更易于理解)。
#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...
}
This code sample changes the settings when the system is "On battary" (eg a laptop). 当系统处于“开机状态”(例如笔记本电脑)时,此代码示例将更改设置。 To set the settings when the system is "On AC power", simply replace PowerWrite DC ValueIndex() by PowerWrite AC ValueIndex(). 要在系统“使用交流电源”时进行设置,只需将PowerWrite DC ValueIndex()替换为PowerWrite AC ValueIndex()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.