Q: Minimizing to system tray?? 
Author Message
 Q: Minimizing to system tray??

   I would like to be able to minimize the program i am working on,
but only have it sit in the tray, not the task bar, you know, by the
clock, and have it open on right click or double left click, like most
tray items, is this controlled by VB or something else? If its VB and
you know how, please fill me in

Fri, 24 Aug 2001 03:00:00 GMT  
 Q: Minimizing to system tray??
I got this text file from a vb page and can actually get it working i only hope
that you can understand it and that i can send that much text

so here it is

Much of the code in this article was developed by Benjamin Bourderon of
Villeurbanne, Rh?ne Alpes,

           The Windows 95 taskbar features a notification area (sometimes
called the system tray) - a location where
           utilities running in the background can display an icon, giving the
user access to the application without tying up a
           slot on the taskbar. For instance, a printer icon appears in the
notification area when you send a document to

           In this article, we'll show you how to place an icon in the
notification area and respond to mouse events. Of
           course, before you display an icon in the notification area, you
should be sure it makes sense for your
           application to do so. If too many applications display such icons,
the notification area will become overcrowded,
           defeating its intended purpose.

           The API

demonstrate requires a call to the
           Shell_NotifyIcon 32-bit API. You can't call this API from the 16-bit
version of Visual Basic - Shell_NotifyIcon
           works only under the Windows 95 and Windows NT 3.51 operating

           The good news is that the Shell_NotifyIcon API will place an icon in
the notification area, assign tool tip text,
           and manage mouse events. This API accepts two parameters. The first
parameter is the notification message,
           which tells Shell_NotifyIcon what function to perform. There are
three valid messages:

                NIM_ADD (&H0) - registers an icon with the system and places it
in the system tray for the first time.
                You should call it only once for this purpose.
                NIM_MODIFY (&H1) - makes changes after the icon is registered.
                NIM_DELETE (&H2) - removes the icon from the system tray. This
message is important because icons
                aren't automatically removed when applications terminate.

           Shell_NotifyIcon 's second parameter is a structure containing the
information that the API needs in order to
           process your request. Table A lists these elements and their

           Table A: NOTIFYICONDATA structure
                             Handle of the window that receives notification
messages associated with an icon in
                             the taskbar notification area.
                             Application-defined identifier of the taskbar
                             Array of flags indicating which other structure
members contain valid data. This
                             member can be a combination of the following
values: NIF_ICON (meaning the hIcon
                             member is valid); NIF_MESSAGE (meaning the
uCallbackMessage is valid); and
                             NIF_TIP (meaning the szTip member is valid).
                             Application-defined message identifier. The system
uses this identifier for notification
                             messages it sends to the window (identified by
hWnd) whenever a mouse event occurs
                             in the bounding rectangle of the icon.
                             Handle of the taskbar icon to add, modify, or
                             Tool tip text to display for the taskbar icon.

           The project

           Our sample project consists of one form and one module. The form
contains two picture boxes and a menu.
           The picture boxes' picture properties contain the filenames
identifying the icon images for the notification area.
           One of the picture boxes will receive messages when the cursor moves
across the icon in the notification area. In
           this example, we'll display a pop-up menu when the user right-clicks
on the icon. Let's get started with our

           Creating the menu

           Begin by opening a new VB project. Set the form's visible property
to False, then choose Menu Editor from the
           Tools menu. In the resulting dialog box, create a Shell_Menu menu by
typing Shell_Menu in the Caption box
           and mnuShell in the Name box. Click Next, then type On in the
Caption box and mnuOn in the Name box.
           Click the ... button to make On a submenu item, then click Next.

           In the same way, create the submenu items Off, -, and Close, with
the names mnuOff, mnuSep1, and mnuClose,
           respectively. When you finish, the Menu Editor should look like
Figure A. Click OK to return to your form.

           Adding the picture boxes

           Next, place two picture boxes on the form. Assign a different icon
to the picture property of each picture box -
           we used the TRFFC09 and TRFF14 icon files from Visual Basic's
\ICONS\TRAFFIC directory. Note that the
           images must be icons - if they aren't, the call to Shell_NotifyIcon
will fail. Figure B shows how our form looks at
           this point.

           Declaring the function

           Now, open a new module. In the General Declarations window, declare
the Shell_NotifyIcon API,
           NOTIFYICONDATA structure, and the necessary constants, as shown in
Listing A. Next, you'll place code
           in Form1 at the following locations: Form_Load, Picture1_MouseMove,
mnuClose_Click, mnuOn_Click, and

           Listing A: Module1 declarations

           Public Declare Function Shell_NotifyIcon _
                      Lib "shell32.dll" _
                      Alias "Shell_NotifyIconA" _
                      (ByVal dwMessage As Long, _
                      lpData As NOTIFYICONDATA) As Long

              Public Type NOTIFYICONDATA
                   cbSize As Long
                   hWnd As Long
                   uID As Long
                   uFlags As Long
                   uCallbackMessage As Long
                   hIcon As Long
                   szTip As String * 64
              End Type

              Global t As NOTIFYICONDATA

              Global Const NIM_ADD = &H0
              Global Const NIM_MODIFY = &H1
              Global Const NIM_DELETE = &H2
              Global Const NIF_MESSAGE = &H1
              Global Const NIF_ICON = &H2
              Global Const NIF_TIP = &H4
              Global Const WM_MOUSEMOVE = &H200


           The Form_Load event initializes the variables in the NOTIFYICONDATA
structure and adds the icon to the
           notification area. Listing B contains the code that passes
Picture1's handle to the t.hWnd parameter and makes
           Picture1 the recipient of notification messages from
Shell_NotifyIcon. You next pass Picture.Picture to the
           t.hIcon parameter, thereby telling Shell_NotifyIcon to display
Picture1's picture property. You pass the literal
           "Shell_NotifyIcon Test" to t.szTip as the tool tip text.

           Listing B: The Form_Load event

           Private Sub Form_Load()

               t.cbSize = Len(t)
               t.hWnd = Picture1.hWnd
               t.uID = 1&
               t.uFlags = NIF_MESSAGE Or _
                                NIF_ICON Or _

               t.uCallbackMessage = WM_MOUSEMOVE

               t.hIcon = Picture1.Picture
               t.szTip = "Shell_NotifyIcon Test"  & Chr$(0)
               Shell_NotifyIcon NIM_ADD, t

           End Sub

           The Picture1_Mouse_Move event receives notifications when the mouse
pointer passes over the icon in the
           notification area. (We describe this event in the next section.) The
MouseMove event fires because you pass
           WM_MOUSEMOVE to the uCallbackMessage parameter.
            Table B: Shell_NotifyIcon
            notification messages
                      Mouse is moving
                      Left button down
                      Left button up
                      Right button down
                      Right button up
                      Left button
                      Right button


                                        The following code displays Form1's
menu when you right-click on the

                                        Private Sub Picture1_MouseMove _
                                                    (Button As Integer, _
                                                     Shift As Integer,  _
                                                     X As Single, Y As Single)

                                            If Hex(X) = "1E3C" Then
                                                Form1.PopupMenu Form1.mnuShell
                                            End If

                                        End Sub

                                        The X parameter of the
Picture1_MouseMove event contains the
                                        notification message. Table B lists the
valid hex values for the

read more »

Sat, 25 Aug 2001 03:00:00 GMT  
 Q: Minimizing to system tray??
VB does not handle this inherently.  There should be a sample project on
your VB CD that tells you how to do this.  Look in the
Tools\Unsupprt\Systray directory.  Also, check out Karl Peterson's web site:

John Tabor



>   I would like to be able to minimize the program i am working on,
>but only have it sit in the tray, not the task bar, you know, by the
>clock, and have it open on right click or double left click, like most
>tray items, is this controlled by VB or something else? If its VB and
>you know how, please fill me in

Sat, 25 Aug 2001 03:00:00 GMT  
 [ 5 post ] 

 Relevant Pages 

1. CoolHide - Help you hide/minimize window to Tray and hide icons from the system tray

2. CoolHide - Help you hide/minimize window to Tray and hide icons from the system tray

3. Minimize AC00 to system tray

4. minimized in system tray

5. Minimize to system tray [VB6]

6. VB3: Minimize to Win 95 System Tray?

7. Starting app minimized in system tray

8. Minimize into System Tray

9. Minimize to system tray [VB6]

10. Minimizing an Application to the System Tray...

11. Minimizing a form to the system tray instead of the taskbar

12. ***** Minimize VB5 app to system tray


Powered by phpBB® Forum Software