![]() |
mbLeft und mbRight bei Menü- und Popup-Items unterscheiden?
Hallo!
Weiß jemand, wie man die Ereignisse "mbLeft!" und "mbRight" beim Betätigen eines Menü- oder Popup-Items ermitteln kann, um verschiedene Funktionen darauf zu setzen? Gruß aus dem Emsland Max |
Re: mbLeft und mbRight bei Menü- und Popup-Items unterscheid
Das ist wohl nicht möglich, da die beiden Menüs kein OnMouseDown-Ereignis haben.
|
Re: mbLeft und mbRight bei Menü- und Popup-Items unterscheid
Hi,
habe mal bei google gesucht und folgendes gefunden, vieleicht hilft dir das weiter:
Delphi-Quellcode:
Zum testen einfach ein Menu auf dein Form und ein Label1. Beim Rechtsklick auf des Menuitem wird dann WOW und die Mouseposition angezeigt, wenn alles klappt.
private
{ Private declarations } hMenuUp: Integer; procedure EnterMenu(var Msg: TMessage); message WM_ENTERMENULOOP; procedure ExitMenu(var Msg: TMessage); message WM_EXITMENULOOP; procedure InitMenu(var Msg: TMessage); message WM_INITMENUPOPUP; var Form1: TForm1; hMHook: Integer; implementation function HookFunc(Code, wParam: Integer; var MouseStrut: TMOUSEHOOKSTRUCT): Integer; stdcall; var MenuItem: cardinal; begin Result:=CallNextHookEx(hMHook, Code, wParam, Integer(@MouseStrut)); if Code < 0 then Exit; {this test for the Right button Up and if the hMenuUp if the first sub-menu in the main menu} if (Code = HC_ACTION) and (wParam = WM_RBUTTONUP) and (Form1.hMenuUp = Form1.MainMenu1.Items[0].Handle) then begin {get the menu item of the of the sub-menu clicked on} MenuItem := Cardinal(windows.MenuItemFromPoint(Form1.Handle, Form1.MainMenu1.Items[0].Handle, MouseStrut.pt)); if MenuItem = 0 then // if Top Menu Item then write some numbers on the Label for a Right click on that Item Form1.Label1.Caption := 'WOW '+IntToStr(MouseStrut.pt.x)+' '+IntToStr(MouseStrut.pt.y)+' '+IntToStr(MenuItem) else Form1.Label1.Caption := 'Not Item zero'; end; end; procedure TForm1.InitMenu(var Msg: TMessage); var MRect: TRect; begin Msg.Result := 0; hMenuUp := Msg.WParam; {get the handle of the sub-menu that is showing in the hMenuUp} end; procedure TForm1.EnterMenu(var Msg: TMessage); begin {start the hook when the menu is shown} Msg.Result := 0; if (Msg.WParam = 0) and (hMHook = 0) then hMHook := SetWindowsHookEx(WH_MOUSE, @HookFunc, hInstance, 0); end; procedure TForm1.ExitMenu(var Msg: TMessage); begin {kill hook on menu close} Msg.Result := 0; if hMHook <> 0 then if UnhookWindowsHookEx(hMHook) then hMHook := 0; end; Bei mir hats funktioniert. Ich hoffe ich hab dich richtig verstanden und es ist das was du brauchst. Gruss p0ke |
Re: mbLeft und mbRight bei Menü- und Popup-Items unterscheid
Hallo!
Ja super! Das Beispiel kann ich auf mein Programm anwenden. Danke noch einmal und einen guten Rutsch. Gruß Max |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:18 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz