From: dr on
I am trying to add suspend mode support to my application. I am getting the
PBT_APMQUERYSUSPEND and PBT_APMSUSPEND event notifications as expected.
According to MSDN "The system allows approximately 20 seconds for an
application to remove the WM_POWERBROADCAST message that is sending the
PBT_APMQUERYSUSPEND event from the application's message queue. If an
application does not remove the message from its queue in less then 20
seconds, the system will assume that the application is in a non-responsive
state, and that the application agrees to the sleep request. Applications
that do not process their message queues may have their operations
interrupted. After it removes the message from the message queue, an
application can take as much time as needed to perform any required
operations before entering the sleep state."

How do I remove the message from the queue? I've tried using the Win32
GetMessage() and PeekMessage() calls but it tells me there is no message to
retrieve. My end goal is to delay suspend as long as I need to clean-up any
outstanding work.

From: Kellie Fitton on
Hi,

You can use the following API to preventing the system from
entering the sleeping power state:

SetThreadExecutionState()

Also, you need to handle the following Windows message and handle
the power suspend event accordingly:

WM_POWERBROADCAST

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setthreadexecutionstate.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/wm_powerbroadcast.asp

Hope these suggestions helps,

Kellie.

From: dr on
Thanks but I do not want to prevent the system from entering the sleeping
power state, I want to delay it once I've received notification that it is
entering the sleeping power state - according to the documentation I pasted
in my original post from Microsoft I should be able to.


"Kellie Fitton" wrote:

> Hi,
>
> You can use the following API to preventing the system from
> entering the sleeping power state:
>
> SetThreadExecutionState()
>
> Also, you need to handle the following Windows message and handle
> the power suspend event accordingly:
>
> WM_POWERBROADCAST
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setthreadexecutionstate.asp
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/wm_powerbroadcast.asp
>
> Hope these suggestions helps,
>
> Kellie.
>
>
From: Skywing on
BTW, in Windows Vista and beyond, you are unable to delay or otherwise block
power operations in response to those messages. In light of this, I would
reconsider your approach and see if you can find a better way without having
to delay those events, because you will break with new OS releases.

"dr" <dr(a)discussions.microsoft.com> wrote in message
news:1537352D-FBEA-4F12-8228-1BAC5205AA30(a)microsoft.com...
> Thanks but I do not want to prevent the system from entering the sleeping
> power state, I want to delay it once I've received notification that it is
> entering the sleeping power state - according to the documentation I
> pasted
> in my original post from Microsoft I should be able to.
>
>
> "Kellie Fitton" wrote:
>
>> Hi,
>>
>> You can use the following API to preventing the system from
>> entering the sleeping power state:
>>
>> SetThreadExecutionState()
>>
>> Also, you need to handle the following Windows message and handle
>> the power suspend event accordingly:
>>
>> WM_POWERBROADCAST
>>
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setthreadexecutionstate.asp
>>
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/wm_powerbroadcast.asp
>>
>> Hope these suggestions helps,
>>
>> Kellie.
>>
>>


From: Pavel A. on
"dr" wrote:
> I am trying to add suspend mode support to my application. I am getting the
> PBT_APMQUERYSUSPEND and PBT_APMSUSPEND event notifications as expected.
> According to MSDN "The system allows approximately 20 seconds for an
> application to remove the WM_POWERBROADCAST message that is sending the
> PBT_APMQUERYSUSPEND event from the application's message queue. If an
> application does not remove the message from its queue in less then 20
> seconds, the system will assume that the application is in a non-responsive
> state, and that the application agrees to the sleep request. Applications
> that do not process their message queues may have their operations
> interrupted. After it removes the message from the message queue, an
> application can take as much time as needed to perform any required
> operations before entering the sleep state."
>
> How do I remove the message from the queue?

This can be surprise for you, but when the app received the
PBT... messages, it *aready* has removed them from the queue :)
Now just take your time and do whatever you need...

--PA

 |  Next  |  Last
Pages: 1 2
Prev: Hook Windows Events
Next: Detours and Internet Explorer