Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:16:42+00:00 2026-06-13T09:16:42+00:00

In Delphi XE2, how can I detect if the user clicked a popup menu

  • 0

In Delphi XE2, how can I detect if the user clicked a popup menu item with the left or with the right mouse button?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:16:44+00:00Added an answer on June 13, 2026 at 9:16 am

    Use this unit, install it as a component and replace the standard TPopupMenu which adds an OnMenuRightClick event.

    unit RCPopupMenu;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Menus;
    
    type
      TMenuRightClickEvent = procedure (Sender: TObject; Item: TMenuItem) of object;
    
      TRCPopupList = class(TPopupList)
      protected
        procedure WndProc(var Message: TMessage); override;
      end;
    
      TRCPopupMenu = class(TPopupMenu)
      private
        FOnMenuRightClick: TMenuRightClickEvent;
      protected
        function DispatchRC(aHandle: HMENU; aPosition: Integer): Boolean;
        procedure RClick(aItem: TMenuItem);
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        procedure Popup(X, Y: Integer); override;
      published
        property OnMenuRightClick: TMenuRightClickEvent read FOnMenuRightClick write FOnMenuRightClick;
      end;
    
    procedure Register;
    
    var
      RCPopupList: TRCPopupList;
    
    implementation
    
    procedure Register;
    begin
      RegisterComponents('Samples', [TRCPopupMenu]);
    end;
    
    { TRCPopupList }
    
    procedure TRCPopupList.WndProc(var Message: TMessage);
    var
      i: Integer;
      pm: TPopupMenu;
    begin
      if Message.Msg = WM_MENURBUTTONUP then
      begin
        for I := 0 to Count - 1 do
        begin
          pm := TPopupMenu(Items[i]);
          if pm is TRCPopupMenu then
            if TRCPopupMenu(Items[i]).DispatchRC(Message.lParam, Message.wParam) then
              Exit;
        end;
      end;
      inherited WndProc(Message);
    end;
    
    { TRCPopupMenu }
    
    constructor TRCPopupMenu.Create(AOwner: TComponent);
    begin
      inherited;
      PopupList.Remove(Self);
      RCPopupList.Add(Self);
    end;
    
    destructor TRCPopupMenu.Destroy;
    begin
      RCPopupList.Remove(Self);
      PopupList.Add(Self);
      inherited;
    end;
    
    function TRCPopupMenu.DispatchRC(aHandle: HMENU; aPosition: Integer): Boolean;
    begin
      Result := False;
      if Handle = aHandle then
      begin
        RClick(Items[aPosition]);
        Result := True;
      end;
    end;
    
    procedure TRCPopupMenu.Popup(X, Y: Integer);
    const
      Flags: array[Boolean, TPopupAlignment] of Word =
        ((TPM_LEFTALIGN, TPM_RIGHTALIGN, TPM_CENTERALIGN),
        (TPM_RIGHTALIGN, TPM_LEFTALIGN, TPM_CENTERALIGN));
      Buttons: array[TTrackButton] of Word = (TPM_RIGHTBUTTON, TPM_LEFTBUTTON);
    var
      AFlags: Integer;
    begin
      DoPopup(Self);
      AFlags := Flags[UseRightToLeftAlignment, Alignment] {or Buttons[TrackButton]};
      if (Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and (Win32MinorVersion > 0)) then
      begin
        AFlags := AFlags or (Byte(MenuAnimation) shl 10);
        AFlags := AFlags or TPM_RECURSE;
      end;
      TrackPopupMenuEx(Items.Handle, AFlags, X, Y, RCPopupList.Window, nil);
    end;
    
    procedure TRCPopupMenu.RClick(aItem: TMenuItem);
    begin
      if Assigned (FOnMenuRightClick) then
        FOnMenuRightClick(Self, aItem);
    end;
    
    var
      oldPL: TPopupList;
    
    initialization
      RCPopupList := TRCPopupList.Create;
    finalization
      RCPopupList.Free;
    
    end.
    

    You can then use the OnMenuRightClick event to perform some action on a right click!

    Note: I didn’t make this unit – I don’t know who did but credit goes to whoever did… I have however just tested it in Delphi XE2 and it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I get a VirtualTreeView component for Delphi XE2? I can see the
Delphi XE2 starter for me, but maybe a general answer will help others ...
Delphi XE2, so Indy 10. My client sends a command which is processed by
Delphi XE2, so I guess that is Indy 10(?). One server, 10 clients. I
Using Delphi XE2 on Win 7 64 bit creating a 32 bit app... In
I am using Delphi XE2 and attempting to upgrade our usb comms dll to
I'm currently using delphi xe2. well the firemonkey part of it. I use to
Create any application in Delphi XE2 and press F1 to run help system. You'll
I have a Delphi XE2 project having components like Label1 , BitBtn1 and Image1
I am using Delphi XE2 to communicate with a fairly large SOAP service. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.