Check if the display is turned off using Windows Power Management

How can I programmatically check in Windows 7 and XP if "Windows Power Management" turned off the display? (If I can get the event, it will be even better.)

+7
source share
3 answers

I do not think that this can be done for XP. Windows 7 has all sorts of goodies related to power management. The Windows API Code Pack is a set of managed wrappers that can be called from C # or VB and that display Windows paradigms (e.g., event receivers, Windows messages, and function pointers) in .NET (e.g., delegates and events). From the Power Management demo that comes with the code package, here's some code:

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:

Windows API Code Package Links: Windows API Code Code: Where is it?

If you want to use it as indicated in this post, check this out: https://stackoverflow.com/a/316829/

+7
source

Your application will receive a WM_SYSCOMMAND message with SC_MONITORPOWER in wParam (wParam with 0xfff0 is required first). It will send a similar message when the screen saver (SC_SCREENSAVE). If your target does not allow the screen to turn off, you can return 0 to them, although this does not work when the user has a password.

+1
source
-5
source

All Articles