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
Solved

Popup menu on system tray icon

Posted on 2000-04-07
12
328 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 143

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…

791 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