Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2007, 07:04 AM
Vkk Vkk is offline
Member
 
Join Date: Jun 2006
Posts: 42
Default Popupmenu item right click?

I need right mouse click for popupmenu item. I have seached forum, but found nothing.

Thanks!
Reply With Quote
  #2  
Old 03-15-2007, 07:33 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Popupmenu item right click?

Menu's do not respond to a right-click.
Please explain better what you want to do.

MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #3  
Old 03-15-2007, 07:48 AM
Vkk Vkk is offline
Member
 
Join Date: Jun 2006
Posts: 42
Default RE: Popupmenu item right click?

Yes, there is only "onclick".. I need to know, if it is left or right click.

I tried wndproc already, could not get it work for popupmenu.

I need some way to capture right mouseclick in popupmenu window.
Reply With Quote
  #4  
Old 03-15-2007, 09:24 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Popupmenu item right click?

nope.

MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #5  
Old 03-15-2007, 03:20 PM
Vkk Vkk is offline
Member
 
Join Date: Jun 2006
Posts: 42
Default RE: Popupmenu item right click?

What do you mean "nope"?
Reply With Quote
  #6  
Old 03-15-2007, 04:51 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Popupmenu item right click?

No, Niet, Not at all, etc...


MrBaseball34
Hook'Em Horns!

2005 College Football National Champions
2005 College Baseball National Champions
Reply With Quote
  #7  
Old 03-15-2007, 09:46 PM
praveenkumar_k praveenkumar_k is offline
Senior Member
 
Join Date: Sep 2006
Posts: 698
Default RE: Popupmenu item right click?

hi,
Did u mean, when u right click, a popup menu should come? If YES then Try the code..

Protected
Procedure Wndproc(Var Msg:TMessage);Override;




procedure TForm1.Wndproc(var Msg: TMessage);
Var Pt:TPoint;
begin
inherited;
GetCursorPos(Pt);
if Msg.Msg=WM_RBUTTONDOWN then
PopupMenu1.Popup(pt.x,pt.y);
end;



Have a nice & Peaceful Day My Friend

Regards
KPK
Reply With Quote
  #8  
Old 03-15-2007, 11:43 PM
Vkk Vkk is offline
Member
 
Join Date: Jun 2006
Posts: 42
Default RE: Popupmenu item right click?

No.

I mean first

PopupMenu1.Popup(pt.x,pt.y);

if user now clicks item with left button -> showmessage('left button was used');
Or right button -> showmessage('right button was used');

There is only "onclick", it doesn't specify which button. Same problem with main menu, how to detect right mouse button.
Reply With Quote
  #9  
Old 03-15-2007, 11:48 PM
Vkk Vkk is offline
Member
 
Join Date: Jun 2006
Posts: 42
Default RE: Popupmenu item right click?

Very funny.

Does it mean you don't know the answer? Or it's not possible?

Anything is possible.
Reply With Quote
  #10  
Old 03-16-2007, 12:15 PM
nester261 nester261 is offline
Moderator
 
Join Date: Jan 2004
Location: UK
Posts: 617
Default RE: Popupmenu item right click?

Use this Unit:

[delphi]
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.
[/delphi]

NOTE:
I did not program this myself, I found it! But I have tested it and it works perfectly.

Nester261
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:39 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.