参考:
https://docs.microsoft.com/en-us/windows/win32/termserv/wm-wtssession-change
1. 注册,一般在创建窗口的时候调用注册,销毁窗口的时候反注册。
BOOL
WINAPI
WTSRegisterSessionNotification(
HWND hWnd,
DWORD dwFlags
);
BOOL
WINAPI
WTSUnRegisterSessionNotification(
HWND hWnd
);
2.在消息循环中添加对WM_WTSSESSION_CHANGE消息的处理.
我是这样用的:
LRESULT Demo::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);
}
bre