name of file.exe or showed name in title-bar is need
get ListNames of all applications there are in SysTray now
get ListNames of all applications there are in SysTray now
get names of all applications there are in SysTray now
name of file.exe or showed name in title-bar is need
name of file.exe or showed name in title-bar is need
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: get ListNames of all applications there are in SysTray now
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
Last edited by netmaestro on Mon Oct 12, 2009 4:37 am, edited 1 time in total.
BERESHEIT
Re: get ListNames of all applications there are in SysTray now
Thanks netmaestro, you save me
Re: get ListNames of all applications there are in SysTray now
> Well, if you're gonna get all shocked about it... how's this grab you?
Awesome!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: get ListNames of all applications there are in SysTray now
hmm - nothing in win7
cheers
cheers
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: get ListNames of all applications there are in SysTray now
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.
[Edit] Tested on XP and Vista, no problems.
BERESHEIT
Re: get ListNames of all applications there are in SysTray now
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.
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.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: get ListNames of all applications there are in SysTray now
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
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: get ListNames of all applications there are in SysTray now
For information...nothing too in W2000 
The happiness is a road...Not a destination
Re: get ListNames of all applications there are in SysTray now
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
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
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.
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
Maybe this thread help you:
viewtopic.php?t=80961
viewtopic.php?t=80961
Re: get ListNames of all applications there are in SysTray now
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
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.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: get ListNames of all applications there are in SysTray now
The code has to be updated to work with Windows 7 and above. Looking at it now for an approach.
BERESHEIT

