Results 1 to 3 of 3

Thread: changing system tray icons

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Sheffield, Derbyshire, UK
    Posts
    68

    Post

    How can I change the Icon in the system tray?
    Also, how can I make it flash?
    Thanx

    ------------------
    jimmy
    ICQ:35813919
    mail:jim@rdalby.f9.co.uk

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Set the NOTIFYICON Type hIcon Property to the Image you want to Display in the Tray, then Call the Shell_NotifyIcon Function with the NIM_MODIFY Flag, eg.

    On a Form, Add an Invisible Picturebox with an Icon loaded in it and a Timer Control..
    Code:
    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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    
    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
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_RBUTTONDOWN = &H204
    
    Private tTrayIcon As NOTIFYICONDATA
    
    Private Sub Form_Load()
        'Create a Tray Icon
        Picture1.Visible = False
        With tTrayIcon
            .hIcon = Icon
            .hwnd = Picture1.hwnd
            .szTip = "My Tray Icon" & Chr(0)
            .uCallbackMessage = WM_MOUSEMOVE
            .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
            .uID = 1
            .cbSize = Len(tTrayIcon)
        End With
        Shell_NotifyIcon NIM_ADD, tTrayIcon
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Resize()
        DoEvents
        If WindowState = vbMinimized Then
            Hide
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Remove the Tray Icon
        Timer1.Enabled = False
        Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Select Case ScaleX(X, vbTwips, vbPixels)
        Case WM_RBUTTONDOWN
            'Show Popup Menu
        Case WM_LBUTTONDBLCLK
            'Show the Form
            WindowState = vbNormal
            Show
        End Select
    End Sub
    
    Private Sub Timer1_Timer()
        Static bFlash As Boolean
        bFlash = Not bFlash
        If bFlash Then
            tTrayIcon.hIcon = Picture1
        Else
            tTrayIcon.hIcon = Icon
        End If
        tTrayIcon.cbSize = Len(tTrayIcon)
        Shell_NotifyIcon NIM_MODIFY, tTrayIcon
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Sheffield, Derbyshire, UK
    Posts
    68

    Post

    Thanx Very much

    ------------------
    jimmy
    ICQ:35813919
    mail:jim@rdalby.f9.co.uk

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