Solved

Popup menu on system tray icon

Posted on 2000-04-07
12
326 Views
Last Modified: 2008-03-03
I have successfully put a system tray icon in my program, i have made it so when you right click on the icon a menu pops up. the only problem with it is the menu wont go away. usually they dissapear when you click on something else on the screen, but mine stays there.
here is the code.

        Select Case X
            Case 7695
                Form1.WindowState = vbNormal
                Form1.Show
                Dim hProcess As Long
                GetWindowThreadProcessId hwnd, hProcess
                AppActivate hProcess
            Case 7740
                Me.PopupMenu Me.Menu " <<-- HERE!!
        End Select

can someone tell me what im doing wrong?
0
Comment
Question by:Gunjitsu
  • 6
  • 5
12 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2693726
try the following:
PopupMenu Menu

Honestly, I don't have your problem, and i used just this code in the MouseUp Event...
0
 
LVL 9

Accepted Solution

by:
samopal earned 40 total points
ID: 2693771
To make TrackPopupMenu work properly in the context of a tray, you must first call SetForegroundWindow on the window that owns the popup. Otherwise, the menu will not disappear when the user presses Escape or clicks the mouse outside the menu.
To find out more, search for Q135788 in MSDN

HTH
0
 

Author Comment

by:Gunjitsu
ID: 2703592
how do i call SetForegroundWindow on the window that owns the popup ?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 9

Expert Comment

by:samopal
ID: 2703697
In your code :
....
  Case 7740
'<<-- ADD HERE!!
     SetForegroundWindow Me
'<<-- ADD HERE!!
     Me.PopupMenu Me.Menu
End Select

HTH

0
 

Author Comment

by:Gunjitsu
ID: 2703873
i get a error saying variable not definied and i click debug and its got "SetForegroundWindow" highlighted...
0
 
LVL 9

Expert Comment

by:samopal
ID: 2703987
:-)))
You have to define this API function in module

Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
0
 

Author Comment

by:Gunjitsu
ID: 2704312
i did that.
i also got another api call that gets the current windows system running time in my module. will that affect it?
when i run the program now it goes type mismatch. :(
0
 

Author Comment

by:Gunjitsu
ID: 2704382
i did that.
i also got another api call that gets the current windows system running time in my module. will that affect it?
when i run the program now it goes type mismatch. :(
0
 
LVL 9

Expert Comment

by:samopal
ID: 2704841
What line of programm gives your this error?
Where did you put SetForegroundWindow declaration?
0
 

Author Comment

by:Gunjitsu
ID: 2711708
it highlightes the word SetForegroundWindow after the error pops up.
this is how i got the code

            Case 7740
                SetForegroundWindow Me
                Me.PopupMenu Me.Menu
            End Select
0
 
LVL 9

Expert Comment

by:samopal
ID: 2712122
It seems to me you are making a syntax mistake in your code. Can you send code to me? Today (Apr,13) I have some time...
dmitry_a@hotmail.com
0
 

Author Comment

by:Gunjitsu
ID: 2736759
its
SetForegroundWindow Me.hwnd
not
SetForegroundWindow Me
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

803 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