Solved

Unload a popup menu

Posted on 1998-10-15
5
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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