Solved

Unload a popup menu

Posted on 1998-10-15
5
202 Views
Last Modified: 2010-04-30
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
Comment
Question by:pjroy
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:traygreen
ID: 1440246
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
 

Author Comment

by:pjroy
ID: 1440247
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
 
LVL 14

Expert Comment

by:waty
ID: 1440248
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
 

Author Comment

by:pjroy
ID: 1440249
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
 
LVL 14

Accepted Solution

by:
waty earned 20 total points
ID: 1440250
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question