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/
Kate gregory
source share