Solved

Closing menu opened by Tray icon

Posted on 1998-01-07
2
149 Views
Last Modified: 2012-05-04
If you create a program that resides in the tray that responds to mouse messages and opens a pop-up menu when right-clicked, how do you make the menu close if the user clicks OUTSIDE the menu? Currently, only messages generated inside the menu are sent via the callback.
0
Comment
Question by:nslip
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
Comment Utility
Try the following when you pop your popup menu up:

SetForegroundWindow(Self.Handle);
try
      PopupMenu.Popup(X, Y);
finally
      SetForegroundWindow(Self.Handle);
end;

(Self.Handle is the tray component's handle.)

Regards,
JB
0
 

Author Comment

by:nslip
Comment Utility
For some reason, in CBuilder I had to call the Popup routine twice or the menu would only re-appear after the second right-click if the first left-click was outside the menu. The code of the form's FormMouseMove method looks like this now:

if (X == WM_RBUTTONUP) {
   GetCursorPos(&pos);
   SetForegroundWindow(Handle);
   try {
      PopupMenu1->Popup(pos.x,pos.y-20);
      PopupMenu1->Popup(pos.x,pos.y-20);
   } catch(...) {
      SetForegroundWindow(Handle);
   }
}

Thanks JimBob!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now