Solved

Problem with Systray

Posted on 2003-10-23
2
275 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 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