我将使用什么 API 调用来更改笔记本电脑 (.NET) 的亮度?
我在索尼笔记本电脑上安装了 Windows Server 2008,但亮度控制不起作用。 我想编写一个程序来允许我更改它。
目前我要做的就是打开电源控制面板,单击高级设置,并与如此多的 UAC 框进行斗争,任何观看我的人一定认为我完全疯了。
我只是想要一个简单的小程序来完成它,但我不知道要调用什么API。
I have Windows Server 2008 installed on a Sony laptop and the brightness control doesn't work. I'd like to write a program to allow me to change it.
Currently what I have to do is open the Power control panel, click advanced settings, and fight through so many UAC boxes that anybody watching me must think I'm completely crazy.
I just want a simple little program to do it but I don't know what API to call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我查找了 约翰Rudy 在 MSDN 中链接到 WmiSetBrightness 并发布了注意
:
ManagementClass
、ManagementObjectCollection
和ManagementObject
都实现了IDisposable
。 您应该调用Dispose()
或使用“using
”以避免资源泄漏。I looked up John Rudy's link to WmiSetBrightness in MSDN and came up with this:
Note:
ManagementClass
,ManagementObjectCollection
, andManagementObject
all implementIDisposable
. You should callDispose()
or use "using
" to avoid leaking resources.这仅适用于 Vista:
http://msdn.microsoft.com/en-us /library/ms775232.aspx
在使用 SetMonitorBrightness 设置显示器的亮度之前,您需要使用 GetPhysicalMonitorsFromHMONITOR 识别显示器。 我怀疑以前没有人在 .net 中这样做过,所以您可能需要编写自己的互操作。 该 API 看起来并不是特别困难,因此您应该能够非常轻松地完成它。
This is vista only:
http://msdn.microsoft.com/en-us/library/ms775232.aspx
You need to identify the monitor with GetPhysicalMonitorsFromHMONITOR before setting its brightness with SetMonitorBrightness. I suspect nobody's done it before in .net so you'll probably need to write your own interop. The api doesn't appear to be particularly difficult so you should be able to do it pretty easily.
据我所知,没有用于此目的的托管(.NET)API。 但是,对于 Vista,可以通过互操作使用非托管 API。 请参阅 MSDN:监视器配置 API 和 WmiSetBrightness。
可能有一些管理方法可以调用 WmiSetBrightness 方法,但我不知道它们。
如果您使用的不是 Vista 或 Server 2008,您将陷入一个令人不愉快的世界:软件配置必须直接通过显示器驱动程序完成。 根据您上面提到的 UAC,我怀疑您的情况并非如此,但下一个人可能想知道。 :)
As far as I'm aware, there are no managed (.NET) APIs for this. However, for Vista, there are unmanaged APIs available via interop. See MSDN: Monitor Configuration APIs and WmiSetBrightness.
There may be managed ways of hitting the WmiSetBrightness method, but I'm not aware of them.
If you're not on Vista or Server 2008, you're in for a world of unpleasantness: The software configuration would have to be done directly through the monitor driver. Based on your mentioning UAC above, I suspect this isn't the case for you, but the next guy might want to know. :)
这里只是集思广益......在笔记本电脑上,您可以使用键盘上的一些组合键来更改亮度。 如果您只想使其变暗/变亮而不必将其设置为特定值,则应该可以发送这些按键。
Just a brainstormer here... On the laptop you can change the brightness using some key-kombinations on the keyboard. It should be possible to send those keyspresses If you just want to make it darker/lighter and not have to set it to a specific value.