Board index » cppbuilder » How to know if Popup menu is visible or not

How to know if Popup menu is visible or not


2004-01-08 05:32:46 PM
cppbuilder19
Hello there! Is there a way of knowing if a popup menu is visible
or not, other than using formcontextpopup and popuppoint.x or y?
Thanks!
--13--@
 
 

Re:How to know if Popup menu is visible or not

"Jet" < XXXX@XXXXX.COM >wrote in message
Quote
Hello there! Is there a way of knowing if a popup menu
is visible or not
You could try using the menu's OnPopup event, but there is no
straight-forward way to determine when the menu is closed, short up
intercepting WM_COMMAND and/or WM_EXITMENULOOP messages manually.
Quote
other than using formcontextpopup and popuppoint.x or y?
That is an easier way to handle it.
Gambit
 

Re:How to know if Popup menu is visible or not

Quote
>other than using formcontextpopup and popuppoint.x or y?

That is an easier way to handle it.


Gambit

A follow-up q: Why is it that popuppoint.x still has a value
even if I used the menu's shortcut? Is it using the previous
value when it popped up?
---13--@
 

{smallsort}

Re:How to know if Popup menu is visible or not

"Jet" < XXXX@XXXXX.COM >wrote in message
Quote
A follow-up q: Why is it that popuppoint.x still has a
value even if I used the menu's shortcut?
I can't answer that until you specify where the value is coming from in the
first place.
Gambit
 

Re:How to know if Popup menu is visible or not

Quote
>... popuppoint.x still has a value even if I used the menu's shortcut?

I can't answer that until you specify where the value is coming from in the
first place.


Gambit
I assigned a PopupMenu, PopupMenu1 to a TForm. Then I assigned
an action, Action1, with a shortcut, Ctrl+A to PopupMenuItem1.
When PopupMenu1 pops up, PopupMenu1->PopupPoint.x = 700, for example. But when PopupMenu1 is no longer visible and I use
Ctrl+A, PopupMenu1->PopupPoint.x is still 700. So, I can't
use it to determine if the popupmenu is visible.
About WM_COMMAND and/or WM_EXITMENULOOP ... can you please
give me an idea on how to use these message handlers? Thanks!
Jet
 

Re:How to know if Popup menu is visible or not

"Jet" < XXXX@XXXXX.COM >wrote in message
Quote
When PopupMenu1 pops up, PopupMenu1->PopupPoint.x = 700,
for example. But when PopupMenu1 is no longer visible and I use
Ctrl+A, PopupMenu1->PopupPoint.x is still 700.
The PopupPoint property is only updated when Popup() is called to actually
display the menu.
Quote
So, I can't use it to determine if the popupmenu is visible.
No, that is not a good approach to determine if the menu is still visible.
Why do you need this anyway? While the menu is displayed, the main thread
can't do anything else anyway, so what good is detecting the menu if your
code wil never run while the menu is actually visible to begin with? Please
explain in more detail exactly what you are trying to accomplish.
Gambit
 

Re:How to know if Popup menu is visible or not

Quote
The PopupPoint property is only updated when Popup() is called to actually
display the menu.
-->But I placed the PopupPoint.x variable inside
PopupMenu1Popup =(
Quote

Why do you need this anyway?
-->It's because in my code :
void __fastcall TMainForm::PopupMenu1Popup(TObject *Sender)
{
TPopupMenu* Menu;
Menu = (TPopupMenu*)Sender;
if(Menu->PopupComponent == NULL) return;
if(PopupMenu1->PopupPoint.x < 0) return;
if(Menu->PopupComponent->ClassNameIs("TMyControl")){
PopupMenuItem1->Enabled = true;
PopupMenuItem2->Enabled = true;
}
else{
PopupMenuItem1->Enabled = false;
PopupMenuItem2->Enabled = false;
}
}
the first time the shortcut is used, it enters Popup()
and the PopupComponent is NULL, so there is no problem with
that.
However, when the popupmenu pops up and then cancelled so
that it is no longer visible, the next time the
shortcut is used, it still enters Popup() and the
PopupComponent is not NULL anymore. Also, the popuppoint
retains its previous value. This causes an access violation,
when it reaches the line
if(Menu->PopupComponent->ClassNameIs("TMyControl")) ...
... and i need it to enable or disable my menu items.
 

Re:How to know if Popup menu is visible or not

"Jet" < XXXX@XXXXX.COM >wrote in message
Quote
>Why do you need this anyway?
-->It's because in my code :
You're still not making any sense. You still have not explained why you
need to detect the menu being visible or not. Inside the OnPopup event, the
menu will ALWAYS be visible immediately afterwards the event handler
exiting. There is no reason to test the PopupPoint property or anything
else for that matter. Just update your items with the assumption that the
menu is visible. That is what the OnPopup event is for - updating the menu
when it is being displayed.
void __fastcall TMainForm::PopupMenu1Popup(TObject *Sender)
{
TPopupMenu* Menu = static_cast<TPopupMenu*>(Sender);
TMyControl *ctrl = dynamic_cast<TMyControl*>(Menu->PopupComponent)
PopupMenuItem1->Enabled = (ctrl != NULL);
PopupMenuItem2->Enabled = (ctrl != NULL);
}
Gambit