Re: System Tray Icon Actions

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: MikeD (nobody_at_nowhere.edu)
Date: 03/27/04


Date: Fri, 26 Mar 2004 19:46:18 -0500


"Matthew Shaw" <matted@[REMOVETHIS]bigpond.net.au> wrote in message
news:eXV4Ph0EEHA.4008@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I've read and implemented the instructions for displaying my app in the
> system tray here:
> http://vbnet.mvps.org/code/subclass/shellnotifybasic.htm
>
> ...and it works, except that I can't seem to figure out how to make a
popup
> menu appear when I right click on the icon in the system tray. My icon is
> appearing but nothing happens when I single/right/doubleclick on the icon.
> My form is hidden by the way (is this the reason, if so, how do I get
around
> it?).What do I need to code to do this (I presume I must have missed
> something)?
>
> I actually just want the user to be able to single click or double click
on
> the icon in the tray and have my app show (it hides when the user clicks
> "send to tray") - is this easy (relativly), or is a popup menu (that I can
> implement myself with the menu editor ect.) easier.

You need to post relevent parts of YOUR code since it's surely not identical
to Randy's. Most likely, you did just miss something, but we need to see
your code to know what you missed.

However, some things to check:

For a single-click (presumably you mean the left button only), you'd have to
check if lParam is WM_LBUTTONUP, and check if lParam is WM_LBUTTONDBLCLK for
a double-click. Augmenting Randy's code to show the form for a left button
click or double-click (although it makes little sense to do the same thing
for both and I wouldn't recommend it), you'd have something like this:

              'lParam is the value of the message
              'that generated the tray notification.
               Select Case lParam
                  Case WM_RBUTTONUP:

                    'show the menu
                     With Form1
                        .PopupMenu.zmnuDemo
                     End With

                  Case WM_LBUTTONUP, WM_LBUTTONDBLCLK
                     Form1.Show

               End Select

Personally, I think the call to SetForegroundWindow should be done in the
WM_RBUTTONUP case (actually, only before showing a context menu), NOT
outside the Select Case as Randy's code does.

A hidden form shouldn't cause any problems. The form is still loaded and
receiving messages (which you're getting via the subclass) If the form
isn't loaded, well, that's a problem because you're NOT getting any messages
for it.

If you're showing a menu for the user to be able to do other things besides
just show the form, you should probably add a "Show" menu command (give it
whatever meaningful caption you want) and indicate that is the default for
double-clicking the icon (by making that menu command bold, done via a
parameter you pass to the PopupMenu method). Then, you'd need to show the
form for WM_LBUTTONDBLCLK as I've shown (again, I recommend against taking
the same action for WM_LBUTTONUP). If the "Show" menu command is the only
menu item, then I don't think I'd have the popup menu at all.

As I said, you need to post your code because there's just too many things
you've most likely changed from Randy's code to use his code a basis for the
problem you're having.

Mike


Quantcast