• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 645
  • Last Modified:

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
0
Cheng_sam
Asked:
Cheng_sam
  • 5
  • 3
  • 2
  • +2
3 Solutions
 
aikimarkCommented:
what version of Delphi are you using?
0
 
Cheng_samAuthor Commented:
hi,
    delphi 2010


thanks
regards
0
 
developmentguruCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now