Solved

Closing menu opened by Tray icon

Posted on 1998-01-07
2
154 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 91
Machine not responding during CopyFile() 3 98
oracle global variables 4 68
TEMBEDDEDWB how can i change its user agent ? 8 58
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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