Reputation: 6933
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)?
Upvotes: 8
Views: 1102
Reputation:
All you need to do is handle WM_SYSCOMMAND
. Options I can think of:
Use SetWindowsHookEx
for this (with WH_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_SYSMESSAGE
from there.
Upvotes: 2
Reputation: 5884
Can't you just handle the message WM_POWERBROADCAST in your WindowProc and once received, call GetSystemPowerStatus?
Upvotes: -1