Actually - my suggestion solves part of your problem( detecting
which button ) but doesn't solve the other part  (responding to
right clicks as well as left clicks)

again - i'm not sure this will work - but i'd try
calling the base class WMNCLBUTTONDOWN handler inside your
WMNCRBUTTONDOWN handler.    (note - your R handler calls the
base class L handler).

   procedure Form1.WMNCRButtonDown(var Message: TWMNCRButtonDown);
   begin
     if Message.WParam = HTMENU then 
     begin 
        mMenuButton:=mbLeft;
        TForm.WMNCLButtonDown( TWMNCLButtonDown( Message ) );
     end
     else inherited;
     
   end;

In effect you will turn the right click into a left click - 
but you will have intercepted it knowing it was a right click
and recorded the fact in mMenuButton.

I hope this is making sense.    (Tired, long day ... )

ns


-----Original Message-----
From: Nello Sestini <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Date: Tuesday, October 10, 2000 16:42
Subject: Re: [DUG]: TMenuItem


> From: Rohit Gupta <[EMAIL PROTECTED]>
> How can I make a TMenuItem respond to both left and right clicks
> and be able to ell which occurred.


this is kind of a pain, but i don't see an easier way to do it:

in your form add a data member:

    type TMenuButton = (mbLeft, mbRight);
    //...
    mMenuButton:TMenuButton;

and declare WMNCLButtonDown and WMNCRButtonDown messagehandlers:

    procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); 
              message WM_NCLBUTTONDOWN;
    procedure WMNCRButtonDown(var Message: TWMNCLButtonDown); 
              message WM_NCRBUTTONDOWN;

in the WMNCLButtonDown handler, look at Message.Wparam and if it
is HTMENU set mMenuButton := mbLeft.    Then call the inherited
implementation.

   procedure Form1.WMNCLButtonDown(var Message: TWMNCLButtonDown);
   begin
     if Message.WParam = HTMENU then mMenuButton:=mbLeft;
     inherited;
   end;

in the WMNCLButtonDown handler, look at Message.Wparam and if it
is HTMENU set mMenuButton := mbRight.   Then call the inherited
implementation.

   // same as above


finally, in the "OnClick" event handlers for your TMenuItem
you can examine mMenuButton to see which mouse button
fired the click.

if you're willing to hang the menu off of a tool button
you can take a look at the TrackButton property which sort of
does the same thing.

i've never tried either of these, and there could easily be
embarrassing errors in the above.  But i think the idea will
work.

good luck

ns




---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to