Killing Queued Notification Balloons (Pre-Vista)

437 views Asked by At

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 balloon 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!!!

1

There are 1 answers

3
Anya Shenanigans On BEST ANSWER

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.