Recent

Author Topic: Popupmenu for menuitem?  (Read 1577 times)

SpaceGit

  • Newbie
  • Posts: 2
Popupmenu for menuitem?
« on: April 05, 2025, 03:33:24 pm »
Is it possible to have a popupmenu for a menuitem when it is right-clicked?
Preferably crossplatform, but failing that I will settle for windows support
Thank you in advance for any and all suggestions

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1572
    • Lebeau Software
Re: Popupmenu for menuitem?
« Reply #1 on: April 05, 2025, 07:04:32 pm »
Is it possible to have a popupmenu for a menuitem when it is right-clicked?
Preferably crossplatform, but failing that I will settle for windows support

It is possible on Windows, yes. Whether or not the LCL natively supports this, I don't know.

In Win32 API terms, you need to handle the WM_MENURBUTTONUP message that is sent to the 1st menu's owner window, and then display the 2nd popup menu using TrackPopupMenuEx() with the TPM_RECURSE flag specified.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jamie

  • Hero Member
  • *****
  • Posts: 7519
Re: Popupmenu for menuitem?
« Reply #2 on: April 06, 2025, 01:03:53 am »
In order to capture that message the form's message handler needs to be hookee.

Overriding the wndproc wont cut it because the lcl blocks it
I wrote a class that makes it easy to force the form class to pass all desired messages so they can be handled normally.

  I posted it here at one time "ezmessages"
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7519
Re: Popupmenu for menuitem?
« Reply #3 on: April 06, 2025, 09:29:50 pm »
I attached a project that uses my msghook i wrote with some code examples of device detection, form moving etc
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7519
Re: Popupmenu for menuitem?
« Reply #4 on: April 07, 2025, 12:50:24 am »
I wanted to let you know that I tried the WM_MENURBUTTONUP message,
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.WmMenuRButtonUp(var Msg:TMessage);
  2. Begin
  3.   TrackPopUpMenuEx(PopUpMenu1.Handle,TPM_RECURSE,Mouse.cursorpos.x,mouse.cursorpos.y,Handle,nil);
  4. End;                                                                                              
  5.  

and it does work, just add the message to the msghook and implement the message handler normally.

The only true wisdom is knowing you know nothing

SpaceGit

  • Newbie
  • Posts: 2
Re: Popupmenu for menuitem?
« Reply #5 on: April 10, 2025, 05:25:54 pm »
Thank you Jamie :) And the rest of yous :)

 

TinyPortal © 2005-2018