Solved

How to know is a TPopupMenu is not showing?

Posted on 2004-10-20
3
826 Views
Last Modified: 2010-04-05
I need to know if TPopupMenu has stoped of being showing.
Like the reverse of the OnPopop Event. Can somebody give me a tip?
Thanks
Mauricio.
0
Comment
Question by:MauricioMaia
3 Comments
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 125 total points
ID: 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.
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(PopWndProc);
  if pMWndProc <> nil then
    pOWndProc := Pointer(SetWindowLong(PopupList.Window, GWL_WNDPROC, Integer(pMWndProc)));
   //  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.Window,GWL_WNDPROC, Integer(pOWndProc));
  FreeObjectInstance(pMWndProc);
  end;
end;



procedure TForm1.PopupMenu1Popup(Sender: TObject);
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).WndProc(Mess1);;
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
0
 
LVL 2

Accepted Solution

by:
gary_williams earned 125 total points
ID: 12363570
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;
0
 

Author Comment

by:MauricioMaia
ID: 12368925
I'll split points between you two guys. Both answers work
Thanks.
Mauricio.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 82
Delphi selector screen 2 70
Magic Software info 18 125
Installshield for Embarcadero EX 10.1 Berlin 4 20
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now