vb将程序最小化到托盘
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hicon 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 GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public 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
Public Const NIM_ADD = 0 '添加图标
Public Const NIM_MODIFY = 1 '修改图标
Public Const NIM_DELETE = 2 '删除图标
Public Const NIF_MESSAGE = 1 '当有鼠标事件发生时产生消息
Public Const NIF_ICON = 2 '
Public Const NIF_TIP = 4 '图标有提示字符串
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_USER = &H400
Public Const WM_NOTIFYICON = WM_USER + &H100 Public Const WM_COMMAND = &H111
Public Const WM_DESTROY = &H2
Public Const WM_DRA WITEM = &H2B
Public Const WM_INITDIALOG = &H110
Public Const WM_PAINT = &HF
Public Const WM_MENUSELECT = &H11F
Public Const GWL_WNDPROC = (-4) '替换窗口处理函数
Dim pmenu As Long
Dim submenu As Long
Global lproc As Long
Function CMenu() As Boolean
'这个函数获得Form1的子菜单
Dim l As Long
Dim l1 As Long
pmenu = GetMenu(Form1.hwnd)
submenu = GetSubMenu(pmenu, 0)
If submenu Then
CMenu = True
Else
CMenu = False
End If
End Function
Function Icon_Del(ihwnd As Long) As Long
Dim ano As NOTIFYICONDATA
Dim l As Long
ano.hwnd = ihwnd
ano.uID = 0
ano.cbSize = Len(ano)
'删除图标
Icon_Del = Shell_NotifyIcon(NIM_DELETE, ano)
End Function
'这个函数接收图标句柄和窗口句柄并且新建图标
Function Icon_Add(ihwnd As Long, hicon As Long) As Long Dim ano As NOTIFYICONDATA