Solved

Show VB Aplication Icon in TaskBar next to Clock?

Posted on 1999-01-15
1
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

726 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