Solved

right click on a popup menu ?

Posted on 2002-06-05
7
592 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
Delphi - replicating a form 8 86
Delphi application Soap connection 5 123
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 73
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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