On Windows only the focused application receives display power events via the WM_SYSCOMMAND message (with wParam set to SC_MONITORPOWER, and lParam representing the new power state).
On Windows Vista and later, any application can be notified of display power events by calling the RegisterPowerSettingNotification function, using the GUID_SESSION_DISPLAY_STATUS GUID.
Is there a way to achieve the same result on Windows XP, at application level (i.e not using code running at kernel mode)?
All you need to do is handle
WM_SYSCOMMAND. Options I can think of:Use
SetWindowsHookExfor this (withWH_CBT).Inject a DLL into every process which hooks CreateProcess and injects itself into all future processes, essentially hooking the entire system. The aforementioned DLL will then subclass all windows in the current process, and you can handle
WM_SYSMESSAGEfrom there.