Handling Logoff Events

Win32 services that interact with the user should be prepared to handle logoff events. When a logoff event occurs, the Win32 service must close all handles to the user's window station and desktop.

This sample demonstrates how the message box in the interaction example code should be dismissed at logoff. The ConsoleCtrlHandler function in this example is a HandlerRoutine that was specified by a call to the SetConsoleCtrlHandler function.


HWND hwnd,

LPARAM lParam)



* Send a WM_CLOSE to destroy the window, because DestroyWindow does

* not work across threads.


SendMessage(hwnd, WM_CLOSE, 0, 0);

return TRUE;


BOOL ConsoleCtrlHandler(

DWORD dwCtrlType)


if (dwCtrlType == CTRL_LOGOFF_EVENT && dwGuiThreadId != 0) {


EnumThreadWindows(dwGuiThreadId, EnumProc, 0);


return FALSE;


Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database