Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Problem with Systray

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
stasio
Asked:
stasio
1 Solution
 
JCinDECommented:
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
 
planoczCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now