How to activate pop-up menus without changing foreground window?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 13
Reputation: aiurovet is an unknown quantity at this point 
Solved Threads: 0
aiurovet aiurovet is offline Offline
Newbie Poster

How to activate pop-up menus without changing foreground window?

 
0
  #1
Feb 18th, 2009
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:
  1. HWND hwndActive = GetForegroundWindow();
  2.  
  3. DWORD thisThreadId = GetCurrentThreadId();
  4. DWORD activeThreadId = GetWindowThreadProcessId(hwndActive, NULL);
  5.  
  6. AttachThreadInput(thisThreadId, activeThreadId, TRUE);
  7.  
  8. UINT result = (UINT)TrackPopupMenu(...);
  9.  
  10. AttachThreadInput(thisThreadId, activeThreadId, FALSE);
  11. 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?
Last edited by Ancient Dragon; Feb 18th, 2009 at 8:49 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: How to activate pop-up menus without changing foreground window?

 
0
  #2
Feb 18th, 2009
Try to enable WS_EX_TOPMOST for the popup menu! But I don't remember if this is exactly what you want.
Last edited by jencas; Feb 18th, 2009 at 9:36 am.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: aiurovet is an unknown quantity at this point 
Solved Threads: 0
aiurovet aiurovet is offline Offline
Newbie Poster

Re: How to activate pop-up menus without changing foreground window?

 
0
  #3
Feb 19th, 2009
Originally Posted by jencas View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC