Solved

Unload a popup menu

Posted on 1998-10-15
5
201 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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