Solved

Popup menu on system tray icon

Posted on 2000-04-07
12
325 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

896 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

16 Experts available now in Live!

Get 1:1 Help Now