我将使用什么 API 调用来更改笔记本电脑 (.NET) 的亮度? [英] What API call would I use to change brightness of laptop (.NET)?

查看:30
本文介绍了我将使用什么 API 调用来更改笔记本电脑 (.NET) 的亮度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Sony 笔记本电脑上安装了 Windows Server 2008,但亮度控制不起作用.我想写一个程序来允许我改变它.

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.

目前我要做的就是打开电源控制面板,点击高级设置,然后通过大量的 UAC 框进行战斗,任何人看着我一定会认为我完全疯了.

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.

我只是想要一个简单的小程序来完成,但我不知道要调用什么 API

I just want a simple little program to do it but i dont know what API to call

推荐答案

我查了一下 John RudyWmiSetBrightness 在 MSDN 中并想出了这个:

I looked up John Rudy's link to WmiSetBrightness in MSDN and came up with this:

ManagementClass mclass = new ManagementClass("WmiMonitorBrightnessMethods");
mclass.Scope = new ManagementScope(@"\\.\root\wmi");
ManagementObjectCollection instances = mclass.GetInstances();

// I assume you get one instance per monitor
foreach(ManagementObject instance in instances)
{
    ulong timeout = 1; // in seconds
    ushort brightness = 50; // in percent
    object[] args = new object[] { timeout, brightness };
    instance.InvokeMethod("WmiSetBrightness", args);
}

注意:ManagementClassManagementObjectCollectionManagementObject 都实现了IDisposable.您应该调用 Dispose() 或使用using"以避免泄漏资源.

Note: ManagementClass, ManagementObjectCollection, and ManagementObject all implement IDisposable. You should call Dispose() or use "using" to avoid leaking resources.

这篇关于我将使用什么 API 调用来更改笔记本电脑 (.NET) 的亮度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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