I am trying to mimic the behavior of Language Indicator pop-up menus (which pop-up when you do left or right mouse click on the Language Indicator), so the foreground window and focus do not change, and it is still possible to use keyboard to select or cancel menu (arrow keys or Escape).

I need this for tray menu, as well as for a general pop-up menu which can be activated at any time by pressing certain keys. And of course, I am hooking to WH_KEYBOARD_LL and WH_MOUSE_LL events properly.

My application is supposed to be running under XP or Vista (2000 is nice to have, but not essential). I am developing it under Vista in Visual Studio 2008 Standard Edition.

The best solution so far was to have something like described on social.msdn:

HWND hwndActive = GetForegroundWindow();

DWORD thisThreadId = GetCurrentThreadId();
DWORD activeThreadId = GetWindowThreadProcessId(hwndActive, NULL);

AttachThreadInput(thisThreadId, activeThreadId, TRUE);

UINT result = (UINT)TrackPopupMenu(...);

AttachThreadInput(thisThreadId, activeThreadId, FALSE);
BringWindowToTop(hwndActive);

Foreground window does not change, mouse navigation is working fine, selection by click is fine, BUT keyboard is not working (you can neither use arrow keys to navigate through menu items, nor press Escape to cancel menu). And also, mouse cursor does not always switch from I-beam to default arrow image when activating menu with Notepad application at foreground.

Is there a proper way to create truly pop-up menus avoiding notorious TrackPopupMenu's requirement to switch foreground window to my app? Should be the only solution to create my own window and simulate menu activities? And still, wouldn't I need to switch foreground window for the period when such 'pop-up menu' is active?

aiurovet
Deleted Member

Try to enable WS_EX_TOPMOST for the popup menu! But I don't remember if this is exactly what you want.

Try to enable WS_EX_TOPMOST for the popup menu! But I don't remember if this is exactly what you want.

This is pointless: menu is not a window, and WS_EX_TOPMOST is a window style.

This article has been dead for over six months. Start a new discussion instead.