简体   繁体   English

检查显示是否被 windows 电源管理关闭

[英]Check if display is turned off by windows power management

How can I programmatically check in Windows 7 and XP if 'windows power management' has turned off the display?如果“Windows 电源管理”已关闭显示屏,我如何以编程方式检查 Windows 7 和 XP? (If I can receive an event, that would be even better.) (如果我能收到一个事件,那就更好了。)

I don't think it can be done for XP.我不认为它可以为 XP 完成。 In Windows 7 there are all kinds of goodies related to power management.在 Windows 7 中有各种与电源管理相关的好东西。 The Windows API Code Pack is a set of managed wrappers that are simple to call from C# or VB and that map Windows paradigms (like event sinks, Windows messages and function pointers) into .NET ones (like delegates and events.) From the Power Management Demo that comes with the code pack, here is some code you might like: The Windows API Code Pack is a set of managed wrappers that are simple to call from C# or VB and that map Windows paradigms (like event sinks, Windows messages and function pointers) into .NET ones (like delegates and events.) From the Power Management代码包附带的演示,这里有一些你可能喜欢的代码:

using Microsoft.WindowsAPICodePack.ApplicationServices;

// . . .
        PowerManager.IsMonitorOnChanged += new EventHandler(MonitorOnChanged);
// . . .
    void MonitorOnChanged(object sender, EventArgs e)
    {
        settings.MonitorOn = PowerManager.IsMonitorOn;
        AddEventMessage(string.Format("Monitor status changed (new status: {0})", PowerManager.IsMonitorOn ? "On" : "Off"));
    }

Edit:编辑:

Links to Windows API Code Pack: Windows API Code Pack: Where is it?链接到 Windows API 代码包: Windows API 代码包:它在哪里?

If you want use it just like is mentioned in this post check this: https://stackoverflow.com/a/27709672/846232如果您想像这篇文章中提到的那样使用它,请检查: https://stackoverflow.com/a/27709672/846232

Your application will get a WM_SYSCOMMAND message with SC_MONITORPOWER in wParam (make sure to and wParam with 0xfff0 first).您的应用程序将在 wParam 中收到一条带有 SC_MONITORPOWER 的 WM_SYSCOMMAND 消息(确保首先使用 0xfff0 和 wParam)。 It will send a similar message when the screen saver kicks in (SC_SCREENSAVE).当屏幕保护程序启动时(SC_SCREENSAVE),它将发送类似的消息。 If your goal is preventing the screen to turn off you can return 0 on these, although that doesn't work when the user has a password set.如果您的目标是阻止屏幕关闭,您可以在这些上返回 0,尽管当用户设置了密码时这不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM