Добавление значка программы в область уведомлений

' Module.bas

Option Explicit

Public Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 128
    dwState As Long
    dwStateMask As Long
    szInfo As String * 256
    uTimeoutAndVersion As Long
    szInfoTitle As String * 64
    dwInfoFlags As Long
End Type

Public Enum bFlag
    NIIF_NONE = &H0
    NIIF_INFO = &H1
    NIIF_WARNING = &H2
    NIIF_ERROR = &H3
    NIIF_GUID = &H5
    NIIF_ICON_MASK = &HF
    NIIF_NOSOUND = &H10
End Enum

Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
          (ByVal dwMessage As Long, _
          pnid As NOTIFYICONDATA) As Boolean
          
Public Declare Function SetForegroundWindow Lib "user32" _
      (ByVal hwnd As Long) As Long
      
Public Const WM_USER As Long = &H400
Public Const WM_MOUSEMOVE = &H200

'Left-click constants.
      Public Const WM_LBUTTONDBLCLK = &H203
      Public Const WM_LBUTTONDOWN = &H201
      Public Const WM_LBUTTONUP = &H202

'Right-click constants.
      Public Const WM_RBUTTONDBLCLK = &H206   'Double-click
      Public Const WM_RBUTTONDOWN = &H204     'Button down
      Public Const WM_RBUTTONUP As Long = &H205
      
Public Const NIN_BALLOONSHOW = (WM_USER + 2)
Public Const NIN_BALLOONHIDE = (WM_USER + 3)
Public Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
Public Const NIN_BALLOONUSERCLICK = (WM_USER + 5)
      
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const NIF_STATE = &H8
Public Const NIF_INFO = &H10

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIM_SETFOCUS = &H3
Public Const NIM_SETVERSION = &H4
Public Const NIM_VERSION = &H5

'Form1.frm Dim ni As NOTIFYICONDATA Private Sub Command1_Click() ' показываем balloon With ni .cbSize = Len(ni) .hwnd = Me.hwnd .uID = 1 .uFlags = NIF_INFO ' добавляем значок в balloon .dwInfoFlags = bFlag.NIIF_WARNING ' текст для заголовка в balloon .szInfoTitle = "Внимание" & vbNullChar ' текст в ballon .szInfo = "Сделай паузу!" & vbNullChar End With Shell_NotifyIcon NIM_MODIFY, ni End Sub Private Sub Form_Load() ni.cbSize = Len(ni) ni.hwnd = Me.hwnd ni.uID = 1& ' устанавливаем флаги ni.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE ni.uCallbackMessage = WM_MOUSEMOVE ' иконка для программы ni.hIcon = Me.Icon ' всплыващая подсказка ni.szTip = "Подсказка!" & vbNullChar Shell_NotifyIcon NIM_ADD, ni Me.Hide App.TaskVisible = False End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Static rec As Boolean, msg As Long Dim Result As Long msg = X / Screen.TwipsPerPixelX If rec = False Then rec = True Select Case msg Case WM_LBUTTONDBLCLK '515 restore form window Me.WindowState = vbNormal Result = SetForegroundWindow(Me.hwnd) Me.Show 'Case WM_LBUTTONDOWN: Case WM_LBUTTONUP '514 restore form window Me.WindowState = vbNormal Result = SetForegroundWindow(Me.hwnd) Me.Show 'Case WM_RBUTTONDBLCLK: 'Case WM_RBUTTONDOWN: Case WM_RBUTTONUP: Result = SetForegroundWindow(Me.hwnd) Me.PopupMenu mnuTray Case NIN_BALLOONUSERCLICK Print "Вы щелкнули на balloon" Case NIN_BALLOONSHOW Print "The balloon tip has just been displayed" 'Case NIN_BALLOONHIDE End Select rec = False End If End Sub Private Sub Form_Resize() 'this is necessary to assure that the minimized window is hidden If Me.WindowState = vbMinimized Then Me.Hide End Sub Private Sub Form_Unload(Cancel As Integer) 'this removes the icon from the system tray Shell_NotifyIcon NIM_DELETE, ni End Sub Private Sub mnuAbout_Click() MsgBox "Русский_Проект" End Sub Private Sub mnuExit_Click() Shell_NotifyIcon NIM_DELETE, ni End End Sub