windows_programming_notes.nbk: Home | Index | Next Page: WM_QUERYNEWPALETTE | Previous Page: WM_QUERYDRAGICON


 WM_QUERYENDSESSION

The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.

After processing this message, the system sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message.

A window receives this message through its WindowProc function.

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

Parameters

Return Value

Applications should respect the user's intentions and return TRUE. By default, the DefWindowProc function returns TRUE for this message.

If shutting down would corrupt the system or media that is being burned, the application can return FALSE. However, it is good practice to respect the user's actions.

Remarks

When an application returns TRUE for this message, it receives the WM_ENDSESSION message, regardless of how the other applications respond to the WM_QUERYENDSESSION message. Each application should return TRUE or FALSE immediately upon receiving this message, and defer any cleanup operations until it receives the WM_ENDSESSION message.

Applications can display a user interface prompting the user for information at shutdown, however it is not recommended. After five seconds, the system displays information about the applications that are preventing shutdown and allows the user to terminate them. For example, Windows XP displays a dialog box, while Windows Vista displays a full screen with additional information about the applications blocking shutdown. If your application must block or postpone system shutdown, use the ShutdownBlockReasonCreate function. For more information, see Shutdown Changes for Windows Vista.

Console applications can use the SetConsoleCtrlHandler function to receive shutdown notification.

Service applications can use the RegisterServiceCtrlHandlerEx function to receive shutdown notifications in a handler routine.

Requirements


windows_programming_notes.nbk: Home | Index | Next Page: WM_QUERYNEWPALETTE | Previous Page: WM_QUERYDRAGICON


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time