Solved

Unload a popup menu

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now