Option ExplicitPublic Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Public OldProc As Long Public NewForm As Form Public NewMenu As Menu Public Const WM_LBUTTONUP = &H202 Public Const WM_RBUTTONUP = &H205 Public Const GWL_WNDPROC = (-4) Public Const GWL_USERDATA = (-21)Public Const NIM_ADD = &H0 Public Const NIM_DELETE = &H2 Public Const NIM_MODIFY = &H1 Public Const NIF_MESSAGE = &H1 Public Const NIF_TIP = &H4Public Const NIF_ICON = &H2 Public Const WM_USER = &H400 Public Const TRAY_CALLBACK = (WM_USER + 1001&) 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 NewD As NOTIFYICONDATAPublic Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = TRAY_CALLBACK Then If lParam = WM_LBUTTONUP Then
End If If lParam = WM_RBUTTONUP Then
End If End If WndProc = CallWindowProc(OldProc, hWnd, Msg, wParam, lParam) End FunctionPublic Sub AddTray(Frm As Form, Mnu As Menu) Set NewForm = Frm Set NewMenu = Mnu OldProc = SetWindowLong(Frm.hWnd, GWL_WNDPROC, AddressOf WndProc) With NewD .uID = 0 .hWnd = Frm.hWnd .cbSize = Len(NewD) .hIcon = Frm.Icon.Handle .uFlags = .uFlags Or NIF_MESSAGE .cbSize = Len(NewD) End With Shell_NotifyIcon NIM_ADD, NewD End SubPublic Sub RemoveTray() With NewD .uFlags = 0 End With Shell_NotifyIcon NIM_DELETE, NewD End SubPublic Sub AddPic(pic As Picture) With NewD .hIcon = pic.Handle .uFlags = NIF_ICON End With Shell_NotifyIcon NIM_MODIFY, NewD End SubPublic Sub AddTip(ByVal Tip As String) With NewD .szTip = Tip & vbNullChar .uFlags = NIF_TIP End With Shell_NotifyIcon NIM_MODIFY, NewD End Sub
VB托盘程序详解 http://www.sijiqing.com/vbgood/experience/index.asp?action=read&id=3807VB6.0实现系统托盘 http://www.sijiqing.com/vbgood/experience/index.asp?action=read&id=3606 例子: 利用API函数Shell_NotifyIcon在任务栏上放置图标。并且可以相应任务栏图标消息。 http://www.applevb.com/sourcecode/baricon.zip简单的添加图标到托盘. http://down.dapha.net/source/api/Easy to use Systray Class.zip在托盘上添加图标,删除图标. http://down.dapha.net/source/api/CTray.zip另类.托盘中的进度条. http://down.dapha.net/source/api/ProgressBar in System Tray.zip
http://www.sijiqing.com/vbgood/experience/index.asp?action=read&id=3606
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public OldProc As Long
Public NewForm As Form
Public NewMenu As Menu
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONUP = &H205
Public Const GWL_WNDPROC = (-4)
Public Const GWL_USERDATA = (-21)Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIM_MODIFY = &H1
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4Public Const NIF_ICON = &H2
Public Const WM_USER = &H400
Public Const TRAY_CALLBACK = (WM_USER + 1001&)
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 NewD As NOTIFYICONDATAPublic Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = TRAY_CALLBACK Then
If lParam = WM_LBUTTONUP Then
End If
If lParam = WM_RBUTTONUP Then
End If
End If
WndProc = CallWindowProc(OldProc, hWnd, Msg, wParam, lParam)
End FunctionPublic Sub AddTray(Frm As Form, Mnu As Menu)
Set NewForm = Frm
Set NewMenu = Mnu
OldProc = SetWindowLong(Frm.hWnd, GWL_WNDPROC, AddressOf WndProc)
With NewD
.uID = 0
.hWnd = Frm.hWnd
.cbSize = Len(NewD)
.hIcon = Frm.Icon.Handle
.uFlags = .uFlags Or NIF_MESSAGE
.cbSize = Len(NewD)
End With
Shell_NotifyIcon NIM_ADD, NewD
End SubPublic Sub RemoveTray()
With NewD
.uFlags = 0
End With
Shell_NotifyIcon NIM_DELETE, NewD
End SubPublic Sub AddPic(pic As Picture)
With NewD
.hIcon = pic.Handle
.uFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, NewD
End SubPublic Sub AddTip(ByVal Tip As String)
With NewD
.szTip = Tip & vbNullChar
.uFlags = NIF_TIP
End With
Shell_NotifyIcon NIM_MODIFY, NewD
End Sub
http://www.sijiqing.com/vbgood/experience/index.asp?action=read&id=3807VB6.0实现系统托盘
http://www.sijiqing.com/vbgood/experience/index.asp?action=read&id=3606
例子:
利用API函数Shell_NotifyIcon在任务栏上放置图标。并且可以相应任务栏图标消息。
http://www.applevb.com/sourcecode/baricon.zip简单的添加图标到托盘.
http://down.dapha.net/source/api/Easy to use Systray Class.zip在托盘上添加图标,删除图标.
http://down.dapha.net/source/api/CTray.zip另类.托盘中的进度条.
http://down.dapha.net/source/api/ProgressBar in System Tray.zip