Registriert seit: 9. Jun 2005
Ort: Unna
1.172 Beiträge
Delphi 10.2 Tokyo Professional
|
Re: Onclick und rechte Maustaste!
4. Feb 2006, 18:12
So, hier eine `richtige´ Lösung für Toolbar2000. Damit erhältst du in der Routine WMMyPopup sowohl den Toolbar-Eintrag unter der Maus als auch die Mauskoordinaten für's Popup-Menü.
Delphi-Quellcode:
const
WM_MYPOPUP = WM_USER + 123; // Beliebig
type
TForm1 = class(TForm)
// ... alle anderen Controls, u.a.
PopupMenu1: TPopupMenu;
Label2: TLabel;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
procedure WMMyPopup(var Msg: TMessage); message WM_MYPOPUP;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
HookHandle: THandle;
function HookRightButton(nCode: Integer; wp: WPARAM; lp: LPARAM): LRESULT;
stdcall;
var
Wnd: TWinControl;
Frm: TWinControl;
View: TTBView;
Item: TTBItemViewer;
Pnt: TPoint;
begin
if nCode = HC_ACTION then
begin
with PMsg(lp)^ do
if message = WM_RBUTTONDOWN then
begin
Wnd := FindControl(hWnd);
if Wnd is TTBToolbar then
begin
Pnt := SmallPointToPoint(TSmallPoint(lParam));
ClientToScreen(hWnd, Pnt);
Frm := Wnd.Parent;
while (Frm <> nil) and not (Frm is TCustomForm) do
Frm := Frm.Parent;
if Frm = nil then
Frm := Application.MainForm;
View := TTBToolbar(Wnd).View;
while View <> nil do
begin
Item := View.ViewerFromPoint(View.Window.ScreenToClient(Pnt));
if Assigned(Item) then
begin
PostMessage(Frm.Handle, WM_MYPOPUP, UINT(Item.Item),
UINT(PointToSmallPoint(Pnt)));
break;
end;
if Assigned(View.OpenViewerView) and (View <> View.OpenViewerView) then
View := View.OpenViewerView
else if Assigned(View.Selected.View) and (View <> View.Selected.View) then
View := View.Selected.View
else
View := nil;
end;
end;
end;
end;
Result := CallNextHookEx(HookHandle, nCode, wp, lp);
end;
procedure TForm1.WMMyPopup(var Msg: TMessage);
var
Item: TTBCustomItem;
Pnt: TPoint;
begin
Item := TTBCustomItem(Msg.WParam);
Pnt := SmallPointToPoint(TSmallPoint(Msg.LParam));
Label2.Caption := Item.Caption;
Label3.Caption := Format('%d,%d', [Pnt.X, Pnt.Y]);
PopupMenu1.Popup(Pnt.X, Pnt.Y);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HookHandle := SetWindowsHookEx(WH_GETMESSAGE, @HookRightButton, 0, GetCurrentThreadId);
end;
end.
// Edit: kleine Korrekturen
|
|
Zitat
|