Button Click

Hi All,

I have an application that is not visible to the user except within the system tray.

When the user clicks on the icon in the system tray, a popup menu appears. How do I make the popup close when the user clicks anywhere else except on one of the menu options?

Thanks in advance,
Chad
dhertzfeAsked:
Who is Participating?
 
intheConnect With a Mentor Commented:
Just before you call PopupMenu.Popup, make an API call:
 
      SetForegroundWindow(Handle);
 
This will force your application to get focus and, upon losing the focus (by clicking on the desktop), the popup will close correctly.
 
Regards Barry
0
 
RBertoraCommented:
How about just using a timer
and hiding it say after 5 seconds or
some timeout interval:
to hide it use

showwindow(popupmenu1.Handle,SW_HIDE);

Rob ;-)
0
 
JaymolCommented:
I had a crappy systemtray component that had this problem.  I couldn't be bothered trying to sort it out, so I just put a "Close Menu" option on the menu and told people it was a special feature (Keeping the menu open) and no other Windows program did it!  People thought it was cool!

Just leave the event handler for "Close Menu" blank.

I know this isn't an answer, but it works.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
RBertoraCommented:
How about using a ttimer to count down a timeout and then hiding it yourself with:


  showwindow(popupmenu1.Handle,SW_HIDE);

Rob ;-)
0
 
dhertzfeAuthor Commented:
Thanks Barry it works perfectly.
0
 
intheCommented:
glad to hear it as i didnt test first  ;-)
0
 
RBertoraCommented:
Good one Inthe!
Rob ;-)
0
All Courses

From novice to tech pro — start learning today.