Solved

Popup menu on system tray icon

Posted on 2000-04-07
12
321 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

762 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

20 Experts available now in Live!

Get 1:1 Help Now