Link to home
Start Free TrialLog in
Avatar of ueihp
ueihp

asked on

system tray

How do you put an application in the
system tray?  I think it is called the
system tray.  I want to put my application
in the lower right corner of the screen.
The area right next to the system time.

the application is an application i wrote
myself.  i would like the application
to put itself in the system tray.  I don't
want to have to do it manually.
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is another site which demonstrates how to do this. Code is included:

http://www.spnc.demon.co.uk/vb/vbtray.htm
Avatar of Juilette
Juilette

Option Explicit

'systray icon delcares and functions
'
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData _
As NOTIFYICONDATA) As Long

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 NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const WM_MOUSEMOVE = &H200

'You can use NIM_MODIFY in conjunction with changing the
'SysTrayIcon.hIcon property to give the effect of
'an animated System Tray Icon.

'Declare a Variable for the SysTray Icon Data
Private SysTrayIcon As NOTIFYICONDATA

Private Sub Form_Load()

'Create the System Tray Icon Object

        'Image to appear in Tray
        SysTrayIcon.hIcon = Icon
        'Handle of Object to recieve Tray Icon Events
         SysTrayIcon.hwnd = picSysTray.hwnd
        'Caption for Tray Icon, Must End with Chr(0)
        SysTrayIcon.szTip = Caption & Chr(0)
        'Event Triggered When Interacting with Tray Icon
        SysTrayIcon.uCallbackMessage = WM_MOUSEMOVE
        'Parts of Tray Icon we want to setup
        SysTrayIcon.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
        'Unique Identifier
        SysTrayIcon.uID = 1
        'Size of this Variable in Bytes.
        SysTrayIcon.cbSize = Len(SysTrayIcon)
     
    'Add the Icon to the System Tray
    Shell_NotifyIcon NIM_ADD, SysTrayIcon
End Sub

Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon 2, SysTrayIcon
   
      End

End Sub

Private Sub picSysTray_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Select Case Right(Hex(X), 2)
        Case "00"  ' Mouse Move
      '<<< Put Your Code Here >>>
         
        Case "0F"  ' Left Mouse Down
      '<<< Put Your Code Here >>>
        'If the Window is Minimized, Restore it else Minimize it.
        WindowState = IIf(WindowState = vbNormal, _
                            vbMinimized, vbNormal)
     
        Case "1E"  ' Left Mouse Up
      '<<< Put Your Code Here >>>
     
        Case "3C"  ' Right Mouse Down
      '<<< Put Your Code Here >>>
         
        Case "4B"  ' Right Mouse Up
      '<<< Put Your Code Here >>>
         
        Case "2D"  ' Double Left Click
      '<<< Put Your Code Here >>>
         
        Case "5A"  ' Double Right Click
      '<<< Put Your Code Here >>>
  End Select
End Sub


Avatar of ueihp

ASKER

thanks everyone.