Task Tray
Learn how to put an application in the Task Tray using Visual Basic 6 with this Tutorial that Celebrates the CESPage 25th Anniversary
This will show you how to put an Icon in the Task Tray and make a Popup Menu appear when you Right Click on the Icon within the Task Tray, this Tutorial is presenting using the original Images and Code.
Step 1
Step 2
Step 3
Step 4
Step 5
Name
property to picHook
Step 6
Form1
then got the Properties Box and change the Visible
property to False
and the ShowInTaskBar
property to False
Step 7
Popup
in the Caption
box and mnuPopup
in the Name
box,
Click on Next then Click on the Arrow pointing Right and type in the Caption
box
Exit
then in the Name
box mnuPopupExit
Step 8
Once the Menu is complete you must now do the coding. Double Click on Form1
then select the
General Declarations from the Left Combo Box then type in the following:
Option Explicit
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 WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
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 t As NOTIFYICONDATA
Step 9
Double Click on the Form of Form1
and type in the Form_Load()
Sub:
t.cbSize = Len(t)
t.hWnd = Me.picHook.hWnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_MOUSEMOVE
t.hIcon = Me.Icon
t.szTip = "TaskTray" & Chr$(0)
Shell_NotifyIcon NIM_ADD, t
Me.Hide
App.TaskVisible = False
Step 10
Double Click on the Picture Box of picHook
and type in the picHook_MouseMove()
Sub:
Static rec As Boolean, msg As Long
msg = X / Screen.TwipsPerPixelX
If rec = False Then
rec = True
Select Case msg
Case WM_LBUTTONDBLCLK:
Case WM_LBUTTONDOWN:
Case WM_LBUTTONUP:
Case WM_RBUTTONDBLCLK:
Case WM_RBUTTONDOWN:
Case WM_RBUTTONUP:
Me.PopupMenu mnuPopup
End Select
rec = False
End If
Step 11
Select Popup from the Form of Form1
and select Exit from the
Menu, and type in the mnuPopupExit_Click()
Sub:
t.cbSize = Len(t)
t.hWnd = picHook.hWnd
t.uId = 1&
Shell_NotifyIcon NIM_DELETE, t
End
Step 12
Step 13
Now Right Click with the Mouse on the Icon nearest the Clock (the Icon will be the same Icon that was the Top Left Corner of the Form) and this will appear:
Step 14
Click on Exit to End
the Program. Try Changing the
Icon or add other Sub Menus and Menus
to the Popup Menu and see what happens!