C/C++ code
WTSRegisterSessionNotification(m_hWnd, NOTIFY_FOR_THIS_SESSION);
退出时
- C/C++ code
- WTSUnRegisterSessionNotification(m_hWnd);
在你的窗口类头文件里添加
- C/C++ code
- afx_msg LRESULT OnSessionChange(WPARAM wParam, LPARAM lParam);
cpp里响应消息
- C/C++ code
- ON_MESSAGE(WM_WTSSESSION_CHANGE, OnSessionChange)
消息响应函数
- C/C++ code
- LRESULT CMainFrame::OnSessionChange(WPARAM wParam, LPARAM lParam) { switch (wParam) { case WTS_CONSOLE_CONNECT: break ; case WTS_CONSOLE_DISCONNECT: break ; case WTS_REMOTE_CONNECT: break ; case WTS_REMOTE_DISCONNECT: break ; case WTS_SESSION_LOGON: break ; case WTS_SESSION_LOGOFF: break ; case WTS_SESSION_LOCK: break ; case WTS_SESSION_UNLOCK: break ; case WTS_SESSION_REMOTE_CONTROL: break ; default : break ; } return 0 ; }