BOOL ExitWindows(dwReserved, uReturnCode) | |||||
DWORD dwReserved; | /* return or restart code | */ | |||
UINT uReturnCode; | /* reserved; must be zero | */ |
The ExitWindows function initiates the standard Windows shutdown procedure. If all applications agree to terminate, the Windows session is terminated. Under DOS, termination simply exits Windows and returns to DOS. Under NT, termination means the file system is shut down and a dialog box comes up informing the user to either reboot or turn the machine off.
dwReserved
Reserved for future use.
uReturnCode
For DOS/Win32 only, this is the return value returned from Windows to DOS when Windows exits.
This function returns FALSE if one or more applications refuse to terminate. If all applications agree to terminate, this function never returns.
The ExitWindows function asks applications if they want to terminate by sending the WM_QUERYENDSESSION message. This message is sent to the main window of an application. This allows applications to query the user for typically one of three choices: save a file and exit, don't save a file and exit, or cancel exiting. One application cancelling a shutdown will cause no applications to shutdown. The applications of all desktops are enumerated. If all applications agree to shutdown, they are sent the WM_ENDSESSION message, which informs them the system is shutting down. The default handling of the WM_ENDSESSION message is to call ExitProcess with dwExitCode set to 1.
'Shutdown mode' is a system-wide mode. No new applications will be allowed to start up in this mode. The user will not be allowed to interact with applications in this mode (except for the user queries for file saving).
System shutdown should not be confused with application shutdown, where the user double clicks on the system menu or selects the 'close' menuitem from the system menu. This sends a WM_CLOSE message to the main window, which causes that window to be destroyed. This sends a WM_DESTROY message to the main window—applications process this message by calling PostQuitMessage, which causes a WM_QUIT to be returned from GetMessage inside the application's main loop, which causes the main loop to exit from main, which ends up calling ExitProcess with dwExitCode set to the return value of main. Before the WM_QUERYENDSESSION message is sent to an application, the system determines if it is in a hung state. If it is, the 'end task' dialog will appear informing the user of the situation. The user will either choose to terminate the application or try to continue.