Solved

Problem with Systray

Posted on 2003-10-23
2
277 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
[X]
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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

751 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