'Download the full source+pictures+... At http://www.geocities.com/SiliconValley/Campus/3636/trayicon.zip
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 TypePrivate 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 = &H4Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayI As NOTIFYICONDATA
Private Sub Form_Load()
TrayI.cbSize = Len(TrayI)
'Set the window's handle (this will be used to hook the specified window)
TrayI.hWnd = pichook.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 = imgIcon(2).Picture
'Set the tooltiptext
TrayI.szTip = "Recent" & Chr$(0)
'Create the icon
Shell_NotifyIcon NIM_ADD, TrayI Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the icon
TrayI.cbSize = Len(TrayI)
TrayI.hWnd = pichook.hWnd
TrayI.uId = 1&
Shell_NotifyIcon NIM_DELETE, TrayI
End
End Sub
Private Sub mnuPop_Click(Index As Integer)
Select Case Index
Case 0
MsgBox "KPD-Team 1998" + Chr$(13) + "URL: http://www.allapi.net/" + Chr$(13) + "E-Mail: [email protected]", vbInformation + vbOKOnly
Case 2
Unload Me
End Select
End Sub
Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Msg = X / Screen.TwipsPerPixelX
If Msg = WM_LBUTTONDBLCLK Then
'Left button double click
mnuPop_Click 0
ElseIf Msg = WM_RBUTTONUP Then
'Right button click
Me.PopupMenu mnuPopUp
End If
End Sub
Private Sub Timer1_Timer()
Static Tek As Integer
'Animate the icon
Me.Icon = imgIcon(Tek).Picture
TrayI.hIcon = imgIcon(Tek).Picture
Tek = Tek + 1
If Tek = 3 Then Tek = 0
Shell_NotifyIcon NIM_MODIFY, TrayI
End Sub
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 TypePrivate 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 = &H4Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayI As NOTIFYICONDATA
Private Sub Form_Load()
TrayI.cbSize = Len(TrayI)
'Set the window's handle (this will be used to hook the specified window)
TrayI.hWnd = pichook.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 = imgIcon(2).Picture
'Set the tooltiptext
TrayI.szTip = "Recent" & Chr$(0)
'Create the icon
Shell_NotifyIcon NIM_ADD, TrayI Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the icon
TrayI.cbSize = Len(TrayI)
TrayI.hWnd = pichook.hWnd
TrayI.uId = 1&
Shell_NotifyIcon NIM_DELETE, TrayI
End
End Sub
Private Sub mnuPop_Click(Index As Integer)
Select Case Index
Case 0
MsgBox "KPD-Team 1998" + Chr$(13) + "URL: http://www.allapi.net/" + Chr$(13) + "E-Mail: [email protected]", vbInformation + vbOKOnly
Case 2
Unload Me
End Select
End Sub
Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Msg = X / Screen.TwipsPerPixelX
If Msg = WM_LBUTTONDBLCLK Then
'Left button double click
mnuPop_Click 0
ElseIf Msg = WM_RBUTTONUP Then
'Right button click
Me.PopupMenu mnuPopUp
End If
End Sub
Private Sub Timer1_Timer()
Static Tek As Integer
'Animate the icon
Me.Icon = imgIcon(Tek).Picture
TrayI.hIcon = imgIcon(Tek).Picture
Tek = Tek + 1
If Tek = 3 Then Tek = 0
Shell_NotifyIcon NIM_MODIFY, TrayI
End Sub
Option Explicit
Private Declare Function Shell_NotifyIconA Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
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_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_MOUSEMOVE = &H200
Dim nidm As NOTIFYICONDATA
Private Sub Form_Load() '初始化
nidm.cbSize = Len(cbSize)
nidm.hIcon = Form1.Icon
nidm.hwnd = Form1.hwnd
nidm.uID = vbNull
nidm.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
nidm.szTip = "show test" & Chr&(0)
nidm.uCallbackMessage = WM_MOUSEMOVE
Call Shell_NotifyIconA(NIM_ADD, nidm)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在图片区时,判断鼠标所激发的事件
Dim msg As Long
msg = X \ Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDBLCLK
Me.Show
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer) '结束程序
Call Shell_NotifyIconA(NIM_DELETE, nidm)
End Sub
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_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONUP = &H205
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_MOUSEMOVE = &H200
Dim nidm As NOTIFYICONDATA
Private Sub Command2_Click()
nidm.cbSize = Len(nidm)
nidm.hIcon = Form1.Icon
nidm.hwnd = Form1.hwnd
nidm.uID = vbNull
nidm.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
nidm.szTip = "show time" & Chr$(0)
nidm.uCallbackMessage = WM_MOUSEMOVE
Call Shell_NotifyIconA(NIM_ADD, nidm)
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在图片区时,判断鼠标所激发的事件
Dim msg As Long
msg = X \ Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDBLCLK
Me.Show
Case WM_RBUTTONUP
Me.PopupMenu wenjian
End Select
End Sub
我有两个源代码,你要的话,给地址。
或者联系我吧。