Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Unload a popup menu

How do I unload a menu loaded with PopupMenu?

       When I right click at another place, I want the menu to be closed and reopened a new one.
0
pjroy
Asked:
pjroy
  • 2
  • 2
1 Solution
 
traygreenCommented:
on the mousedown event for the conrol disable the control then renable it on the form mouse up

eg.
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  if Button = vbRightButton then
     Text1.Enabled = True
  end if
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Text1.Enabled = False
End Sub

If there are multiple controls on the form that you wish to disable you will need to save the control to a form level variable

eg.
Private mControl As Control

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   mControl.Enabled = True
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Text1.Enabled = False
   Set mControl = Text1
End Sub

I know there is a method through the API, but this works for a quick and dirty

0
 
pjroyAuthor Commented:
It doesn't work for a popup menu.

What I want to do is to unload a popup menu.

When I right click elsewhere, nothing happens. I have the left click elsewhere for the menu to disappear.
0
 
watyCommented:
Do as follow :

Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_USER = &H400&



      SetForegroundWindow Me.hwnd            ' Set current window as ForegroundWindow
      DisplayPopupMenuTaskbar
      PostMessage Me.hwnd, WM_USER, 0&, 0&   ' Update form...

0
 
pjroyAuthor Commented:
It's not really clear.
In wich event I put this code?
 SetForegroundWindow Me.hwnd            ' Set current window as ForegroundWindow
 DisplayPopupMenuTaskbar  //what is this function?
 PostMessage Me.hwnd, WM_USER, 0&, 0&   ' Update form...

Here is my code from Node Click event:
if Button = vbRightButton Then        
   PopupMenu mnuPopup
End If

Now if I right click elsewhere, I want the menu to be closed.
If I open it with PopupMenu mnuPopup,
how can I close it?

Thanks
0
 
watyCommented:
Do as follow :

if Button = vbRightButton Then        
   SetForegroundWindow Me.hwnd            ' Set current window as ForegroundWindow
   PopupMenu mnuPopup
   PostMessage Me.hwnd, WM_USER, 0&, 0&   ' Update form...
End If


0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now