name of file.exe or showed name in title-bar is need

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