Solved

right click on a popup menu ?

Posted on 2002-06-05
7
598 Views
Last Modified: 2010-08-05
Hello all,

Is there a way to let a Popup menu react to a user-right-click ? i.e. an equivalent of OnMouseDown event .  Also I need to know on which menuitem user was positioned when he right-clicked

many thanks
0
Comment
Question by:fadyg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7057011
add popup menu to ur form, then assign the Popmenu property of the from to ur popup menu
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7057064
also you can view it manually in the OneMouseDown Event

  if Button = mbRight then
    PopupMenu1.Popup(X + Top,Y + Left);

0
 
LVL 1

Expert Comment

by:bes67
ID: 7057116
Hi

if you mean right-click in a popup menu that has been already activated I think that you have to look at TrackPopupMenu API function. TrackPopupMenu API function (that is used to show popup menu  in respond of user right-click) has TPM_RECURSE flag that is not used in Delphi. This flag allows to use context menu within a menu but only in Win98/me and win2000/xp. To use this flag you have to make your own procedure to invoke popup menu

Hope this will help
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:bes67
ID: 7057138
Small addition to my previous post:

you have to write WM_MENURBUTTONUP message handler to use nested popup menus
0
 

Author Comment

by:fadyg
ID: 7057282
Hello again guys,

sorry for not being very accurate in my description of the problem. I have already a popupmenu assigned to a control and this popup works very nicely when I right click on the control.  What is needed now is to be able to respond to right-clicks WHILE the popup is open and showing its items.  

for example, one of the item is "modem". When the mouse comes over it on the popup, it is highlighted. A normal click would activate the modem, while a right click would open the properties of the modem (of course this is just an example).

bes67 got it almost correct, but I don't need a menu when righ-cliking but rather call an event.

is it a bit clearer ?


0
 
LVL 1

Accepted Solution

by:
bes67 earned 300 total points
ID: 7058534
Hi

try this unit. To define right-click menu handle use 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
    { Private declarations }
    FOnMenuRightClick: TMenuRightClickEvent;
  protected
    { Protected declarations }
    function DispatchRC(aHandle: HMENU; aPosition: Integer): Boolean;
    procedure RClick(aItem: TMenuItem);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Popup(X, Y: Integer); override;
  published
    { Published declarations }
    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
  case Message.Msg of
    WM_MENURBUTTONUP:
      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.

hope this will help
0
 

Author Comment

by:fadyg
ID: 7059319
Nice one !!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LAN or WAN ? 11 121
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 93
Delphi Firemonkey send email on Android 1 82
Posting a string with PostMessage 23 49
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question