Mega Search
23.2 Million


Sign Up

Make a donation  
Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi

In my application, when a popup menu is displayed, as the mouse passes 
from item to item I display the associated Hint value. Thanks to pointers 
from Remy, I handle this by intercepting the WM_MENUSELECT message. If 
the user selects a menu item or clicks somewhere outside of the popup 
menu, I intercept messages to force my hint to stop showing.

However, I can't seem to find a way to detect when the mouse moves off of 
a displayed popup menu when the user has not clicked on anything else. 
That is, the user causes the popup menu to display and then just moves 
the mouse off of the popup menu - the popup menu itself is still visible 
to the user.

What I need to do in this situation is stop displaying my popup hint if 
it is visible. Reading online it seems like the popup menu should be 
sending a message CM_MOUSELEAVE but this does not appear to be happening.

I know I must be missing something stupid but I am at a loss. Can anyone 
point me in the right direction to detect when a mouse cursor leaves a 
visible popup menu?

Thanks!

Rich

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 10-Mar-2014, at 10:58 AM EST
From: Rich Ackerson
 
Re: Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi
Rich Ackerson wrote:

> In my application, when a popup menu is displayed, as the mouse
> passes from item to item I display the associated Hint value. Thanks
> to pointers from Remy, I handle this by intercepting the
> WM_MENUSELECT message. If the user selects a menu item or clicks
> somewhere outside of the popup menu, I intercept messages to force my
> hint to stop showing.
> 
> However, I can't seem to find a way to detect when the mouse moves
> off of a displayed popup menu when the user has not clicked on
> anything else.  That is, the user causes the popup menu to display
> and then just moves the mouse off of the popup menu - the popup menu
> itself is still visible to the user.
> 
> What I need to do in this situation is stop displaying my popup hint
> if it is visible. Reading online it seems like the popup menu should
> be sending a message CM_MOUSELEAVE but this does not appear to be
> happening.
> 
> I know I must be missing something stupid but I am at a loss. Can
> anyone point me in the right direction to detect when a mouse cursor
> leaves a visible popup menu?

The popup menu is an API window and the menu navigation is completely
handled by Windows, including all key and mouse message handling while
the menu is active and the internal menu message loop is running.
I assume you have subclassed the TPopupList class to catch messages
Windows sends to the menu's owner. That is not enough for your purpose,
you would have to catch messages that are sent to the popup menu window
itself. For which you have no window handle, so the best option may be
to handle WM_ENTERMENULOOP and WM_EXITMENULOOP to install and remove a
windows hook to either track the mouse yourself, or intercept the
messages sent to the menu window.

Popup hints are alien to menu items. You are needlessly complicating
your life if you try to implement them. Just use a TStatusbar with
Autohint set to true to show hints for the menu items. That is all
automatic.

-- 
Peter Below (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 10-Mar-2014, at 12:02 PM EST
From: Peter Below
 
Re: Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi
Rich,

> However, I can't seem to find a way to detect when the mouse moves
> off of a displayed popup menu when the user has not clicked on anything
> else.

AFAIK, there is no message for that condition, unfortunately.

> Reading online it seems like the popup menu should be sending a message
> CM_MOUSELEAVE but this does not appear to be happening.

That message only applies to visual components, not to popup menus.

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 10-Mar-2014, at 12:25 PM EST
From: Remy Lebeau (TeamB)
 
Re: Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi
Peter wrote:

> I assume you have subclassed the TPopupList class to catch messages
> Windows sends to the menu's owner. That is not enough for your
> purpose, you would have to catch messages that are sent to the popup
> menu window itself.  For which you have no window handle, so the best
> option may be to handle WM_ENTERMENULOOP and WM_EXITMENULOOP
> to install and remove a windows hook to either track the mouse yourself,
> or intercept the messages sent to the menu window.

But that does not tell you when the mouse moves off the menu while the menu 
is still active.  And tracking the mouse is not helpful if you cannot retreive 
the rectangle that the menu is currently occupying.

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 10-Mar-2014, at 12:28 PM EST
From: Remy Lebeau (TeamB)
 
Re: Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi
Remy/Peter,

Thank you both very much for chiming in. 

For whatever its worth, I completely agree that trying to handle hints 
like this from a popup menu is bizarre and needless aggrevation. 
Unfortunately, it is also a feature the boss is insisting on and one that 
is out of my control to implement any other way.

Remy: thanks for confirming what I was about to post a question about - 
the WM_EXITMENULOOP message firing while the popup menu is still visible. 
I thought I was really doing something wrong when I couldn't even 
intercept THAT message.

Looks like its time to convince the boss he really doesn't need this 
feature.

Thanks again

Rich

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 10-Mar-2014, at 12:40 PM EST
From: Rich Ackerson
 
Re: Detect when mouse exits a TPopupMenu  
News Group: embarcadero.public.delphi.nativeapi
"Rich Ackerson"  wrote in message news:658913@forums.embarcadero.com... 

> Unfortunately, it is also a feature the boss is insisting on 
> and one that is out of my control to implement any other way.
> ... Looks like its time to convince the boss he really doesn't 
> need this feature.

Rich, one day you will become a boss...  All you need to do is 
draw your menu items yourself:  it's called owner-drawn menus: 
the OnDrawItem event handler will be called when mouse pointer 
leaves it (moves off of the item), check to see if the pointer 
is still within the menu's rectangle, and hide your hint / tip 
if it is not. 
p.s. @Peter: menu is not a window. 

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 17-Mar-2014, at 4:37 PM EST
From: =?Utf-8?Q?Boba_=C2=BD=C2=B0?=