Tech Journal Back to Tech Journal

Why doesn't clicking away from my tray icon make the context menu dissapear?

The problem is that tray's icon isn't really a window, so there's no really loss of focus. The solution is that the window that displays the icon needs to be set as the foreground window using SetForegroundWindow(hwnd). It doesn't matter if the window is hidden (e.g. invisible.)

The problem with just doing that is that if the window was invisible, then it will appear in the ALT+TAB list. If you don't want this, just make sure the window with CreateWindowEx() with an extended_style of WS_EX_TOOLWINDOW (The CreateWindowEx() is the same as CreateWindow() except that the first argument is the extended style.) Oh, and make sure that the WS_ style don't include WS_APPWINDOW (and some other ones...)

Last updated on 2005-07-09 14:00:00 -0700, by Shalom Craimer

Back to Tech Journal