窗体加一个 picture1, 放一图片 窗体代码: 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 t As NOTIFYICONDATA Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dw_Message As Long, pnid As NOTIFYICONDATA) As Boolean Private Sub Form_Resize() If Me.WindowState = vbMinimized Then t.cbSize = Len(t) t.hWnd = Picture1.hWnd t.uId = 1& t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE t.ucallbackMessage = WM_mousemove t.hIcon = Picture1.Picture t.szTip = "最大化窗口" Shell_NotifyIcon NIM_ADD, t Me.Hide End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Me.WindowState <> vbMinimized Then Exit Sub End If
If ((Button And vbLeftButton) > 0) Then t.cbSize = Len(t) t.hWnd = Picture1.hWnd t.uFlags = NIF_ICON t.uId = 1& Shell_NotifyIcon NIM_delete, t Me.WindowState = vbNormal Me.Show End If
窗体代码: 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 WM_mousemove = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private t As NOTIFYICONDATA
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dw_Message As Long, pnid As NOTIFYICONDATA) As Boolean
Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then
t.cbSize = Len(t)
t.hWnd = Picture1.hWnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_mousemove
t.hIcon = Picture1.Picture
t.szTip = "最大化窗口"
Shell_NotifyIcon NIM_ADD, t
Me.Hide
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Me.WindowState <> vbMinimized Then
Exit Sub
End If
If ((Button And vbLeftButton) > 0) Then
t.cbSize = Len(t)
t.hWnd = Picture1.hWnd
t.uFlags = NIF_ICON
t.uId = 1&
Shell_NotifyIcon NIM_delete, t
Me.WindowState = vbNormal
Me.Show
End If
End Sub