Results 1 to 11 of 11

Thread: Dismiss a PopuMenu in code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Dismiss a PopuMenu in code?

    When moving a pointer over a control I'm invoking a hidden "What's this?" PopupMenu to give user a help on that functionality.

    The control has MouseEnter and MouseLeave events so I show the popup in MouseEnter, but I'd like to remove the menu in MouseLeave if user doesn't click on the menu.

    Can I remove PopupMenu without clicking on it?
    Thanks

    Tomexx.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Dismiss a PopuMenu in code?

    Doesn't it go away if the user clicks on anything else other than the popup menu? That's the default behavor of a popup menu.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dismiss a PopuMenu in code?

    Does this help?

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Dismiss a PopuMenu in code?

    Hack,

    Not to attempt to draw away from his post but what causes a popup menu to not go away by clicking elsewhere? I have never had that problem.

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Dismiss a PopuMenu in code?

    The popup menu will go away if you click anywhere else on the form...but I think that is his point. I'm assuming he wants the menu to go away when the mouse leave the control without having to click anywhere.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dismiss a PopuMenu in code?

    Quote Originally Posted by MarkT
    The popup menu will go away if you click anywhere else on the form...but I think that is his point. I'm assuming he wants the menu to go away when the mouse leave the control without having to click anywhere.
    Correct, and correct.....

    I use the code in the link I posted with popup menus from my programs that are running in the system tray, so I'm guessing that might work with his as well.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Dismiss a PopupMenu in code?

    Hi Guys,
    I'm back.

    MarkT is right, I'd like to move the mouse over a control, see popup menu, then move away and for menu to dissapear.

    Hack, I tried the SetForegroundWindow() but didn't work for me
    I also tried EndMenu() same result.

    BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.

    When the user actually does click the menu, I'm showing a help form.
    Thanks

    Tomexx.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dismiss a PopupMenu in code?

    Quote Originally Posted by Tomexx
    BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.
    That would explain why it didn't work for you.

    I was testing on a standard VB command button (and you can code the mouse enter/mouse leave with a couple of API calls.)

    I'll take a look at his XPButtons and see if I can come up with something.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Dismiss a PopuMenu in code?

    Thanks Hack,
    Can you also show me how to code those MouseEnter & MouseLeave events for use with standard buttons?
    Thanks

    Tomexx.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dismiss a PopuMenu in code?

    I suspect Woka's buttons are a lot cooler looking so I wouldn't swap everything out just yet. I'm sure there is a way to get this done using what you currently have. Like I said, I'll take a look and see if I can come up with anything.

    This is for future reference.
    Code:
    Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long 
    Private Declare Function ReleaseCapture Lib "user32" () As Long 
    Private Declare Function GetCapture Lib "user32" () As Long 
    
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (X < 0) Or (Y < 0) Or (X > Command1.Width) Or (Y > Command1.Height) Then 
           ReleaseCapture 
           'the mouse is no longer over the button, so do whatever
    ElseIf GetCapture() <> Command1.hwnd Then 
           SetCapture Command1.hwnd 
           'the mouse is over the button, so do whatever
    End If
    End Sub

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Dismiss a PopupMenu in code?

    Quote Originally Posted by Tomexx
    Hack, I tried the SetForegroundWindow() but didn't work for me
    I also tried EndMenu() same result.

    BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.
    I'm not familiar with Woka's vbXPbuttons but I just had a similar problem where I use subclassing to detect the mouse buttons and found that PopupMenus don't close when clicking the Forward or Back mouse buttons, so to solve that I just set the parent's .Enabled property to False then set it right back to True and the PopupMenu closes!
    Code:
    Public Sub ClosePopUpMenu()
        ' Called from hook - forward/back mouse buttons.
        If MnuSave.Visible = True Then ' check one of the visible menu options.
            Me.Enabled = False
            Me.Enabled = True
        End If
    End Sub
    If vbXPbuttons mouseleave event does not fire when a PopupMenu is visible then I'd guess you'd have to subclass or use a timer to track the mouse cursor position
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width