get ListNames of all applications there are in SysTray now

Just starting out? Need help? Post your questions and find answers here.
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

get ListNames of all applications there are in SysTray now

Post by A M S »

get names of all applications there are in SysTray now

name of file.exe or showed name in title-bar is need :?:
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: get ListNames of all applications there are in SysTray now

Post by A M S »

:shock: any :shock:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: get ListNames of all applications there are in SysTray now

Post by netmaestro »

Well, if you're gonna get all shocked about it... how's this grab you? :mrgreen:

Code: Select all

; Enumerate Systray Icons
; netmaestro October 2009
; Tested on XP and Vista, doesn't work for Windows 7
; Just for fun

Structure TRAYOWNER
  bitmap.i
  hwnd.s
  filename.s
EndStructure

 Structure TRAYDATA
    hwnd.l                
    uID.l             
    uCallbackMessage.l    
    Reserved.l[2]      
    hIcon.l                
 EndStructure

Global NewList TrayIcons.TRAYOWNER()

Procedure Enumerate_TrayIcons()

  lib = OpenLibrary(#PB_Any, "psapi.dll")
  
  ; Find the System Tray Icon Toolbar
  Protected hwnd
  hWnd = FindWindow_("Shell_TrayWnd", #Null)
  If hWnd
    hWnd = FindWindowEx_(hWnd, #Null, "TrayNotifyWnd", #Null)
    If hWnd
      hWnd = FindWindowEx_(hWnd,#Null, "SysPager", #Null)
      If hWnd 
        hTray = FindWindowEx_(hWnd, #Null, "ToolbarWindow32", #Null)
      Else
        ProcedureReturn 0
      EndIf
    Else
      ProcedureReturn 0
    EndIf
  Else
    ProcedureReturn 0
  EndIf
  
  count = SendMessage_(hTray, #TB_BUTTONCOUNT, 0, 0)
  
  Dim button.TBBUTTON   (count)
  Dim button_td.TRAYDATA(count)
  
  dwExplorerThreadId=GetWindowThreadProcessId_(hTray, @dwExplorerProcessId)
  hProc = OpenProcess_(#PROCESS_ALL_ACCESS, #False, dwExplorerProcessId)
  *lpData = VirtualAllocEx_(hProc, #Null, SizeOf(TBBUTTON)*count, #MEM_COMMIT, #PAGE_READWRITE)
  
  For i = 0 To count-1
    SendMessage_(hTray, #TB_GETBUTTON, i, *lpData+i*SizeOf(TBBUTTON) )
    ReadProcessMemory_(hProc, *lpData+(i*SizeOf(TBBUTTON)), @button.TBBUTTON(i), SizeOf(TBBUTTON), #Null)
    ReadProcessMemory_(hProc, button(i)\dwData, @button_td.TRAYDATA(i), SizeOf(TRAYDATA), #Null)
    
    thisbmp = button_td(i)\hIcon
    thishwnd = button_td(i)\hwnd
    thisfilename$ = Space(#MAX_PATH)

    GetWindowThreadProcessId_(thishwnd, @thisprocessID.i)
    hthisProcess = OpenProcess_( #PROCESS_QUERY_INFORMATION | #PROCESS_VM_READ, #False, thisprocessID )
    CallFunction(lib, "GetProcessImageFileNameA", hthisProcess, @thisfilename$, 255)
    CloseHandle_(hthisProcess)
    
    AddElement(TrayIcons())
    TrayIcons()\hwnd = Str(thishwnd)
    trayIcons()\filename = thisfilename$
    TrayIcons()\bitmap = thisbmp
  Next
  
  VirtualFreeEx_(hProc, *lpData, #Null, #MEM_RELEASE)

  CloseHandle_(hProc)
  If IsLibrary(lib) : CloseLibrary(lib) : EndIf
  
EndProcedure

Enumerate_TrayIcons()

OpenWindow(0,0,0,600,400,"System Tray Icon Owners",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0,0,0,600,400,"Icon", 60, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Owner hWnd",100)
AddGadgetColumn(0, 2, "Owner Location",435)
ForEach TrayIcons()
  AddGadgetItem(0,-1, Chr(10)+TrayIcons()\hwnd +Chr(10)+trayicons()\filename, TrayIcons()\bitmap)
Next

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Last edited by netmaestro on Mon Oct 12, 2009 4:37 am, edited 1 time in total.
BERESHEIT
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: get ListNames of all applications there are in SysTray now

Post by A M S »

:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D
Image
:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D
Thanks netmaestro, you save me
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: get ListNames of all applications there are in SysTray now

Post by PB »

> Well, if you're gonna get all shocked about it... how's this grab you?

:lol: Awesome!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: get ListNames of all applications there are in SysTray now

Post by rsts »

hmm - nothing in win7 :(

cheers
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: get ListNames of all applications there are in SysTray now

Post by netmaestro »

Do a bit of troubleshooting if you can rsts, I'd start looking at the classnames I'm searching for with FindWindowEx. Maybe they're different in w7. Throw a debug in right after the search block with all those ProcedureReturn 0's and see if you're still there. My guess is Elvis has left the building. If we can learn the right names for w7 we can do a GetVersion first and branch. Let me know what you find.

[Edit] Tested on XP and Vista, no problems.
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: get ListNames of all applications there are in SysTray now

Post by rsts »

They're all there apparently, no debugs on the return 0.

Win 7 does something with grouping the traskbar and trayIcons, so it may be handling them somewhat differently.

I'll see what I can find

cheers

edit
#TB_BUTTONCOUNT always returns 1.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: get ListNames of all applications there are in SysTray now

Post by netmaestro »

Yeah, it looks like the system tray in Win7 is a different animal. Probably can't be made to work in its current form, have to do some research.
BERESHEIT
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: get ListNames of all applications there are in SysTray now

Post by Kwai chang caine »

For information...nothing too in W2000 :oops:
ImageThe happiness is a road...
Not a destination
A M S
User
User
Posts: 58
Joined: Fri Aug 14, 2009 2:26 pm
Location: Afghanistan

Re: get ListNames of all applications there are in SysTray now

Post by A M S »

then i have many chance, because just i need this code for XP nonce :D
the code is really one, if it was compatible with XP and next , it will be Excellent :D
jayand
User
User
Posts: 22
Joined: Sat Mar 04, 2023 12:55 pm

Re: get ListNames of all applications there are in SysTray now

Post by jayand »

Crashes on Win 10 with PB 6.01 b5..Any chance of an update??
Line 88 reads:
AddGadgetItem(0,-1, Chr(10)+TrayIcons()\hwnd +Chr(10)+trayicons()\filename, TrayIcons()\bitmap)
Crash Log:
[ERROR] Line: 88
[ERROR] AddGadgetItem(): The specified 'ImageID' is not valid.
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: get ListNames of all applications there are in SysTray now

Post by Caronte3D »

Maybe this thread help you:
viewtopic.php?t=80961
jayand
User
User
Posts: 22
Joined: Sat Mar 04, 2023 12:55 pm

Re: get ListNames of all applications there are in SysTray now

Post by jayand »

Thanks Caronte3D,
I am already aware of that code and viewtopic.php?t=51549, but I wanted to get this code working also.
Regards
Jay
Last edited by jayand on Sun Mar 05, 2023 11:08 pm, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: get ListNames of all applications there are in SysTray now

Post by netmaestro »

The code has to be updated to work with Windows 7 and above. Looking at it now for an approach.
BERESHEIT
Post Reply