Monday, March 26, 2012

How determine how a Context menu was closed?

Hello,
I need to be able to determine the method used to close a Context menu. It
appears that there are three possibilities: 1) a menu selection was clicked,
2) the User clicked outside the menu or 3) the User hit ESC. I need to
determine if the menu closed due to either of the last two possiibilities.
(This may seem like a mysterious requirement but the popup of the Context
Menu is triggered by a specific event in a Frame. If a menu selection is
made then certain actions are taken but if the User "cancels" by items #2 or
#3 I need to take a different action to "clean up").
TrackPopupMenu() blocks and does not return until the menu has been closed,
but this happens before the handler for a selected menu item (if an item was
choosen) is called. That means that upon return from TrackPopupMenu() I
can't tell yet if a menu item was selected (since, if a handler is going to
fire, it hasn't yet fired). WM_EXITMENULOOP is also sent when the menu
closes but I can't depend that this will always been sent/processed *AFTER*
any possible menu selection message so I hacve the same problem with using
that.
So the question boils down to how can I, upon return from WM_EXITMENULOOP(),
detect how the menu was closed? I guess I could "go to sleep" for one
second upon return to give any possible menu selection message time to hit
its handler but that seems like a big kludge and I'm not sure how long I'd
have to wait to be sure.
Thanks.
Al
AlKoch@.MyRealBoxREMOVEALLTHESECHARS.comSorry - please ignore - obviously sent to wrong group!
Al

No comments:

Post a Comment