Solved

Closing menu opened by Tray icon

Posted on 1998-01-07
2
152 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
ID: 1355734
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
ID: 1355735
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

11 Experts available now in Live!

Get 1:1 Help Now