views:

1451

answers:

2

Is there a way in Delphi 7 to find out if a pop-up menu is visible (shown on the screen) or not, since it lacks a Visible property.

+2  A: 

You could make your own flag by setting it in the OnPopup event. The problem is knowing when the popupmenu is closed. Peter Below has a solution for that.

But my I ask why you would want this? Maybe there is a better way to solve the underlying problem.

Lars Truijens
A control pop's up the menu, now I want to show the menu under certain conditions when the control is clicked again. Problem is when the menu is displayed and the click happens outside the menu the menu get's closed, and the control doesn't know if the menu is visible. (hope it is not to confusing)
Drejc
I think that the link @Lars has given you, to Peter Below's solution, will help you to do this, then. As Lars said, Peter's code should enable you to keep some kind of state/track variable of your own. Good luck!
robsoft
The Bellow example works OK, but you need to store the state in some place as the message does not get propagated to controls but only to the form. (So at least in my example)
Drejc
+1  A: 

This seems to be a bit simpler (I used Delphi 2007):

In your WM_CONTEXTMENU message handler, before calling the inherited handler, the popup menu is about to be shown, you can set your flag. After calling inherited, the popup menu has been closed, reset your flag.

procedure TForm1.WMContextMenu(var Message: TWMContextMenu);
begin
  FPopupActive := True;
  try
    OutputDebugString(PChar(Format('popup opening', [])));
    inherited;
  finally
    FPopupActive := False;
    OutputDebugString(PChar(Format('popup closed', [])));
  end;
end;
TOndrej