palapatine
asked on
adding icons to the taskbar
how do you add programs to the taskbar (where the clock is) in VB 6 ?
code would be nice.
code would be nice.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Could you give some better instructions on using this...
I'm baffled byall the error messages I got when I tried to use this?????
I'm baffled byall the error messages I got when I tried to use this?????
ben_1, What kind of error did you find ?
I got errors reguarding public and private class etc...
If you said more specificly where to paste each block of code this might help...
Did you make this in VB6????
If you said more specificly where to paste each block of code this might help...
Did you make this in VB6????
ben_1, here it is :
Note : If you got error with public or private
Add Private/Public before API declared
'put it in your general declaration
Public Const MAX_TOOLTIP As Integer = 64
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Type NOTIFYICONDATA
cbSize As Long 'Size of the NOTIFYICONDATA structure.
hwnd As Long 'Handle of window receiving notification messages.
uID As Long 'Application-defined identifier of the taskbar icon.
uFlags As Long 'One of the below flags
uCallbackMessage As Long 'Message sent to the window whenever a mouse event occurs..
hIcon As Long 'Handle of the icon to add, modify, or delete.
szTip As String * MAX_TOOLTIP 'Tooltip text to display for the icon.
End Type
'FLAG DESCRIPTION
'NIF_ICON The hIcon member is valid.
'NIF_MESSAGE The uCallbackMessage member is valid.
'NIF_TIP The szTip member is valid.
Public nfIconData As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'Form Code
' You have to add 2 command button on your form
' named it cmdAdd and the other cmdRemove
'Add this code to the cmdAdd_Click event:
Private Sub cmdAdd_Click()
'
' Add this application's icon to the system tray.
'
' Parm 1 = Handle of the window to receive notification messages
' associated with an icon in the taskbar status area.
' Parm 2 = Icon to display.
' Parm 3 = Handle of icon to display.
' Parm 4 = Tooltip displayed when cursor moves over system tray icon.
'
With nfIconData
.hwnd = Me.hwnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = "System Tray Example" & vbNullChar
.cbSize = Len(nfIconData)
End With
Shell_NotifyIcon NIM_ADD, nfIconData
End Sub
Add this code to the cmdRemove_Click event:
Private Sub cmdRemove_Click()
'
' Remove this application from the System Tray.
'
Shell_NotifyIcon NIM_DELETE, nfIconData
End Sub
Note : If you got error with public or private
Add Private/Public before API declared
'put it in your general declaration
Public Const MAX_TOOLTIP As Integer = 64
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Type NOTIFYICONDATA
cbSize As Long 'Size of the NOTIFYICONDATA structure.
hwnd As Long 'Handle of window receiving notification messages.
uID As Long 'Application-defined identifier of the taskbar icon.
uFlags As Long 'One of the below flags
uCallbackMessage As Long 'Message sent to the window whenever a mouse event occurs..
hIcon As Long 'Handle of the icon to add, modify, or delete.
szTip As String * MAX_TOOLTIP 'Tooltip text to display for the icon.
End Type
'FLAG DESCRIPTION
'NIF_ICON The hIcon member is valid.
'NIF_MESSAGE The uCallbackMessage member is valid.
'NIF_TIP The szTip member is valid.
Public nfIconData As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'Form Code
' You have to add 2 command button on your form
' named it cmdAdd and the other cmdRemove
'Add this code to the cmdAdd_Click event:
Private Sub cmdAdd_Click()
'
' Add this application's icon to the system tray.
'
' Parm 1 = Handle of the window to receive notification messages
' associated with an icon in the taskbar status area.
' Parm 2 = Icon to display.
' Parm 3 = Handle of icon to display.
' Parm 4 = Tooltip displayed when cursor moves over system tray icon.
'
With nfIconData
.hwnd = Me.hwnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = "System Tray Example" & vbNullChar
.cbSize = Len(nfIconData)
End With
Shell_NotifyIcon NIM_ADD, nfIconData
End Sub
Add this code to the cmdRemove_Click event:
Private Sub cmdRemove_Click()
'
' Remove this application from the System Tray.
'
Shell_NotifyIcon NIM_DELETE, nfIconData
End Sub
ASKER
i need to try that as well , please hold on a little longer
Here is setiwan's code modified to working status on my machine...
'put it in your general declaration
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Private Type NOTIFYICONDATA
cbSize As Long 'Size of the NOTIFYICONDATA structure.
hwnd As Long 'Handle of window receiving notification messages.
uID As Long 'Application-defined identifier of the taskbar icon.
uFlags As Long 'One of the below flags
uCallbackMessage As Long 'Message sent to the window whenever a mouse event occurs..
hIcon As Long 'Handle of the icon to add, modify, or delete.
szTip As String * MAX_TOOLTIP 'Tooltip text to display for the icon.
End Type
'FLAG DESCRIPTION
'NIF_ICON The hIcon member is valid.
'NIF_MESSAGE The uCallbackMessage member is valid.
'NIF_TIP The szTip member is valid.
Private nfIconData As NOTIFYICONDATA
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Sub cmdAdd_Click()
'
' Add this application's icon to the system tray.
'
' Parm 1 = Handle of the window to receive notification messages
' associated with an icon in the taskbar status area.
' Parm 2 = Icon to display.
' Parm 3 = Handle of icon to display.
' Parm 4 = Tooltip displayed when cursor moves over system tray icon.
'
With nfIconData
.hwnd = Me.hwnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = "System Tray Example" & vbNullChar
.cbSize = Len(nfIconData)
End With
Shell_NotifyIcon NIM_ADD, nfIconData
End Sub
Private Sub cmdRemove_Click()
'
' Remove this application from the System Tray.
'
Shell_NotifyIcon NIM_DELETE, nfIconData
End Sub
'put it in your general declaration
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_RBUTTONDBLCLK = &H206
Private Type NOTIFYICONDATA
cbSize As Long 'Size of the NOTIFYICONDATA structure.
hwnd As Long 'Handle of window receiving notification messages.
uID As Long 'Application-defined identifier of the taskbar icon.
uFlags As Long 'One of the below flags
uCallbackMessage As Long 'Message sent to the window whenever a mouse event occurs..
hIcon As Long 'Handle of the icon to add, modify, or delete.
szTip As String * MAX_TOOLTIP 'Tooltip text to display for the icon.
End Type
'FLAG DESCRIPTION
'NIF_ICON The hIcon member is valid.
'NIF_MESSAGE The uCallbackMessage member is valid.
'NIF_TIP The szTip member is valid.
Private nfIconData As NOTIFYICONDATA
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Sub cmdAdd_Click()
'
' Add this application's icon to the system tray.
'
' Parm 1 = Handle of the window to receive notification messages
' associated with an icon in the taskbar status area.
' Parm 2 = Icon to display.
' Parm 3 = Handle of icon to display.
' Parm 4 = Tooltip displayed when cursor moves over system tray icon.
'
With nfIconData
.hwnd = Me.hwnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = "System Tray Example" & vbNullChar
.cbSize = Len(nfIconData)
End With
Shell_NotifyIcon NIM_ADD, nfIconData
End Sub
Private Sub cmdRemove_Click()
'
' Remove this application from the System Tray.
'
Shell_NotifyIcon NIM_DELETE, nfIconData
End Sub
Now that we have that, How would I give a form focus based on a click on that icon????
Or create a menu?????
Thanx so far
Or create a menu?????
Thanx so far
ASKER
that was what i was originaly geting at, but since it was no in my original question i will tack on 20 more for a good answer on how to get a menu to popup from the icon.
ASKER