Visibility of PopUp menu

How to determine, whether a PopUp menu is visible at the moment ?
I have custom event, which mustn't be called when popup is visible.
AleqAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alisher_NCommented:
are you a creator of this pop-up menu or no ?
0
Alisher_NCommented:
if you are:

Procedure MyCustomEvent;

begin
  if MyPopUpMenu.Visible then Exit;
  // no, not visible, do what you wanted
  //
end;
0
florisbCommented:
visible is not a popup property
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

AttarSoftwareCommented:
Have a public variable on your form (isPoppedUp : boolean), and then in the OnPopUp event of the menu :

procedure tForm1.Popupmenu1Popup( sender : tObject ) ;
begin
  isPoppedUp := true ;
end ;

And in the onClick events of your menuItems, put:

  isPoppedUp := false ;

and then you can check it with

  if( isPoppedUp ) then
  begin
    ShowMessage( 'NO!' ) ;
    exit ;
  end ;

Cheap and cheerful ;O)

Good Luck,

Tim.
0
florisbCommented:
****, I just tried it myself, can't find the easy solution (asking the popup whether it's up).

AttarSoftware: Does only works if user selects item... ...not if he clicks out of the form after the drop down...
0
AttarSoftwareCommented:
Oh yeah ;O)

Doh!!

Tim.
0
AttarSoftwareCommented:
If you call GetTopWindow( 0 ) then the handle returned is different when a PopupMenu is displayed, but I cannot see how this handle returned relates to either the window, or the PopupMenu...

Heh, guess we are no nearer...

Tim.
0
florisbCommented:
Errrrr. I'm waiting for a college and start to feel stupid I can't solve this... I couldn;t find what to to with the handle of the popup.

When does your custom event happen by the by?


procedure customEvent;
//just prevents the popup when in your custum event...
begin
form1.popupmenu := nil;
//your code here.
form1.popupmenu := popupmenu1;
end;







0
Alisher_NCommented:
in addition to AttarS suggestion we can also add
isPopUpVisible := False;
to OnActivate event of main (or underlying) form, so when we back from PopUp (or other window) we set IsPopUpVisible to proper state (when you click main form again - popup disappears)

Only one potential problem is occurs when this 'CustomEvent' required to be valid even if mainform in background state... what about this, Aleq ?
0
florisbCommented:
Errrrr. I'm waiting for a college and start to feel stupid I can't solve this... I couldn;t find what to to with the handle of the popup.

When does your custom event happen by the by?


procedure customEvent;
//just prevents the popup when in your custum event...
begin
form1.popupmenu := nil;
//your code here.
form1.popupmenu := popupmenu1;
end;







0
AleqAuthor Commented:
Alisher: No, I'm not a creator - I ment delphi default Popup menu

Attar: I also tried GetWindowPlacement and watched the showcmd. It had different values when popup menu was shown and when it was hidden, but the value of visible popup also depends on system, so it's not usable ...

Florisb: the situation is: it is my own editor component, that's makes event MouseTimeOut (when hint should be shown). This event is used (in IDE application) to inspect variable value. The problem is, when user clicks right mouse button. Popup menu is shown but MouseTimeOut event occurs (since user moves mouse in editor area). In this event, user calls method for showing hint (and it is shown under or above the popup)....


Alisher: I'll try the OnActivate solution ...

---
BTW, I also tried to inspect messages. I used winspector and watched what's coming when user right clicks and when the menu disappears - nothing ! damn...
0
Alisher_NCommented:
not clear... what delphi default popup ???
if you create a from there is no any popup until you create & assign it...
or popup in another program ?
0
AleqAuthor Commented:
I meant the popup component I use is the one, that is shipped with delphi (not my own custom component).
Yes, I create a form and a popup and than I assign that popup to the editor....
0
Alisher_NCommented:
;-) it doesn't matter who wrote it, if you use it that means for me that
you are the creator (in scope of this program) and you have access to
Popup's items code

now I think my suggestion + AtarSoft will do the thing:

insert in every procedure of Popup items
isPopupVisible := True;

and into OnActivate event of main form
isPopupVisible := False;

0
SteveWaiteCommented:
WM_CONTEXTMENU is message from OnPopup but no message found for close popupmenu.
WM_MENUSELECT and the others only seem to work on main menus.

You could also find the rect of popup and test the mouse pos outside of rect but find below something less kludgy.

I hope this helps.

Steve


//-----------------------------

type
  TForm1 = class(TForm)
    ..
    ..
  private
    { Private declarations }
    procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
    procedure WndProc(var Message: TMessage); override;
    ..
    ..
  public
    { Public declarations }
    MenuShowing: Boolean;
    ..
    ..
  end;

implementation
{$R *.DFM}

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  MenuShowing := True;
end;

procedure TForm1.WndProc(var Message: TMessage);
begin
  case Message.Msg of
    WM_KILLFOCUS: MenuShowing := False;
  end;
  inherited WndProc(Message);
end;

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  case Msg.message of
    WM_KEYUP,
    WM_LBUTTONDOWN,
    WM_RBUTTONDOWN,
    WM_MBUTTONDOWN,
    WM_NCLBUTTONDOWN,
    WM_NCRBUTTONDOWN,
    WM_NCMBUTTONDOWN:
      MenuShowing := False;
  end;
  Handled := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := AppMessage;
  MenuShowing := False;
end;

//-----------------------------

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveWaiteCommented:
PS
Forgot to mention

procedure TForm1.PopupMenu1Item1Click(Sender: TObject);
begin
  MenuShowing := False;
end;

for each item

Steve
0
SteveWaiteCommented:
And.. should put
procedure WndProc(var Message: TMessage); override;
in { Public declarations }.
Just a note. within AppMessage() - needs to be WM_KEYUP because keydown is handled by the menu.
   
0
gandalf_the_whiteCommented:
listening...
0
JesperRisagerCommented:
0
SteveWaiteCommented:
Thanks Jasper!
0
AleqAuthor Commented:
Indeed.
Thanx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.