Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Tray icon popup menu problem 2

Status
Not open for further replies.

darkman0101

Technical User
Oct 10, 2000
51
0
0
NZ
I have added an icon (form) to the system tray using the Shell_NotifyIcon api. The form has a menu that I pop up if the right mouse button is pressed on the form, (which is captured with the form's MouseMove event).

If one clicks the desktop (or anywhere outside the popup menu) the menu remains visible. With other applications if one clicks outside the menu the menu closes.

How is this done? do I need to obtain the hWnd for hte meny and capture messeges sent to it and look for when it looses focus?
 
I've had the exact same problem on a previous project. In the Tools/Unsupported folder in Visual Studio folder, there's a folder called systray which has a custom control. You need to add this to your project and follow the instructions included.

This worked fine for me.
 
The problem is that the window handling you tray icon is not active when you click to display the menu.

Set the window to the active window using API SetForegroundWindow(Hwnd) just before you popup the menu.

The window will then receive the lose focus event when you click off the menu, and hide the popup menu for you...
 
Sweet,
thanks for that that was the missing link that I was looking for.

Cheers

Jas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top