Check if display is turned off by windows power management

故事扮演 提交于 2019-12-22 04:48:34

问题


How can I programmatically check in Windows 7 and XP if 'windows power management' has turned off the display? (If I can receive an event, that would be even better.)


回答1:


I don't think it can be done for XP. In Windows 7 there are all kinds of goodies related to power management. 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:

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?

If you want use it just like is mentioned in this post check this: https://stackoverflow.com/a/27709672/846232




回答2:


Your application will get a WM_SYSCOMMAND message with SC_MONITORPOWER in wParam (make sure to and wParam with 0xfff0 first). It will send a similar message when the screen saver kicks in (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.




回答3:


I think you can use ServiceController! how to turn windows service on if its off. control it from webapplication



来源:https://stackoverflow.com/questions/6530968/check-if-display-is-turned-off-by-windows-power-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!