补充上一帖子(API函数问题)
https://bbs.bccn.net/thread-444836-1-1.html最后一楼的问题过早结贴了,所以重新给一下分
[ 本帖最后由 renxiaoyao36 于 2015-5-5 20:46 编辑 ]
Option Explicit Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) 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 WM_LBUTTONUP = &H202 'Private Const WM_RBUTTONUP = &H205 Public Const NIM_ADD = &H0 Public Const NIM_MODIFY = &H1 Public Const NIM_DELETE = &H2 Public Const NIF_MESSAGE = &H1 Public Const NIF_ICON = &H2 Public Const NIF_TIP = &H4 Public Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP Public Const WM_MOUSEMOVE = &H200 Public Const WM_LBUTTONDBLCLK = &H203 Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const WM_RBUTTONDBLCLK = &H206 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205 Public Const SW_RESTORE = 9 Public Const SW_HIDE = 0 '添加图标到系统托盘 Public Sub AddIco(frm As Form, Information As String) On Error Resume Next Dim LPICON As Long Dim Tic As NOTIFYICONDATA Tic.cbSize = Len(Tic) Tic.hWnd = frm.hWnd Tic.UID = 1& Tic.uFlags = NIF_DOALL Tic.uCallbackMessage = WM_MOUSEMOVE Tic.hIcon = frm.Icon Tic.szTip = Information & Chr$(0) LPICON = Shell_NotifyIcon(NIM_ADD, Tic) End Sub '修改图标 Public Sub ModiIco(frm As Form, Information) On Error Resume Next Dim LPICON As Long Dim Tic As NOTIFYICONDATA Tic.cbSize = Len(Tic) Tic.hWnd = frm.hWnd Tic.UID = 1& Tic.uFlags = NIF_DOALL Tic.uCallbackMessage = WM_MOUSEMOVE Tic.hIcon = frm.Icon Tic.szTip = Information & Chr$(0) LPICON = Shell_NotifyIcon(NIM_ADD, Tic) End Sub '删除图标 Public Sub DeleteIcon(frm As Form) On Error Resume Next Dim LPICON As Long Dim Tic As NOTIFYICONDATA Tic.cbSize = Len(Tic) Tic.hWnd = frm.hWnd Tic.UID = 1& LPICON = Shell_NotifyIcon(NIM_DELETE, Tic) End Sub
Option Explicit Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next Dim lMsg As Single lMsg = X / Screen.TwipsPerPixelX Select Case lMsg Case WM_LBUTTONUP, WM_RBUTTONUP '单击左键,显示窗体 Me.WindowState = 0 Me.Show Call DeleteIcon(Me) End Select End Sub
Option Explicit Private Sub Command1_Click() Call AddIco(MDIForm1, "提示") MDIForm1.Hide End Sub