|
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.
BOOL CALLBACK EnumProc(
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) {
SetThreadDesktop(GetThreadDesktop(dwGuiThreadId));
EnumThreadWindows(dwGuiThreadId, EnumProc, 0);
}
return FALSE;
}
Related Links
Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
More Online Helps
Win32 Multimedia Programmer's Reference (mmedia.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages
|