Handling Logoff Events
Service applications that interact with the user should be prepared to handle logoff events. When a logoff event occurs, the service application 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;
}
服务应用与用户交互时需处理注销事件。当注销事件发生,服务应用要关闭用户窗口站和桌面的所有句柄。示例展示了交互代码中的消息框在注销时应如何关闭,还提及了ConsoleCtrlHandler函数。
1万+

被折叠的 条评论
为什么被折叠?



