开发者

Killing Queued Notification Balloons (Pre-Vista)

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:

  1. Is there a way to cancel any outstanding balloo开发者_开发知识库n I made, when a new balloon arrives?
  2. 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!!!


Regarding option (2) you need to register interest in 'SessionNotifications', using the function WTSRegisterSessionNotification:

WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags);

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:

WTSUnRegisterSessionNotification(HWND hWnd);

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜