我有一个非 MFC、非 ATL C++ 应用程序,它通常会在系统托盘图标上创建通知气球。如果在 Vista 之前的机器上,用户锁定屏幕 - 这些新创建的“气球已排队",当用户最终重新登录时,这会造成混乱。可能有数十或数百个气球在等待。为每个气球设置的超时在用户重新登录之前不适用!
因此,为了解决这个问题,我需要知道:
- 当新气球到达时,是否有办法取消我制作的任何未完成的气球?
- 我应该检查“会话锁定”/“屏幕锁定”并在用户缺席时停止创建气球吗?
关于选项 #2,我应该在 Windows 循环中监听什么消息来捕获帐户锁定/会话锁定?我尝试了事件 WM_ENDSESSION,但我的应用程序表现得好像没有看到它。这是正确的活动吗?我需要注册吗?
当然,如果有更简单的方法来解决这个问题,我很想知道。当然,对于 Vista 及更高版本,NIF_REALTIME uFlags 选项轻松解决问题。
ps 令我震惊的是,我无法在网上找到带有描述的 Windows 消息列表。我发现的只是一个没有描述的列表,而且它甚至不是由微软托管的!
I have a non-MFC, non-ATL C++ app that routinely creates notification balloons on a system tray icon. If, on pre-Vista boxes, the user locks the screen - these newly created "balloons are queued", which creates a mess when the user finally logs back in. There could be dozens or hundreds of balloons waiting. The timeout set for each balloon does not apply until the user logs back in!!
So to solve this, I need to know either:
- Is there a way to cancel any outstanding balloon I made, when a new balloon arrives?
- Should I instead check for a "session lock" / "screen lock" and stop creating balloons in the user's absence?
Regarding option #2, what message do I listen for in the windows loop to capture an account lock / session lock? I tried the event WM_ENDSESSION, but my app acted like it didn't see it. Is that the right event? Do I need to register for it?
Of course if there is a simpler way to solve this, I'd love to know. Certainly for Vista and later, the NIF_REALTIME uFlags option solves the problem handily.
p.s. I'm appalled that I can't find a list of windows messages online with descriptions. All I found was a list without descriptions, and it isn't even hosted by Microsoft!!!
发布评论
评论(1)
关于选项 (2),您需要使用函数 WTSRegisterSessionNotification:
将句柄传递给窗口以接收消息WM_WTSSESSION_CHANGE,并使用标志 NOTIFY_FOR_THIS_SESSION,这表明您希望在会话事件发生时获取消息。
您感兴趣的会话事件是 WTS_SESSION_LOCK 和 WTS_SESSION_UNLOCK。请记住,您必须使用相应的注销函数 WTSUnRegisterSessionNotification:
您需要跟踪会话的锁定/解锁/连接/断开连接状态,这允许您决定何时安排气球消息。
Regarding option (2) you need to register interest in 'SessionNotifications', using the function WTSRegisterSessionNotification:
You pass in the handle to the window to receive the message WM_WTSSESSION_CHANGE, and use the flag NOTIFY_FOR_THIS_SESSION, which indicates you want to get messages when session events occur.
Session events you would be interested in are WTS_SESSION_LOCK and WTS_SESSION_UNLOCK. Please bear in mind that you must use the corresponding deregister function WTSUnRegisterSessionNotification:
You need to keep track of the locked/unlocked/connected/disconnected state of the session, which allows you to decide when to schedule balloon messages.