📄 tray.bas
字号:
Attribute VB_Name = "Tray"
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIM_MODIFY = &H1
Public Const WM_MOUSEMOVE = &H200
Public Const trayLBUTTONDOWN = 7695
Public Const trayLBUTTONUP = 7710
Public Const trayLBUTTONDBLCLK = 7725
Public Const trayRBUTTONDOWN = 7740
Public Const trayRBUTTONUP = 7755
Public Const trayRBUTTONDBLCLK = 7770
Public Const trayMOUSEMOVE = 7680
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
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Dim trayStructure As NOTIFYICONDATA
Dim MinFlag As Boolean
Public Function AddIcon(pic As Control, tip$, f As Form)
trayStructure.szTip = tip$ & Chr$(0)
trayStructure.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP
trayStructure.uID = 100
trayStructure.cbSize = Len(trayStructure)
trayStructure.hwnd = pic.hwnd
' The message CBWnd will receive when there's an icon event
trayStructure.uCallbackMessage = WM_MOUSEMOVE
trayStructure.hIcon = f.Icon
' Add the icon to the taskbar tray
rc = Shell_NotifyIcon(NIM_ADD, trayStructure)
End Function
Public Function DeleteIcon(pic As Control)
' On remove, we only have to give enough information for Windows
' to locate the icon, then tell the system to delete it.
trayStructure.uID = 100
trayStructure.cbSize = Len(trayStructure)
trayStructure.hwnd = pic.hwnd
trayStructure.uCallbackMessage = WM_MOUSEMOVE
rc = Shell_NotifyIcon(NIM_DELETE, trayStructure)
End Function
Public Sub NewTip(pic As Control, tip$)
' You can change the tip whenever you want during the program
trayStructure.uFlags = NIF_TIP
trayStructure.uID = 100
trayStructure.cbSize = Len(trayStructure)
trayStructure.hwnd = pic.hwnd
trayStructure.uCallbackMessage = WM_MOUSEMOVE
' New Tip
trayStructure.szTip = tip$ & Chr$(0)
rc = Shell_NotifyIcon(NIM_MODIFY, trayStructure)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -