Systray Icon

SonicX_BlueBlur
SonicX_BlueBlur used Ask the Experts™
on
How do I make a Systray icon, and also how to call a context menu when one right-clicks the Systray icon?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
add this to a form:

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_MODIFY = &H1
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 Const WM_LBUTTONDBLCLK = &H203   'Double-click
Private Const WM_LBUTTONDOWN = &H201     'Button down
Private Const WM_LBUTTONUP = &H202       'Button up
Private Const WM_RBUTTONDBLCLK = &H206   'Double-click
Private Const WM_RBUTTONDOWN = &H204     'Button down
Private Const WM_RBUTTONUP = &H205       'Button up
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim nid As NOTIFYICONDATA


Private Sub Form_Load()
'If the application dosen't have a previous instance then load the form
If App.PrevInstance = False Then
       nid.cbSize = Len(nid)
       nid.hwnd = Form1.hwnd
       nid.uId = vbNull
       nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       nid.uCallBackMessage = WM_MOUSEMOVE
       nid.hIcon = Form1.Icon
       nid.szTip = "Double Click To Restore Your application.." & vbNullChar
       Shell_NotifyIcon NIM_ADD, nid
  End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   Dim lMsg As Long
   Dim sFilter As String
   lMsg = X / Screen.TwipsPerPixelX
   Select Case lMsg
      Case WM_LBUTTONDOWN
     
      Case WM_LBUTTONUP
            MsgBox "Left Button"
      Case WM_LBUTTONDBLCLK
     
      Case WM_RBUTTONDOWN

      Case WM_RBUTTONUP
            MsgBox "Right Button"
      Case WM_RBUTTONDBLCLK
   
   End Select
 End Sub


Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
End
End Sub

Commented:
HOWTO: Use the System Tray Directly from Visual Basic
http://support.microsoft.com/default.aspx?scid=KB;en-us;q176085

Commented:
The above will use the icon that you set on your form in the system tray.
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

To create a system tray icon, simply set the forms icon to your desired image and use the ActiveForm control which can be found here: http://elogica.br.inter.net/prograph/activepack/download/ActiveForm.zip  to send it to the system tray.  Use the menu editor to create an menu item and set its visible property to false.  under that item, add the items you would like to display when the tray icon is clicked.  To give these items functionality, simply locate their corresponding sub (i.e., mnuExit) and place your event handling code there.
Author of the Year 2009

Commented:
Moderator, my recommended disposition is:

    Accept vinnyd79's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Author

Commented:
Sorry about that. Triple points because I forgot :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial