Как поместить иконку в трей
Добавьте на форму PictureBox и введите следующий код
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_MBUTTONDOWN = &H207
Private Const WM_MBUTTONUP = &H208
Private Const WM_MBUTTONDBLCLK = &H209
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
Dim IconData As NOTIFYICONDATA
Private Sub Form_Load()
Picture1.Visible = False
IconData.cbSize = Len(IconData)
' События, связанные с иконкой будут отображаться в
' Picture1_MouseMove
IconData.hWnd = Picture1.hWnd
IconData.ucallbackMessage = WM_MOUSEMOVE
' Изображение иконки
IconData.hIcon = Form1.Icon
IconData.uId = 1&
IconData.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' Текст подсказки
IconData.szTip = "Пример помещения иконки в трей" & Chr$(0)
' Добавляем иконку в трей
Shell_NotifyIcon NIM_ADD, IconData
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Удаляем иконку из трея
IconData.cbSize = Len(IconData)
IconData.hWnd = Picture1.hWnd
IconData.uId = 1&
Shell_NotifyIcon NIM_DELETE, IconData
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
' События, связанные с иконкой можно узнать по координате X
If X / Screen.TwipsPerPixelX = WM_LBUTTONDOWN Then _
MsgBox "Нажата левая кнопка мыши"
End Sub
|