Click to Rate and Give Feedback
MSDN
MSDN Library
System Shutdown
 WM_ENDSESSION Message

  Switch on low bandwidth view
WM_ENDSESSION Message

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.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc( 
  HWND hwnd,      // handle to window 
  UINT uMsg,      // message identifier 
  WPARAM wParam,  // end-session option 
  LPARAM lParam   // logoff option
);

Parameters

hwnd

A handle to the window.

uMsg

The WM_ENDSESSION identifier.

wParam

If the session is being ended, this parameter is TRUE; the session can end any time after all applications have returned from processing this message. Otherwise, it is FALSE.

lParam

This parameter can be one or more of the following values. If this parameter is 0, the system is shutting down or restarting (it is not possible to determine which event is occurring).

ValueMeaning
ENDSESSION_CLOSEAPP
0x1

If wParam is TRUE, the application must shut down. Any data should be saved automatically without prompting the user (for more information, see Remarks). The Restart Manager sends this message when the application is using a file that needs to be replaced, when it must service the system, or when system resources are exhausted. The application will be restarted if it has registered for restart using the RegisterApplicationRestart function. For more information, see Guidelines for Applications.

If wParam is FALSE, the application should not shut down.

ENDSESSION_CRITICAL
0x40000000

The application is forced to shut down.

ENDSESSION_LOGOFF
0x80000000

The user is logging off. For more information, see Logging Off.

 

Note that this parameter is a bit mask. To test for this value, use a bit-wise operation; do not test for equality.

Return Value

If an application processes this message, it should return zero.

Remarks

Applications that have unsaved data could save the data to a temporary location and restore it the next time the application starts. It is recommended that applications save their data and state frequently; for example, automatically save data between save operations initiated by the user to reduce the amount of data to be saved at shutdown.

The application need not call the DestroyWindow or PostQuitMessage function when the session is ending.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinUser.h (include Windows.h)

See Also

Logging Off
Shutting Down
DestroyWindow
PostQuitMessage
SetProcessShutdownParameters
WM_QUERYENDSESSION

Send comments about this topic to Microsoft

Build date: 6/4/2009

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Value      Đonny   |   Edit   |   Show History
WM_ENDSESSION = &H16
<Flags()> Public Enum WM_ENDSESSION As Integer
<EditorBrowsable(EditorBrowsableState.Advanced)> Zero = 0
ENDSESSION_CLOSEAPP = 1
ENDSESSION_LOGOFF = &H80000000
End Enum
How WM_ENDSESSION terminates the process      Gideon7   |   Edit   |   Show History

The MSDN article above states "The application need not call the DestroyWindow or PostQuitMessage function when the session is ending." When your msgproc returns from handing WM_ENDSESSION you have only a few seconds to clean up and exit your program. Otherwise the system will nuke your process with TerminateProcess.

If your app reacts badly to TerminateProcess then you need to ignore the MSDN article's advice and execute your normal close sequence: DestroyWindow, PostQuitMessage, etc. This is required if you want to exit gracefully.

The system does not send any messages to gracefully close your app (such as WM_CLOSE, WM_DESTROY, or WM_QUIT). You must do it yourself.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker