Solved

Show VB Aplication Icon in TaskBar next to Clock?

Posted on 1999-01-15
1
396 Views
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?
0
Comment
Question by:carlosvs
1 Comment
 
LVL 2

Accepted Solution

by:
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
Private 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
Private t As NOTIFYICONDATA
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.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    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

0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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