We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Determine if right click menu is shown

amnav
amnav asked
on
Medium Priority
284 Views
Last Modified: 2010-05-02
Hi,

I built an Auto logoff mechanism in my application.
If user left system after he right click on one of my controls, and right click menu has appeared,
the auto logoff is working incorrectly - when I unload the form, the function that operate the pop up menu is still active.

I want to cancel the auto logoff if pop up menu is shown.
Is there a way to determine if a pop up menu is shown ?
Of course, I can set some flag before I open menus, but I prefer a better way

Thanks
Comment
Watch Question

Commented:
PopupMenu() and TrackPopupMenu(Ex) (API) both wait for returns before processing anything else so the thread will be "blocked". If your "Auto logoff mechanism" is within it's own thread (a Timer control for example), it won't be effected by it. Your only likely option is just to use a flag-variable to check if any PopupMenus are open at the time and I doubt there are any more efficient methods (will take note to any if they're posted). A few boolean variables shouldn't harm much.

You could always just create your own windows (WS_POPUP) and try to simulate PopupMenus though. You can avoid the input-asynchronous behavior that way (at a costly price however).



FYI, interested in possible solutions for this question also now.

Commented:
I think the simplest way to do this would be to add a global boolean variable ie blnPopupShown

Then when you display a popup menu do the following

blnPopupShown = True
popupmeeu  ....
blnPopupShown = False

Then in your timeout feature just add
If Not blnPopUpshow Then
 timeout code
End If

Commented:
you can check for the visibilty of the popupmenu, in case the menu is invisible at design time. something like this




if not myPop.Visible then unload me

as long as the popup is displayed the visible property returns true. once the popup is closed its visible property returns false.

Commented:
If the menus are only used as popup, then you can just check the visibility of the menu.

Commented:
Hi,
If you don't use SetCapture in your code, you can use GetCapture to determine if popup window captured mouse.
GetCapture will return 0 if there is no popup shown, and <> 0 if your popup, or textbox's built-in popup menu is shown.  (If you are using SetCapture in your code, you know that it is similar in behavior, i.e. normally code waits for another mouse action and it should be treated the same as popup.)

' Form1, add menu mnuPop (visible=false) and a submenu
'        also, add Textbox and Timer (interval=1000)
Option Explicit
Private Declare Function GetCapture Lib "user32" () As Long

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then Me.PopupMenu Me.mnuPop
End Sub

Private Sub Timer1_Timer()
    Beep
    Caption = GetCapture ' shows 0 or, if menu is shown, some value <>0
End Sub

Commented:
GetCapture will also return non-zero, if your mouse action is in progress, e.g. you are holding mouse down and moving it.  Hope it is OK behavior.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Cool!

Commented:
My recommendation:
    Split: ameba {http:#10814855} & zzzzzooc {http:#10819088}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.