Using Windows Power Management API to dim monitor

*爱你&永不变心* 提交于 2020-01-01 11:46:06

问题


I'm trying to do something that seems simple enough, I just want to have my program able to adjust the monitor brightness under certain conditions. So, I looked into the windows Power Management API and found some things that seemed like they would work for me. The core of the code I put together (basically, I referenced this) looks like this:

GUID *pPwrGUID;
GUID subGUID = GUID_VIDEO_SUBGROUP;
GUID BriGUID = GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS;

PowerGetActiveScheme(NULL, &pPwrGUID);
PowerWriteACValueIndex(NULL, pPwrGUID, &subGUID, &BriGUID, 0);

Which seems simple enough. The problem I'm having is that PowerWriteACValueIndex returns error code 2: File Not Found, which isn't making a lot of sense to me. I was thinking that the problem was just that I had a bad Index value (last param in the PowerWriteACValueIndex function), but changing the write to a read with PowerReadACValueIndex (to see if I could get a legitimate value) also returns a 2. I already checked and made sure that GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS is under GUID_VIDEO_SUBGROUP in the header file.

Only other info I can think of that may be helpful is that my WINVER is set to 0x0600 (vista).

Any ideas what could be going wrong here? It seems like it should be a pretty straightforward process but I'm not really having any luck. Thank you.


回答1:


Okay, got what I wanted working through some trial and error. Apparently GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS is not the correct thing to use and for some reason the functions won't work with it (even though it's in my header file under the subgroup). So, I'm not really sure at this point what the purpose of it is, but don't use it for this case.

What does work is the same function but using GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS. There's also GUID_DEVICE_POWER_POLICY_VIDEO_DIM_BRIGHTNESS if you want to change the brightness of the "dimmed" state.

Using this define instead, I get my desired behavior.



来源:https://stackoverflow.com/questions/14566830/using-windows-power-management-api-to-dim-monitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!