Solved

Show VB Aplication Icon in TaskBar next to Clock?

Posted on 1999-01-15
1
385 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now