Results 1 to 5 of 5

Thread: Aaron Young SysTray Sample - Help

  1. #1

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    I am using Aaron Young sample to add My Appl to a systray and it is very good - BUT - i would like to change the icon in some event in my project. How Can i accomplish that???



    Aron Young Sample:


    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 WM_MOUSEMOVE = &H200
    Private Const WM_RBUTTONUP = &H205
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202

    Private tTrayIcon As NOTIFYICONDATA

    Private Sub Form_Load()
    Picture1.Visible = False
    'Create a System Tray Icon
    With tTrayIcon
    'Set the Handle to the Icon you want to Display
    'This could be any Icon, for this example I'm using
    'The Icon assigned to the "Icon" Property of the Form.
    .hIcon = Icon
    'Tray Icon Messages are ReRouted to a Window Handle of
    'Your choice, typically it's wise to use a Picturebox
    'For this purpose.
    .hwnd = Picture1.hwnd
    'Set the "ToolTip" Caption that will Appear
    .szTip = Caption & Chr(0)
    'Set the Message used when Redirecting to the Specified
    'Window Handle
    .uCallbackMessage = WM_MOUSEMOVE
    'Set the Flags to add an Icon, ToolTip and Callback Message
    .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
    'Give the Icon a Unique ID, (This is unique to this Thread/App)
    .uID = 1
    'Set the Size of this Structure
    .cbSize = Len(tTrayIcon)
    End With
    'Add the Icon to the System Tray
    Shell_NotifyIcon NIM_ADD, tTrayIcon
    End Sub

    Private Sub Form_Resize()
    'Don't show the Form in the Taskbar when Minimized
    If WindowState = vbMinimized Then
    Hide
    WindowState = vbNormal
    End If
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    'Remove the System Tray Icon when the Form Unloads
    Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub

    Private Sub mnuExit_Click()
    'Unload the Form from the "Exit" PopupMenu Option
    Unload Me
    End Sub

    Private Sub mnuShow_Click()
    'Show the Form from the "Show" PopupMenu Option
    Show
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'This is the Event that's passed the Callback Message Data
    'From the SystemTray Icon
    Select Case ScaleX(X, vbTwips, vbPixels)
    Case WM_LBUTTONDBLCLK
    'Double Click on SysTray Icon to Show Form
    Show
    Case WM_RBUTTONUP
    'Used for Displaying a Popup Menu
    Me.PopupMenu mnuPopup
    End Select
    End Sub



    Best Regards




  2. #2
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    I too have seen this very popular Sample(many has claimed credits, as well as modifications) one particular modification I had was much longer, but not to much longer, if you look at the code, you'll notice it uses the icon from the picture box, my guess would be to change the picture box, you end up changing the icon, chances are it has a direct connection to the picture box (A hook I assume) so any changes to the picture box, affects the systray, which is why if you right click, move over, do anyting to the system tray, it triggers the Picture1_MouseOver, etc etc etc, good luck, If I find the more detailed and helpful sample I'll give you a holler, I have it at home somewhere on my PRogramming CDs that I saved alot of my beginning projects(boy those were fun)

    Good Luck, be patience answers always come eventually.
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    icon

    change the icon of the form
    ...your original icon that is displayed...

    'The Icon assigned to the "Icon" Property of the Form.


    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    There's a working trayicon control on my homepage, i can send you the source if you want...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Add the "NIM_MODIFY" constant to your Code:
    Code:
    Private Const NIM_MODIFY = &H1
    Then use this Sub:
    Code:
    Public Sub ChangeTrayIcon(vIcon As Variant)
        With tTrayIcon
            .hIcon = vIcon
            .cbSize = Len(tTrayIcon)
        End With
        Shell_NotifyIcon NIM_MODIFY, tTrayIcon
    End Sub
    Example:
    Code:
    Private Sub Command1_Click()
        ChangeTrayIcon LoadPicture("..\Common\Graphics\Icons\Misc\Face01.ico")
    End Sub

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