Solved

Problem with Systray

Posted on 2003-10-23
2
276 Views
Last Modified: 2010-05-01
Hi, my english is not very good, but anyway:
my application puts an icon in the systray and when you rightclick the icon a popup menu appears; ok that works very good, but the problem is that when you rightclick on the icon and you later decide not to click on any of the menu's on the popup menu, the popupmenu stays, nomather where you click even if you click somewhere on the desktop it does not go away.

please help me with this problem.

thank you,
Stasio
0
Comment
Question by:stasio
2 Comments
 
LVL 5

Accepted Solution

by:
JCinDE earned 250 total points
ID: 9608814
It's really easy to solve.

Add this API declaration to your code:

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

Call it right before you call the PopupMenu function:

    SetForeGroundWindow Me.hWnd
    PopupMenu mnuPopup

This causes your app to take focus before displaying the menu. When you click away from the menu, your app loses focus again and destroys the menu. If you don't call this then your app never takes focus until you actually click a menu item...so if you click somewhere else instead of the menu, it never receives the 'lost focus' message and doesn't get rid of the menu.

Hope it helps!
-JC
0
 
LVL 27

Expert Comment

by:planocz
ID: 10173594
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
No response from stasio from 10/23/2003 comment
Award points to JCinDE is recommend.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

planocz
EE Cleanup Volunteer
0

Featured Post

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.

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…
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…
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…

830 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