Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Mouse leave event for a Popup Menu


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: May 10, 2016 10:27 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Adriano Macome

Posts: 56
Registered: 9/26/11
Mouse leave event for a Popup Menu  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 10, 2016 5:31 AM
Hi;

I am trying to find a way to close a popup menu when the mouse cursor goes out of the popup menu. The first problem I found is, I can´t handle the event; for example I tried to write a descendant with an procedure like:

TMyPPM = class(TPopupMenu)
private
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
end;

procedure TMyPPM.CMMouseLeave(var Message: TMessage);
begin
CloseMenu;
end;

but it is not fired when I move the cursor outside the menu.

The other problem is that it seems that TPopupMenu.CloseMenu does not close the popup.

Is it possible to do this?, How?

Thank you!
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Mouse leave event for a Popup Menu  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 10, 2016 8:56 AM   in response to: Adriano Macome in response to: Adriano Macome
Adriano Macome wrote:

Hi;

I am trying to find a way to close a popup menu when the mouse cursor
goes out of the popup menu. The first problem I found is, I can´t
handle the event; for example I tried to write a descendant with an
procedure like:

TMyPPM = class(TPopupMenu)
private
procedure CMMouseLeave(var Message: TMessage); message
CM_MOUSELEAVE; end;

procedure TMyPPM.CMMouseLeave(var Message: TMessage);
begin
CloseMenu;
end;

but it is not fired when I move the cursor outside the menu.

The other problem is that it seems that TPopupMenu.CloseMenu does not
close the popup.

Is it possible to do this?, How?

Thank you!

It's (almost) impossible to achieve, the short version the popup menu
is managed by Windows not Delphi and that's the reason why
CM_MOUSELEAVE doesn't fires.

For more detailed information please read the following discussion:
http://www.devsuperpage.com/search/Articles.aspx?G=2&ArtID=36067
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Mouse leave event for a Popup Menu  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 10, 2016 10:27 AM   in response to: Adriano Macome in response to: Adriano Macome
Adriano wrote:

I am trying to find a way to close a popup menu when the mouse
cursor goes out of the popup menu.

Why? That is not standard popup menu behavior.

The first problem I found is, I can´t handle the event

That is because there is no event to handle.

for example I tried to write a descendant with an procedure like:
<snip>
but it is not fired when I move the cursor outside the menu.

Of course not. CM_MOUSELEAVE is a custom VCL message, not a Win32 message.
CM_MOUSELEAVE is only sent to VCL Forms and UI controls, not to popup menus.
There is no message, whether stardard or custom, when the mouse cursor leaves
a popup menu.

The other problem is that it seems that TPopupMenu.CloseMenu
does not close the popup.

Works fine for me. How exactly are you trying to use it?

Is it possible to do this?

Not the way you describe it, no.

But, what you can do is use the Win32 SetMenuInfo() function to enable
the menu's MNS_AUTODISMISS style:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms647997.aspx

This way, the menu auto-closes itself when the mouse cursor is outside of
the menu for more than 10 seconds. For example:

procedure TForm60.PopupMenu1Popup(Sender: TObject);
var
  info: TMenuInfo;
begin
  ZeroMemory(@info, sizeof(info));
  info.cbSize := sizeof(info);
  info.fMask := MIM_STYLE;
  info.dwStyle := MNS_AUTODISMISS;
  SetMenuInfo(PopupMenu1.Handle, info);
end;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02