October 2nd, 2012, 03:05 AM
Is PBT_APMSUSPEND notification supposed to be sent out during forced sleep in XP?
I'm not sure if I'm reading documentation correctly, so I'd appreciate if someone could clarify.
I run the following API to put Windows XP SP3 into sleep (or standby mode) from a worker thread:
Then in the main thread, while processing window messages:
BOOL bForced = TRUE;
SetSuspendState(FALSE, bForced, FALSE);
So when SetSuspendState is called with request for a 'forced' sleep mode, the PBT_APMSUSPEND notification is never broadcast. Only if I set forced parameter to FALSE I receive it.
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if(message == WM_POWERBROADCAST)
if(wParam == PBT_APMSUSPEND)
AddLogMsg(_T("SUSPEND event received"));
else if(wParam == PBT_APMRESUMEAUTOMATIC)
AddLogMsg(_T("RESUME event received"));
//Do other processing
Any idea why?
PS. PBT_APMRESUMEAUTOMATIC is received in either case.
PS2. PBT_APMSUSPEND is always received when run on Windows Vista/7.
October 2nd, 2012, 05:45 AM
Re: Is PBT_APMSUSPEND notification supposed to be sent out during forced sleep in XP?
Guys, I made a short test project to illustrate the problem. (It's attached here as a MSVS 2008 solution.)
Also a couple of screenshots:
1. Invoking it as a non-forced sleep:
2. While keeping the first process alive, I start another one and perform forced sleep from it:
and this is where the logic breaks. As you can see, I not only miss my own notification of the system entering the sleep, but also other processes won't get it either.
So my original question, is it done by design? And if so, how can my process (local service) get notified of a system entering a sleep mode on a Windows XP system?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!