如何登出目前的使用者

下列範例會使用 ExitWindows 函式來登出目前的使用者。

// Log off the current user. 

ExitWindows(0, 0);

下列範例會使用 ExitWindowsEx 函式來登出目前的使用者。

// Log off the current user. 

ExitWindowsEx(EWX_LOGOFF, 0);

應用程式會收到 WM_QUERYENDSESSION 訊息,並顯示對話方塊,詢問它是否確定結束會話。 如果使用者按一下 [是 ],系統就會登出使用者。 如果使用者按一下 [否 ],則會取消登出。

// Process the message in the window procedure. 

case WM_QUERYENDSESSION:  
{ 
    int r; 
    r = MessageBox(NULL,(LPCWSTR)L"End the session?",(LPCWSTR)L"WM_QUERYENDSESSION",MB_YESNO);
 
    // Return TRUE to continue, FALSE to stop. 
 
    return r == IDYES; 
    break; 
}

登出