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:
Code:
BOOL bForced = TRUE;
SetSuspendState(FALSE, bForced, FALSE);
Then in the main thread, while processing window messages:
Code:
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
}
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.
Any idea why?
PS. PBT_APMRESUMEAUTOMATIC is received in either case.
PS2. PBT_APMSUSPEND is always received when run on Windows Vista/7.
3 Attachment(s)
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:
Attachment 30399
2. While keeping the first process alive, I start another one and perform forced sleep from it:
Attachment 30401
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?