A simpler way of accomplishing the same effect is to subclass TPopupMenu and add an OnHide (or OnClose or OnCollapse, take your pick of terminology) event hook:
type
TPopupMenuEx = class(TPopupMenu)
private
FOnHide: TNotifyEvent;
protected
procedure DoHide; virtual;
public
procedure Popup(X, Y: Integer); override;
published
property OnHide: TNotifyEvent read FOnHide write FOnHide;
end;
procedure TPopupMenuEx.DoHide;
begin
if Assigned(OnHide) then OnHide(Self);
end;
procedure TPopupMenuEx.Popup(X, Y: Integer);
begin
inherited;
DoHide;
end;
Main Topics
Browse All Topics





by: Slick812Posted on 2004-10-20 at 13:06:03ID: 12362664
hello MauricioMaia, , I have gotten a Notification for a Pop Up Menu closing (disapearing, finished), by getting the application PopupList and subclassing the pop up menu message window and testing for the WM_EXITMENULOOP message.
roc); pList.Wind ow, GWL_WNDPROC, Integer(pMWndProc)));
ndow,GWL_W NDPROC, Integer(pOWndProc)); oc);
der: TObject);
roc(Mess1) ;;
the pop menu closing event is in the WM_EXITMENULOOP message. Your TPopupMenu OnPopUp is the PopupMenu1Popup procedure below, more than One pop up menu can use this procedure, , , , , ,
There are 2 Form events below, the OnCreate and OnClose .
Code for this -
type
THackPList = class(TPopupList);
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
PopupMenu2: TPopupMenu;
private
{ Private declarations }
hPopMenu: THandle;
pMWndProc, pOWndProc: Pointer;
procedure PopWndProc(var Mess1: TMessage);
- - - - - - - - -
procedure TForm1.FormCreate(Sender: TObject);
begin
if PopupList.Count <> 0 then
begin
pMWndProc := MakeObjectInstance(PopWndP
if pMWndProc <> nil then
pOWndProc := Pointer(SetWindowLong(Popu
// subclass the menu window
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// besure to reset the WndProc, if you got other forms with pop menus
if Assigned(pMWndProc) and (PopupList.Count > 0) then
begin
SetWindowLong(PopupList.Wi
FreeObjectInstance(pMWndPr
end;
end;
procedure TForm1.PopupMenu1Popup(Sen
begin // get the Pop up menu handle that has popped
if Sender is TPopUpMenu then
hPopMenu := TPopUpMenu(Sender).Handle;
end;
procedure TForm1.PopWndProc(var Mess1: TMessage);
begin // the pop menu close events are here
THackPList(PopupList).WndP
if (Mess1.Msg = WM_EXITMENULOOP) and (Mess1.WParam = 1) then
if hPopMenu = PopupMenu1.Handle then
begin
// this is the pop menu 1 finish-Close event
Label1.Caption := '1 PopupMenu1 Gone';
end else
if hPopMenu = PopupMenu2.Handle then
begin
// this is the pop menu 2 finish-Close event
Label1.Caption := '2 PopupMenu2 Gone';
end;
end;
- - - - - - - - - - - - - - - - - - - - - - - - - - -
ask questions if you need more info