Results 1 to 21 of 21

Thread: Systray Icon

  1. #1

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Systray Icon

    am using a new thread which is a revisit to my previous thread "Tow Questions"

    my second question was dat how do i put my application's icon in System Tray ?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Systray Icon

    my second question was dat how do i put my application's icon in System Tray ?
    in the previous thread, you said to the task bar

    to put into the system tray you use an api call to
    Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long


    · dwMessage
    Identifier of the message to send. This parameter can be one of these values:
    NIM_ADD
    Adds an icon to the status area.
    NIM_DELETE
    Deletes an icon from the status area.
    NIM_MODIFY
    Modifies an icon in the status area.

    · pnid
    Pointer to a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage.


    try a search on "NotifyIcon" to see if any examples have been posted previously

    rgds peter

  3. #3
    Addicted Member Rogier's Avatar
    Join Date
    Jun 2004
    Location
    Netherlands
    Posts
    143

    Re: Systray Icon

    ....or you can try this file:
    Attached Files Attached Files

  4. #4

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    heylo
    well first of all i have imlemented the Shell Notification Icon n its workin fi9 for me, secondly the file u gave me is not workin i tried on win XP as well 98

    now my question is dat i want to change the icon according to the data coming from the port, jus like when we connect internet using dial up connection, there comes two computer like icon in the system tray n they blink lights according to the in/out traffic

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Systray Icon

    you have to use the loadpicture command to change a forms icon.

    me.icon =loadpicture("newicon.ico")

    there is quite a bit in the helpfile for it

    rgds peter

  6. #6

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    well if i change the icon using
    me.icon = loadpicture( someicon )
    it only changes the icon of the form n not the one display in the System Tray

  7. #7
    Lively Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    80

    Re: Systray Icon

    A 3rd party OCX usually does the trick, and require minum code and configuration

  8. #8

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    i searched google, came up few results, but most of them were commercial n one was no more available on da net, so if u do knw ne such ocx pls upload it here or gimme da link !

  9. #9

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    well another prb wid icon is that as the application gets terminated the icon doesn't disappear until i point the mouse over to that icon in hte sytem tray

  10. #10
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Systray Icon

    Why would you want to use 3rd party ocxs? They just make your app larger in size when distributing and may create some problems.

    Basic code for adding to systray is
    VB Code:
    1. NID.cbSize = Len(NID)
    2.   NID.hWnd = yourpicbox.hWnd
    3.   NID.uID = 0
    4.   NID.uID = NID.uID + 1
    5.   NID.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    6.   NID.uCallbackMessage = WM_MOUSEMOVE
    7.   NID.hIcon = yourpicbox.Picture
    8.   NID.szTip = yourtooltiptext + Chr$(0)
    9.   Shell_NotifyIconA NIM_ADD, NID

    Use APIviewer for all the declarations (NID is NOTIFYICONDATA type and make sure it's public otherwise removing won't work)

    to remove the systray use Shell_NotifyIconA NIM_DELETE, NID

    all systray commands now are processed in your yourpicbox_mousemove.
    use msg = (x And &HFF) * &H100 to determine what is going on over the systray icon and If msg = &HF00 then whatever (left click), etc.

    P.S. I don't remember the constants for all the mouse actions but I think they are all WM_ group.

  11. #11

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    hi well u were ryte, NID_DELET was private n making it public removes the icon from systray
    now wat abt the next question dat i want to frequently update the icon, n lemme tell u project is same sa windows dialler n the icon i want to change is jus like blinking lights when data comes n goes.
    adding n deleting icon each time wont do the job !

  12. #12
    Junior Member
    Join Date
    Jan 2005
    Posts
    26

    Re: Systray Icon

    search on google for "mbtray". it's a .ocx file and it's easy to understand.

  13. #13
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Systray Icon

    Here's the code. I figured I'd make a nice mod for my collection also.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type NOTIFYICONDATA
    4.   cbSize As Long
    5.   hWnd As Long
    6.   uID As Long
    7.   uFlags As Long
    8.   uCallbackMessage As Long
    9.   hIcon As Long
    10.   szTip As String * 64
    11. End Type
    12.  
    13. Public Enum bMode
    14.   Add = 1
    15.   Modify = 2
    16.   Delete = 3
    17. End Enum
    18.  
    19. Private Const WM_MOUSEMOVE As Integer = &H200
    20. Private Const NIM_ADD = &H0&
    21. Private Const NIM_MODIFY As Integer = &H1
    22. Private Const NIM_DELETE As Integer = &H2
    23. Private Const NIF_MESSAGE As Integer = &H1
    24. Private Const NIF_ICON As Integer = &H2
    25. Private Const NIF_TIP As Integer = &H4
    26.  
    27. Private Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    28.  
    29. Public NID As NOTIFYICONDATA
    30.  
    31. Public Sub TrayIcon(TrayPic As PictureBox, Optional TrayTip As String = "", Optional in_bMode As bMode = 1)
    32.  
    33.   If in_bMode = Add Then
    34.     NID.cbSize = Len(NID)
    35.     NID.hWnd = TrayPic.hWnd
    36.     NID.uID = 0
    37.     NID.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    38.     NID.uCallbackMessage = WM_MOUSEMOVE
    39.     NID.hIcon = TrayPic.Picture
    40.     NID.szTip = TrayTip + Chr$(0)
    41.     Shell_NotifyIconA NIM_ADD, NID
    42.   ElseIf in_bMode = Modify Then
    43.     NID.cbSize = Len(NID)
    44.     NID.hIcon = TrayPic.Picture
    45.     NID.szTip = TrayTip + Chr$(0)
    46.     Shell_NotifyIconA NIM_MODIFY, NID
    47.   ElseIf in_bMode = Delete Then
    48.     Shell_NotifyIconA NIM_DELETE, NID
    49.   End If
    50.  
    51. End Sub

    To add a pic use TrayIcon yourpicturebox, "test_add", Add
    To modify (animate to a next slide) use TrayIcon your2ndpicturebox, "test_modify", Modify
    To delete use TrayIcon TrayPic, vbNullString, Delete

    Make sure an ICON is loaded into your picturebox, not a bitmap.
    Last edited by Dmitri K; Jan 3rd, 2005 at 07:10 PM.

  14. #14

    Thread Starter
    Addicted Member hyousuf2's Avatar
    Join Date
    Dec 2004
    Location
    Dublin
    Posts
    226

    Re: Systray Icon

    hi well i havent tried ur code as yet but can jus explain the parameters passed to NotifyIconData n explain their purpose !

  15. #15
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Systray Icon

    A systray example from my archives. See also the topic the attachment is posted in for more information.

  16. #16
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: Systray Icon

    Hi everybdy...


    VB Code:
    1. Private Const WM_MOUSEMOVE As Integer = &H200....
    ....

    can any one of u please tell me how to remeber all these CONSTANTS...Is there any specific way to remember or else will these come automatically with the API viewer(Like Type Variables..)..I tried with API Viewer,but they didn't come ..Please tell me whatz the use of these constants and hw to remember these..


    rgrds
    Srikanth..

  17. #17
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Systray Icon

    THey are in API viewer. Make sure you load WIN32API.txt and the contants will be in the API Type dropdown.

    P.S. It is impossible to remember all the contants on top of all the declarations because you can make your own DLL with its own declarations and your own constants like Const Five As Integer = 5. They are used to simplify coding/for the code to make more sense, you do NOT have to use them. You can replace every Five with a 5 in the code, or in your example every WM_MOSEMOVE with 512 (&H200 = 512). The problem is if you use 512, how are you going to remember when updating your project that 512 is mousemove? Instead of having

    case 513
    case 519
    case 516

    I'd rather have

    case WM_LBUTTONDOWN
    case WM_MBUTTONDOWN
    case WM_RBUTTONDOWN

    It just makes your life easier.
    Last edited by Dmitri K; Jan 4th, 2005 at 05:16 PM.

  18. #18
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Systray Icon

    hyousuf2: Click here for the explanation

  19. #19
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Systray Icon

    Hmmmm...

    The code that has been posted, no offence Merri, is a little bit of a hack.
    By this I mean using a forms Mouse events to handle systray events. Personally I don't like this. It also means you have to replicate code from app to app that use the systray.

    The link in my sig has come systray code that allows you to create a systray icon with it's own window to handle it's events. No need for a form.
    It also allows for dynamic menus at runtime and does not reply on the menu from a form.
    It is also capable of animated systray icons, of which there is a demo of in my code.

    The systray code is wrapped up in a simple class that exposes usefull events and properties to the UI.

    The code to use my systray icon class would be something like:
    Code:
    Option Explicit
    
    Private mobjSystray   As Systray
    
    Private Sub Form_Load()
        Set mobjSysTray = New SysTray
        With mobjSysTray
            Set .ImageList = ImageList1
            .Icon = 1
            .Menu.Add "Show", "SHOW", , , , False
            .Menu.Add "Hide", "HIDE", , , , True
            .Menu.Add "-"
            .Menu.Add "Annimate", "ANNIMATE", , , False
            .Menu.Add "-"
            .Menu.Add "Exit Application", "EXIT"
            .EnableMenu = True
            .Visible = True
        End With
    End Sub
    
    Private Sub mobjSysTray_DoubleClick(ByVal Button As MouseButtonConstants)
        ShowForm
    End Sub
    
    Private Sub mobjSysTray_MenuClick(Item As vbSysTrayTools.MenuItem)
        Select Case Item.Key
            Case "SHOW"
                ShowForm
            Case "HIDE"
                HideForm
            Case "ANNIMATE"
                'Annimate
            Case "EXIT"
                Unload Me
        End Select
    End Sub
    
    Private Sub ShowForm()
        With mobjSysTray.Menu
            .Item("SHOW").Enabled = False
            .Item("HIDE").Enabled = True
        End With
        Me.WindowState = vbNormal
        Me.Show
    End Sub
    
    Private Sub HideForm()
        With mobjSysTray.Menu
            .Item("SHOW").Enabled = True
            .Item("HIDE").Enabled = False
        End With
        Me.Hide
    End Sub
    Hope this helps.

    WOka

    PS I found this thread while trying to search for a method to get the hWnd of the icon window in the systray, as I need this for something I am working on. Anyone got any ideas?

  20. #20
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Systray Icon

    a couple of mins ago i was going thru another thread, right here and guess what i found, the guy has a working(assumed) version of system tray icon or something u need and he is working with windows xp.

    http://www.vbforums.com/showthread.php?t=320143
    try it. he has attached a project there which has the class module. u even have a readymade example.

  21. #21
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Systray Icon

    That example isn't the neatest I've seen around, but better than most, plus they are STILL using a form to deal with the systray messages. This is NOT required as is a cheap hack.
    Also, the systray code doesn't have much functionality.

    Woka

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