Results 1 to 7 of 7

Thread: Where i can find a exemple of systemtray

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    9

    Question

    I found on previous topic some code API to put my form in tray whit icon but they dont work. Maybe is my fault but
    I try to find some example ready to show me how you do.

    thanks

  2. #2
    Guest
    Try this. Make 2 Forms (frmTray and Form1) and a Module. On frmTray, make a PictureBox or an ImageBox with an Icon in it and set the Index property to 0. Also, Set Form1's ShowInTaskBar property to False.

    Add this code to the Module. Make sure the Startup Form is Sub Main.
    Code:
    Option Explicit
    
    Sub Main()
        Load frmTray
        Form1.Show
    End Sub
    Now add this code to frmTray.
    Code:
    Option Explicit
    
    'Messages
    Private Const NIM_ADD = &H0             'Adds an icon to the taskbar notification area
    Private Const NIM_MODIFY = &H1          'Changes the icon, tooltip text or notification message for an icon in the notification area
    Private Const NIM_DELETE = &H2          'Deletes an icon from the taskbar notification area
    
    'Flags
    Private Const NIF_MESSAGE = &H1         'hIcon is valid
    Private Const NIF_ICON = &H2            'uCallbackMessage is valid
    Private Const NIF_TIP = &H4             'szTip is valid
    
    Private Const WM_MOUSEMOVE = &H200      'MouseMove message identifier
                                        
                                            'Messages sent to the form's MouseMove event
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const WM_RBUTTONDBLCLK = &H206
    Private Const WM_RBUTTONDOWN = &H204
    Private Const WM_RBUTTONUP = &H205
    
    
    Private Type NOTIFYICONDATA
        cbSize              As Long
        hWnd                As Long         'Handle of window that receives notification messages
        uID                 As Long         'Application-defined identifier of the taskbar icon
        uFlags              As Long         'Flags indicating which structure members contain valid data
        uCallbackMessage    As Long         'Application defined callback message
        hIcon               As Long         'Handle of taskbar icon
        szTip               As String * 64  'Tooltip text to display for icon
    End Type
    
    Dim mtIconData          As NOTIFYICONDATA
    Dim mnLight             As Integer
    
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long
    
    Private Sub Form_Load()
        AddIconToTray
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        DeleteIconFromTray  'Put cleanup code here so that it always gets executed
        Set frmTray = Nothing
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Static bBusy As Boolean
        If bBusy = False Then
            bBusy = True
            
            Select Case CLng(X)
                Case WM_LBUTTONDBLCLK   ' Left button Double Clicked
                    Form1.Show          ' Show our Form
                Case WM_LBUTTONDOWN     ' Left button Down
                    If Shell_NotifyIcon(NIM_MODIFY, mtIconData) = 0 Then
                        MsgBox "Unable to change icon in system tray!"
                    End If
                Case WM_LBUTTONUP       'Left mouse button released
                Case WM_RBUTTONDBLCLK   'Double-click right mouse button
                Case WM_RBUTTONDOWN     'Right mouse button pressed
            End Select
            bBusy = False
        End If
        
    End Sub
    
    
    Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area
    
        With mtIconData
            .cbSize = Len(mtIconData)
            .hWnd = Me.hWnd                                     'Use the form to receive callback messages.
            .uCallbackMessage = WM_MOUSEMOVE                    'Tell icon to send MouseMove messages.
            .uID = 1&                                           'Application defined identifier
            .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
            .hIcon = imgTrayIcon(0).Picture                     'Initial icon
            .szTip = "ToolTipText" & Chr$(0)                    'Initial tooltip for icon
            If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then   'Create icon in tray
                MsgBox "Unable to add icon to system tray!"
            End If
        End With
        
    End Sub
    
    Private Sub DeleteIconFromTray()
        If Shell_NotifyIcon(NIM_DELETE, mtIconData) = 0 Then
            MsgBox "Unable to delete icon from system tray!"
        End If
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    9
    i got a error of compiling there (in black)

    Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area

    With mtIconData
    .cbSize = Len(mtIconData)
    .hWnd = Me.hWnd 'Use the form to receive callback messages.
    .uCallbackMessage = WM_MOUSEMOVE 'Tell icon to send MouseMove messages.
    .uID = 1& 'Application defined identifier
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .hIcon = imgTrayIcon(0).Picture 'Initial icon
    .szTip = "ToolTipText" & Chr$(0) 'Initial tooltip for icon
    If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then 'Create icon in tray
    MsgBox "Unable to add icon to system tray!"
    End If
    End With

    End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    9
    try to do a nice code clean.....


    Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area

    With mtIconData
    .cbSize = Len(mtIconData)
    .hWnd = Me.hWnd 'Use the form to receive callback messages.
    .uCallbackMessage = WM_MOUSEMOVE 'Tell icon to send MouseMove messages.
    .uID = 1& 'Application defined identifier
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .hIcon = imgTrayIcon(0).Picture 'Initial icon
    .szTip = "ToolTipText" & Chr$(0) 'Initial tooltip for icon
    If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then 'Create icon in tray
    MsgBox "Unable to add icon to system tray!"
    End If
    End With

    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    9
    i hope this time they work

    Code:
    Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area 
    
    With mtIconData 
    .cbSize = Len(mtIconData) 
    .hWnd = Me.hWnd 'Use the form to receive callback messages. 
    .uCallbackMessage = WM_MOUSEMOVE 'Tell icon to send MouseMove messages. 
    .uID = 1& 'Application defined identifier 
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE 
    .hIcon = imgTrayIcon(0).Picture 'Initial icon 
    .szTip = "ToolTipText" & Chr$(0) 'Initial tooltip for icon 
    If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then 'Create icon in tray 
    MsgBox "Unable to add icon to system tray!" 
    End If 
    End With 
    
    End Sub

  6. #6
    Guest
    Did you set the Index property to 0?

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    9
    ok they work now..but when i doubleclick on the icon, the form supose come up ?.

    Or do you have the code to hide my form and after appear icon in the systemtray ..(like icq) thats i try to find

    but your code is great to...

    sorry if i ask too much..long time i try to do that systemtray.

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width