unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TForm1 =
class(TForm)
PopupMenu1: TPopupMenu;
PopupItem11: TMenuItem;
popupitem21: TMenuItem;
submenu1: TMenuItem;
Label1: TLabel;
procedure PopupItem11Click(Sender: TObject);
procedure PopupItem21Click(Sender: TObject);
procedure PopupItemClick(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
private
FSelectedItem: TMenuItem;
FTracking: Boolean;
procedure MenuRButtonUp(
var Msg: TMessage);
message WM_MENURBUTTONUP;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.MenuRButtonUp(
var Msg: TMessage);
// ??? wird nie aufgerufen
var
Cmd: UINT;
begin
Label1.Caption := TimeToStr(now);
LongBool(Cmd) := TrackPopupMenuEx(PopupMenu1.Handle,
TPM_RECURSE
or TPM_BOTTOMALIGN
or TPM_RETURNCMD,
Mouse.CursorPos.X, Mouse.CursorPos.Y,
Handle,
nil);
if Cmd <> 0
then
PopupMenu1.DispatchCommand(Cmd);
inherited;
end;
procedure TForm1.PopupItem11Click(Sender: TObject);
begin
Caption := TimeToStr(Now)+'
Popup Item 1 clicked on ';
end;
procedure TForm1.PopupItem21Click(Sender: TObject);
begin
// whatever..
Caption := TimeToStr(Now)+'
Popup Item 2 clicked on ';
end;
procedure TForm1.PopupItemClick(Sender: TObject);
begin
Caption := TimeToStr(Now)+'
clicked on '+TMenuItem(Sender).Caption;
end;
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var mi : TMenuItem;
begin
submenu1.Clear;
mi := TMenuItem.Create(PopupMenu1);
mi.Caption := '
Test1';
mi.OnClick := PopupItemClick;
submenu1.Add(mi);
mi := TMenuItem.Create(PopupMenu1);
mi.Caption := '
Test2';
mi.OnClick := PopupItemClick;
submenu1.Add(mi);
end;
end.