我将使用什么 API 调用来更改笔记本电脑 (.NET) 的亮度?

发布于 2024-07-10 01:45:45 字数 180 浏览 9 评论 0原文

我在索尼笔记本电脑上安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

Saygoodbye 2024-07-17 01:45:45

我查找了 约翰Rudy 在 MSDN 中链接到 WmiSetBrightness 并发布了注意

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”以避免资源泄漏。

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

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

心头的小情儿 2024-07-17 01:45:45

这仅适用于 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.

橙味迷妹 2024-07-17 01:45:45

据我所知,没有用于此目的的托管(.NET)API。 但是,对于 Vista,可以通过互操作使用非托管 API。 请参阅 MSDN:监视器配置 APIWmiSetBrightness

可能有一些管理方法可以调用 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. :)

诗酒趁年少 2024-07-17 01:45:45

这里只是集思广益......在笔记本电脑上,您可以使用键盘上的一些组合键来更改亮度。 如果您只想使其变暗/变亮而不必将其设置为特定值,则应该可以发送这些按键。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文