Link to home
Start Free TrialLog in
Avatar of Amita
Amita

asked on

Icon in Taskbar ?

At the time of installment of our software , how can we make our icon appear in the right hand side of the taskbar(not sure what it is called as )....where curent time appears...?
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Chong
It's called System Tray.

Here is an example:

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 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_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayI As NOTIFYICONDATA

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    'Divide by Screen.TwipsPerPixelX if ScaleMode = vbTwips
    If Me.ScaleMode = vbTwips Then
        msg = x / Screen.TwipsPerPixelX
    Else
        msg = x
    End If
    If msg = WM_LBUTTONDBLCLK Then
        'Left button double click
        LeftButtonDlbClick
    ElseIf msg = WM_LBUTTONUP Or msg = WM_RBUTTONUP Then
        'Left/ Right button click
        Me.PopupMenu mnuPop
    End If
End Sub

Private Sub LeftButtonDlbClick()
    tmp = Me.WindowState
    i = ShowWindow(Me.hwnd, SW_SHOW)
    If isDownloading = False Then Me.Show
    Me.WindowState = vbNormal
    DoEvents
    If isDownloading = False Then Me.SetFocus
    If Val(tmp) <> vbNormal Then
        Call ReleaseCapture
        lngReturnValue = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    End If
    End Sub

Private Sub CreateTray()
    TrayI.cbSize = Len(TrayI)
    'Set the window's handle (this will be used to hook the specified window)
    TrayI.hwnd = Me.hwnd
    'Application-defined identifier of the taskbar icon
    TrayI.uid = 1&
    'Set the flags
    TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    'Set the callback message
    TrayI.ucallbackMessage = WM_LBUTTONDOWN
    'Set the picture (must be an icon!)
    TrayI.hIcon = Me.Icon
    'Set the tooltiptext
    TrayI.szTip = "HPB Gaming Console" & Chr$(0)
    'Create the icon
    Shell_NotifyIcon NIM_ADD, TrayI
   
    isTray = True
    Me.Hide
End Sub

Private Sub ModifyTray(ic As Long)
    'Set the picture (must be an icon!)
    TrayI.hIcon = ic
    'Modify the icon
    Shell_NotifyIcon NIM_MODIFY, TrayI
End Sub

Private Sub removeTray()
    'remove the icon
    TrayI.cbSize = Len(TrayI)
    TrayI.hwnd = Me.hwnd
    TrayI.uid = 1&
    Shell_NotifyIcon NIM_DELETE, TrayI
    isTray = False
End Sub
ops.. :)