Private Sub Command1_Click()
'Lägg till en ikon i systrayen.
nid.cbSize = Len(nid)
nid.hWnd = Form1.hWnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Form1.Icon
nid.szTip = "Systray Status Area Program" & vbNullChar
Shell_NotifyIcon NIM_ADD, nid
End Sub
Private Sub Command2_Click()
'Radera ikonen från systrayen
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_Load()
Command1.Caption = "Add an Icon"
Command2.Caption = "Delete Icon"
End Sub
Private Sub Form_Terminate()
'Radera ikonen från systrayen när programmet avslutas.
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_MouseMove _
(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
'Händelse utlöses när muspekaren är över ikonen 'i systrayen..
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
CommonDialog1.DialogTitle = "Välj en ikon"
sFilter = "Icon Files (*.ico)|*.ico"
sFilter = sFilter & "|All Files (*.*)|*.*"
CommonDialog1.Filter = sFilter
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Form1.Icon = LoadPicture(CommonDialog1.FileName)
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONDOWN
Dim ToolTipString As String
ToolTipString = InputBox("Skriv in ett ToolTip:", "Ändra ToolTip")
If ToolTipString <> "" Then
nid.szTip = ToolTipString & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End Sub