The ExitWindows function logs off the current user. All applications must agree to terminate before the user logs off. If any application returns FALSE when it processes the WM_QUERYENDSESSION message, the user is not logged off. If your application handles the WM_QUERYENDSESSION message, you can allow the user to cancel the log-off operation, even if another application or Windows originated the end-session request.
The following example logs off the current user, unless the user clicks the No button in the message box displayed when the application receives the WM_QUERYENDSESSION message.
// Log off the current user.
ExitWindows(0, 0);
// Process the message in the application's window procedure.
case WM_QUERYENDSESSION:
{
int r;
r = MessageBox(NULL, "Shut down?","WM_QUERYENDSESSION", MB_YESNO);
// Return TRUE to allow shutdown, FALSE to stop.
return r == IDYES;
break;
}