Solved

Calling TrackPopupMenu() when a another menu is active

Posted on 1997-04-07
5
267 Views
Last Modified: 2013-12-03
Is it somehow possible to call TrackPopupMenu(..) when
the user is rightclicking on a menu item in a "normal"
popup?  (The problem is not to detect the rightclick but
to successfully call TrackPopupMenu(..))


0
Comment
Question by:dag.garthus
  • 2
  • 2
5 Comments
 

Expert Comment

by:ebritten
ID: 1334436
I don't know if there is a way to check if you right clicked a menu item.  You can call TrackPopupMenu in a WM_COMMAND message handler in response to menu selection.
0
 

Author Comment

by:dag.garthus
ID: 1334437
>I don't know if there is a way to check if you right
>clicked a menu item. You can call TrackPopupMenu in a
>WM_COMMAND message handler in response to menu selection.

Yes i know - but is it possible to call TrackPopupMenu while
the other menu is still visible (nothing is yet selected)?

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1334438
What would you expect TrackPopupMenu to do?  Popup another menu on top of the current one (in which case, why not just cascade), or popup the other menu in place of the first one (in which case, they aren't both open at once anyway.I think that if you look what happens in other apps when you right click, you'll see that it is possible and that the old popup is closed and a new one opened if you right click again.
0
 

Author Comment

by:dag.garthus
ID: 1334439
> What would you expect TrackPopupMenu to do? Popup
> another menu on top of the current one
... Yes

> (in which case, why not just cascade)
Because that's another menu item.

Let me try to illustrate what I'm seeking.  
Take the Win95 "Start Menu" and assume this a normal
menu with ownerdraw items - all implemented by me :\

When rightclicking on a folder in the startmenu this
would bring up a PopUp with the say "Delete Folder" and
"Create Folder" items - with the startmenu still visible.

Yes - this could be implemented by adding these items
to the sub menu that normally contains that menufolder
items but that's not what I'm looking for.

0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1334440
TrackPopupMenu is a WIN32 API function which processes window events until a selection is made or the popup menu is dismissed (click somewhere else or ESC key etc). You can select an item with either the right or left mouse buttons. AFTER the menu disappears, a WM_COMMAND event is generated corresponding to the message (and TrackPopupMenu returns).

This means you cannot detect any interaction with the popup menu until AFTER it has disappeared. This would make the direct detection of a right click extremely difficult - let alone displaying another menu ON TOP of the popup menu.

Another thought is to detect which mouse button was used to select a menu item from the popup. However, I don't think this is possible, because all you get is the WM_COMMAND message. But you MAY be able to determine WHERE on the menu that the user clicked the mouse by examining the position member of the MSG structure for the WM_COMMAND message (if you have assess to this). You could use this information to implement some "hot" area on the menu so if the user clicks here another menu appears after the first disappears. You could then pop-up an appropriate menu etc after the original has disappeared.

Yet another thought is, rather than right-clicking on a menu item to customise it, hold down the shift key (say) when right clicking to pop-up the original menu. You program can detect this and pops up another menu which LOOKS like your usual popup. You can either associate different ID's with this other menu that ,when processed, popup your "Delete Folder" etc menu. Alternatively it could be built with cascading options for these.

Still another thought is to write your own popup menu handler - but that would require a LOT of work, 'cause you'd have to draw the menu yourself, and handle the interaction with it.Also note that the way TrackPopupMenu works, you cannot have two active at once (for one task anyway) because of the way TrackPopupMenu controls the message loop, and disappears itself when any other event occurs (other than mouse/keyboard interaction with the menu itself).

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now