简体   繁体   中英

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).

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?

Have much thanks in before. Yours 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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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