CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 1999
    Posts
    18

    Getting a list of apps shown in system tray

    Hello,

    Is there a way to get a list of all the applications represented by the system tray icons ? For example, I would like to get, for each of them :

    - Application name
    - Application state (minimized or not)
    - System Tray Icon absolute coordinates

    Thanks...


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Getting a list of apps shown in system tray

    I'd use FindWindow API to find the system tray window:
    hwnd = FindWindow("Shell_TrayWnd", vbNullString)

    Then, enumerate all children of that window using EnumChildWindows.
    Then, for each child
    - call GetWindowText to get the application title
    - call IsIconic to find out if it is minimized
    - call GetWindowRect to get the position of the window


  3. #3
    Join Date
    Dec 1999
    Posts
    18

    Re: Getting a list of apps shown in system tray

    Close, but not quite right...

    Here's the window tree I get when I call EnumChildWindows recursively on "Shell_TrayWnd" :

    Child Class = Button, Title = , L: 2, R: 56
    Child Class = TrayNotifyWnd, Title = , L: 856, R: 1022
    +++++Child Class = TrayClockWClass, Title = , L: 961, R: 1022
    Child Class = TrayClockWClass, Title = , L: 961, R: 1022
    Child Class = MSTaskSwWClass, Title = , L: 60, R: 852
    +++++Child Class = SysTabControl32, Title = , L: 60, R: 852
    Child Class = SysTabControl32, Title = , L: 60, R: 852

    I see the TrayNotifyWnd window going from horizontal coordinates 856 to 1022 (in a 1024*768 resolution), but calling EnumChildWindows on that window results in only ONE child, the TrayClockWClass window, going from horizontal coordinates 961 to 1022.

    How do I get access to the icons, which are obviously between horizontal coordinates 856 and 960 ?

    Unless my code to get recursive windows is bugged... Here's the callback function for the EnumChildWindows API function:


    Function enumRecursif(byval lhWnd as Long, byval lParam as Long) as Long
    Dim RetVal as Long
    Dim WinClassBuf as string * 255, WinTitleBuf as string * 255
    Dim WinClass as string, WinTitle as string
    Dim WinRect as RECT
    Dim WinWidth as Long, WinHeight as Long
    Dim tmpText as string
    Dim i as Long
    Dim ThreadId as Long

    RetVal = GetClassName(lhWnd, WinClassBuf, 255)
    WinClass = StripNulls(WinClassBuf) ' remove extra Nulls & spaces
    RetVal = GetWindowText(lhWnd, WinTitleBuf, 255)
    WinTitle = StripNulls(WinTitleBuf)
    RetVal = GetWindowRect(lhWnd, WinRect)
    for i = 1 to lParam * 5
    tmpText = tmpText & " "
    next i
    tmpText = tmpText & "Child Class = " & WinClass & ", Title = " & WinTitle & ", L: " & WinRect.Left & ", R: " & WinRect.Right
    Debug.print tmpText
    Call WrapperRecursif(lhWnd, lParam + 1)
    enumRecursif = true
    End Function

    Sub WrapperRecursif(byval lhWnd as Long, lParam as Long)
    Dim RetVal as Long
    RetVal = EnumChildWindows(lhWnd, AddressOf enumRecursif, lParam)
    End Sub






  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Getting a list of apps shown in system tray

    At the first look, i am confused, why is there a call to

    Call WrapperRecursif(lhWnd, lParam + 1)



    in the Function enumRecursif ?? (in the last but 2 line)!!

    This function need not call the Wraperxxx again.. One call to EnumChildWindows will call this enumRecuseif function, passing each window handle of the child windows.

    To proceed you need to return True, or return false to stop. You dont need to call the function again & again.

    Well this is at the first look, excuse me if i overlooked something!...

    RK

  5. #5
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Getting a list of apps shown in system tray

    Ok. sorry , i was too fast.. unnecesarily..
    You want enumeration, lover levels.. intentional.

    Sorry again.

    RK

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

Featured