Add your application's icon to the system tray

   Option Explicit
   ' Variables and Declares used by various Win32 API calls.
   Public Const NIF_ICON = &H2
   Public Const NIF_MESSAGE = &H1
   Public Const NIF_TIP = &H4
   Public Const NIM_ADD = &H0
   Public Const NIM_DELETE = &H2
   Public Const WM_MOUSEMOVE = &H200
   Public Const MAX_TOOLTIP As Integer = 64

      cbSize As Long
      hwnd As Long
      uID As Long
      uFlags As Long
      uCallbackMessage As Long
      hIcon As Long
      szTip As String * MAX_TOOLTIP
   End Type

   Public nfIconData As NOTIFYICONDATA

   Declare Function Shell_NotifyIcon Lib "Shell32.dll" _
      Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, _
      lpData As NOTIFYICONDATA) As Long
   Public Sub pAddIconToTray(ByVal lHwnd As Long, ByVal lIcon As Long, _
      ByVal lIconHwnd As Long, sTip As String
      ' Add this application's icon to the system tray.
      ' Parm 1 = Handle of form
      ' Parm 2 = Icon
      ' Parm 3 = Handle of icon
      ' Parm 4 = Tip for sys tray icon.
      With nfIconData
         .hwnd = lHwnd
         .uID = lIcon
         .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
         .uCallbackMessage = WM_MOUSEMOVE
         .hIcon = lIconHwnd
         .szTip = sTip & vbNullChar
         .cbSize = Len(nfIconData)
      End With

      Call Shell_NotifyIcon (NIM_ADD, nfIconData)
   End Sub

   Public Sub pRemoveIconFromTray()
      ' Remove this application from the System Tray.
      Call Shell_NotifyIcon (NIM_DELETE, nfIconData)
   End Sub

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2016 TheScarms
Goto top of page