pjroy
asked on
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.
When I right click at another place, I want the menu to be closed and reopened a new one.
ASKER
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.
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.
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...
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...
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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