Page 1 of 1
get ListNames of all applications there are in SysTray now
Posted: Fri Oct 09, 2009 1:39 pm
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

Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 2:32 pm
by A M S

any

Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 5:45 pm
by netmaestro
Well, if you're gonna get all shocked about it... how's this grab you?
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
Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 6:08 pm
by A M S
Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 8:32 pm
by PB
> Well, if you're gonna get all shocked about it... how's this grab you?

Awesome!
Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 9:04 pm
by rsts
hmm - nothing in win7
cheers
Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 9:14 pm
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.
Re: get ListNames of all applications there are in SysTray now
Posted: Sun Oct 11, 2009 10:52 pm
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.
Re: get ListNames of all applications there are in SysTray now
Posted: Mon Oct 12, 2009 4:38 am
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.
Re: get ListNames of all applications there are in SysTray now
Posted: Mon Oct 12, 2009 9:49 am
by Kwai chang caine
For information...nothing too in W2000

Re: get ListNames of all applications there are in SysTray now
Posted: Mon Oct 12, 2009 12:41 pm
by A M S
then i have many chance, because just i need this code for XP nonce

the code is really one, if it was compatible with XP and next , it will be Excellent

Re: get ListNames of all applications there are in SysTray now
Posted: Sat Mar 04, 2023 7:06 pm
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.
Re: get ListNames of all applications there are in SysTray now
Posted: Sat Mar 04, 2023 8:33 pm
by Caronte3D
Maybe this thread help you:
viewtopic.php?t=80961
Re: get ListNames of all applications there are in SysTray now
Posted: Sat Mar 04, 2023 9:07 pm
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
Re: get ListNames of all applications there are in SysTray now
Posted: Sat Mar 04, 2023 9:09 pm
by netmaestro
The code has to be updated to work with Windows 7 and above. Looking at it now for an approach.