使用 Windows 电源管理 API 调暗显示器 [英] Using Windows Power Management API to dim monitor

查看:26
本文介绍了使用 Windows 电源管理 API 调暗显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些看起来足够简单的事情,我只是想让我的程序能够在某些条件下调整显示器亮度.因此,我查看了 Windows 电源管理 API 并发现了一些似乎对我有用的东西.我放在一起的代码的核心(基本上,我参考了 this) 看起来像这样:

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

这看起来很简单.我遇到的问题是 PowerWriteACValueIndex 返回错误代码 2:找不到文件,这对我来说没有多大意义.我在想问题只是我有一个错误的 Index 值(PowerWriteACValueIndex 函数中的最后一个参数),但是将写入更改为使用 PowerReadACValueIndex 读取(以查看是否可以获得合法值)也会返回 2.我已经检查并确保 GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS 在头文件中的 GUID_VIDEO_SUBGROUP 下.

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.

我能想到的其他可能有用的信息是我的 WINVER 设置为 0x0600 (vista).

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.

推荐答案

好的,通过反复试验得到了我想要的结果.显然 GUID_VIDEO_CURRENT_MONITOR_BRIGHTNESS 不是正确的使用方法,并且由于某种原因,这些函数无法使用它(即使它在我的子组下的头文件中).所以,我现在不太确定它的目的是什么,但不要在这种情况下使用它.

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.

起作用的是相同的功能,但使用 GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS.如果您想更改变暗"状态的亮度,还有 GUID_DEVICE_POWER_POLICY_VIDEO_DIM_BRIGHTNESS.

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.

这篇关于使用 Windows 电源管理 API 调暗显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆