简体   繁体   English

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

[英]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.

相关问题 如何将stdout重定向到Windows应用程序中的某些可见显示? - How can I redirect stdout to some visible display in a Windows Application? 如何在Qt客户端应用程序中显示OSM磁贴? - How can I display my OSM tiles in Qt client application? 如何垂直更改河内塔楼的输出显示? - How can I change my hanoi tower output display vertically? 尝试打开显示设备句柄以使用C ++在Windows XP上更改亮度 - Trying to open display device handle to change brightness on Windows XP using C++ 如何更改C ++ Windows服务的显示名称? - How do I change the display name of a c++ windows service? 如何使用 imshow 在多个窗口中显示多个图像? - How can I use imshow to display multiple images in multiple windows? 是否有任何跨平台方法可以更改监视器显示的亮度/对比度? - Any cross-platform method to change the brightness/contrast of the monitor display? 如何将数组更改为字符串以在c ++中显示符号? - How can I change an array to a string to display symbols in c++? 如何从bash脚本捕获终端输出并将其显示在Qt UI中? - How can I capture terminal output from a bash script and display it in my Qt UI? 如何在Windows窗体应用程序中显示cv :: Mat? - How to display a cv::Mat in a Windows Form application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM