SexyFast
asked on
Detecting Windows Shutdown
I'm writting a windows app, that has no UI, no windows, is not a service, and is not a console application.
How can I detect a windows shutdown so my application can perform a clean exit?
Example code is useful too.
Thanks in advance.
How can I detect a windows shutdown so my application can perform a clean exit?
Example code is useful too.
Thanks in advance.
WM_QUERYENDSESSION is only sent to apps which have a windows message loop. You need at least one (pseudo) window for that.
Why not make it a service? Then, SCM will call you by callback in case of a shutdown.
ASKER
Any example code for having a message loop?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-----
the thread which runs that loop will be blocked after that
-----
ignore that. PeekMessage only peeks as long as there are messages. you need a handling after loop so that the message loop was called again until you want to stop.
the thread which runs that loop will be blocked after that
-----
ignore that. PeekMessage only peeks as long as there are messages. you need a handling after loop so that the message loop was called again until you want to stop.
WM_QUERYENDSESSION
The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls the ExitWindows function. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.
and
WM_ENDSESSION
The WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending.