Tmousemove in Tmainmenu

hi,Experts
    the Tmainmenu component has no Tmouse event.
    I would like to use the Tmousemove/Tmousedown event in Tmainmenu.how to get?

thanks
regards
Cheng_samAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
what version of Delphi are you using?
0
Cheng_samAuthor Commented:
hi,
    delphi 2010


thanks
regards
0
developmentguruPresidentCommented:
As is usual with many of the base Delphi components, the TMainMenu is a wrapper for a windows control.  In this case it is an OLE2 Menu.  In order to handle this you would likely need to bypass the Delphi control altogether and use OLE2 to try to set it up.  Personally I would find it easier to make my own menu components if I needed that functionality.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

aikimarkCommented:
or look at some third party components, such as those from Raize Software.
0
BlueVDCommented:
You can use Windows Messages API. Here's an example:
http://delphi.about.com/od/vclusing/a/menuitemhints.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lomo74Commented:
menu bars are windowless, so you can't get mouse move messages from the menu bar area.
a possible approach: intercept WM_NCHITTEST; when result is HTMENU, then it means the mouse is inside the menu bar area.
you can then use the message's X and Y coordinates (into LParam) and read button state (using GetAsyncKeyState) to mimic WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_RBUTTONDOWN, and so on, accordingly.
0
Cheng_samAuthor Commented:
HI,
   Thanks all experts' comment.
   lomo74,would you give a example ?

thanks
regards
0
lomo74Commented:
hello --
just a draft...
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, StrUtils;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    file1: TMenuItem;
    new1: TMenuItem;
    Label1: TLabel;
    Label2: TLabel;
  private
    procedure WMMouseMove(var Msg: TWMMouseMove); message WM_MOUSEMOVE;
    procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.WMMouseMove(var Msg: TWMMouseMove);
begin
  inherited;
  Label1.Caption := Format('%d, %d', [Msg.XPos, Msg.YPos]);
end;

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
var
  pts, ptc: TPoint;
  pt: Integer;
begin
  inherited;
  if Msg.Result = HTMENU then begin
    pts.X := Msg.XPos;
    pts.Y := Msg.YPos;
    ptc := ScreenToClient(pts);
    //mimic mouse events
    //you can replace the following line with whatever
    Label2.Caption := Format('%d, %d  %s',
      [ptc.X,
       ptc.Y,
       IfThen((GetAsyncKeyState(VK_LBUTTON) and $10000) <> 0,
        '(left button down)',
        '(left button up)')]);
  end;
end;

end.

Open in new window

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 422
  ClientWidth = 516
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 120
    Top = 120
    Width = 31
    Height = 13
    Caption = 'Label1'
  end
  object Label2: TLabel
    Left = 120
    Top = 168
    Width = 31
    Height = 13
    Caption = 'Label1'
  end
  object MainMenu1: TMainMenu
    Left = 248
    Top = 216
    object file1: TMenuItem
      Caption = 'file'
      object new1: TMenuItem
        Caption = 'new'
      end
    end
  end
end

Open in new window

0
Cheng_samAuthor Commented:
hi,thanks the demo
 i test the example.it  only run in mainmenu.there isn't response in submenu.can it be improve?

thanks
regards
0
lomo74Commented:
well, that's hard.
when you press the menu, it enters a message loop controlled by windows.
don't really know how you can hook into this loop.
what's exactly your goal?
0
Cheng_samAuthor Commented:
hi,

    sorry for my late response.
    sometime we need to make some different style operation.to use the mousedown event in Tmainmenu is a cool one i think.i have downloaded the file that BlueVD suggested and tested it.it look fine but need to modified.
thanks
regards
0
Cheng_samAuthor Commented:
Thanks for experts' canswer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.