Show VB Aplication Icon in TaskBar next to Clock?

Posted on 1999-01-15
Last Modified: 2012-06-27
How can I make my TSR Visual Basic Aplication to be show in
the taskbar next to the clock like the diplay icon or then
volume control? some examples?
Question by:carlosvs
1 Comment

Accepted Solution

trillo earned 50 total points
ID: 1456733
I've put two pictureboxes and a menu with some itmes (mnuOn, mnuOff, mnuClose), and the the following code (with full comments)

'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 on page 3
'lists these elements and their purposes.

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    cbSize As Long
    hWnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 64
End Type
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200

'Table A: NOTIFYICONDATA structure
'Element    Purpose
' hWnd      Handle of the window that receives notification messages associated with
'           an icon in the taskbar notification area.
' uID       Application-defined identifier of the taskbar icon.
' uFlags    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).
' uCallbackMessage
'           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.
' hIcon     Handle of the taskbar icon to add, modify, or delete.
' szTip     Tool tip text to display for the taskbar icon.

'IMPORTANT: Note that the images must be icons--if they aren't, the call to
'   Shell_NotifyIcon will fail.

Private Sub Form_Load()
    Me.Visible = False
    t.cbSize = Len(t)
    t.hWnd = Picture1.hWnd
    t.uID = 1&
    t.uCallbackMessage = WM_MOUSEMOVE
    t.hIcon = Picture1.Picture
    t.szTip = "Shell_NotifyIcon Test" & Chr$(0)
    Shell_NotifyIcon NIM_ADD, t
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'The X parameter of the Picture1_MouseMove event contains the notification message.
'Table B: Shell_NotifyIcon notification messages
'Hex Value Meaning
' '1E00'   Mouse is moving
' '1E0F'   Left button down
' '1E1E'   Left button up
' '1E3C'   Right button down
' '1E4B'   Right button up
' '1E2D'   Left button double-click
' '1E5A'   Right button double-click
    If Hex(X) = "1E3C" Then
        Me.PopupMenu Me.mnuShell
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
'The NIM_DELETE message removes the icon from the notification area. This is important: Without this message, entries in the notification area will
'remain when an application terminates.
    Shell_NotifyIcon NIM_DELETE, t
End Sub

Private Sub mnuClose_Click()
    Unload Me
End Sub

'The Click event for the Off/On menu items toggles the checked values of mnuOff and
'mnuOn and uses the NIM_MODIFY message to change the icon and tool tip text.
'The t.hIcon parameter receives the icon image stored in Pictures' picture value,
'and the event passes a new text string to t.szTip.
Private Sub mnuOff_Click()
    mnuOff.Checked = True
    mnuOn.Checked = False
    t.hIcon = Picture2.Picture
    t.szTip = "Shell_NotifyIcon is Off" & Chr$(0)
    Shell_NotifyIcon NIM_MODIFY, t
End Sub

Private Sub mnuOn_Click()
    mnuOn.Checked = True
    mnuOff.Checked = False
    t.hIcon = Picture1.Picture
    t.szTip = " Shell_NotifyIcon is On " & Chr$(0)
    Shell_NotifyIcon NIM_MODIFY, t
End Sub


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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