Try this. First you new to make a 2 Forms and a Module. The first Form is called frmTray. The 2nd Form is called Form1.
On frmTray, make a PictureBox or an ImageBox with an Icon in it and set the Index property to 0. Set the ShowInTaskBar property for Form1 to False.
Add thid code to the Module. Make sure the Startup Form is Sub Main.
Now add this code to frmTray.Code:Option Explicit Sub Main() Load frmTray Form1.Show End Sub
Code:Option Explicit 'Messages Private Const NIM_ADD = &H0 'Adds an icon to the taskbar notification area Private Const NIM_MODIFY = &H1 'Changes the icon, tooltip text or notification message for an icon in the notification area Private Const NIM_DELETE = &H2 'Deletes an icon from the taskbar notification area 'Flags Private Const NIF_MESSAGE = &H1 'hIcon is valid Private Const NIF_ICON = &H2 'uCallbackMessage is valid Private Const NIF_TIP = &H4 'szTip is valid Private Const WM_MOUSEMOVE = &H200 'MouseMove message identifier 'Messages sent to the form's MouseMove event 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 Type NOTIFYICONDATA cbSize As Long hWnd As Long 'Handle of window that receives notification messages uID As Long 'Application-defined identifier of the taskbar icon uFlags As Long 'Flags indicating which structure members contain valid data uCallbackMessage As Long 'Application defined callback message hIcon As Long 'Handle of taskbar icon szTip As String * 64 'Tooltip text to display for icon End Type Dim mtIconData As NOTIFYICONDATA Dim mnLight As Integer Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Sub Form_Load() AddIconToTray End Sub Private Sub Form_Unload(Cancel As Integer) DeleteIconFromTray 'Put cleanup code here so that it always gets executed Set frmTray = Nothing End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Static bBusy As Boolean If bBusy = False Then bBusy = True Select Case CLng(X) Case WM_LBUTTONDBLCLK ' Left button Double Clicked Form1.Show ' Show our Form Case WM_LBUTTONDOWN ' Left button Down If Shell_NotifyIcon(NIM_MODIFY, mtIconData) = 0 Then MsgBox "Unable to change icon in system tray!" End If Case WM_LBUTTONUP 'Left mouse button released Case WM_RBUTTONDBLCLK 'Double-click right mouse button Case WM_RBUTTONDOWN 'Right mouse button pressed End Select bBusy = False End If End Sub Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area With mtIconData .cbSize = Len(mtIconData) .hWnd = Me.hWnd 'Use the form to receive callback messages. .uCallbackMessage = WM_MOUSEMOVE 'Tell icon to send MouseMove messages. .uID = 1& 'Application defined identifier .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE .hIcon = imgTrayIcon(0).Picture 'Initial icon .szTip = "ToolTipText" & Chr$(0) 'Initial tooltip for icon If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then 'Create icon in tray MsgBox "Unable to add icon to system tray!" End If End With End Sub Private Sub DeleteIconFromTray() If Shell_NotifyIcon(NIM_DELETE, mtIconData) = 0 Then MsgBox "Unable to delete icon from system tray!" End If End Sub




Reply With Quote