Enumerating Taskbar buttons?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Does anyone know a way to get a list, in order, of all the buttons in
the Windows Taskbar? I just need their caption text, in left-right
order. I've tried using FindWindowEx with the Taskbar's handle but
it doesn't work... and the following is supposed to show how many
buttons are in the Taskbar but it reports 0 all the time:

Code: Select all

hShellTray = FindWindow_("Shell_TrayWnd" , "")
hRebarWindow = FindWindowEx_(hShellTray, 0, "RebarWindow32" , "")
hTaskSwitch = FindWindowEx_(hRebarWindow, 0, "MSTaskSwWClass" , "")
hTaskbar = FindWindowEx_(hTaskSwitch, 0, "SysTabControl32" , "")
ItemCount = SendMessage_(hTaskBar, #TCM_GETITEMCOUNT, 0, 0)

PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

You need the tab control handle, wich is a child window of the tray window:

Code: Select all

procedure EnumChildProc(hwnd,lparam)
  shared htab
  cname$=space(255)
  GetClassName_(hwnd,@cname$,255)
  if cname$="SysTabControl32"
    htab=hwnd
    procedurereturn 0
  else
    procedurereturn 1
  endif
endprocedure

hShellTray=FindWindow_("Shell_TrayWnd",#null)
;find tab handle
EnumChildWindows_(hShellTray,@EnumChildProc(),0)

ItemCount=SendMessage_(htab, #TCM_GETITEMCOUNT, 0, 0)

messagerequester("",str(ItemCount),0)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Thanks Justin, but after some extensive web searching I came up with
the following, which has almost achieved my goal:

Code: Select all

taskbar=FindWindow_("Shell_TrayWnd","")
r=FindWindowEx_(taskbar,0,"MSTaskSwWClass","")
tc=FindWindowEx_(r,0,"SysTabControl32","")
i=SendMessage_(tc,#TCM_GETITEMCOUNT,0,0)
Debug Str(i)+" buttons on Taskbar:"
;
For r=1 To i
  a$=Space(255)
  SendMessage_(@tc,#TCM_GETITEM,r,a$)
  Debug Str(r)+" = "+a$
Next
Anyone know why I'm not getting the button captions?

UPDATE: Both Justin and my methods don't work with Win XP... :cry:
xgp
Enthusiast
Enthusiast
Posts: 128
Joined: Mon Jun 13, 2005 6:03 pm

Post by xgp »

Hi!
I've searched with all the words i can imagine to get an approach to this, but only found this as most close.

Just wanted to know if someone has an idea on how to archieve this ( listing tray icons ).

Bye!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Theoretically this should work, however it crashes explorer.exe here.

Code: Select all

hTaskbar = FindWindow_("Shell_TrayWnd", "")


hTray = FindWindowEx_(hTaskbar, 0, "TrayNotifyWnd", "")
hTray = FindWindowEx_(hTray, 0, "ToolbarWindow32", "")

; At this point, hTray contains the window handle of the
; system tray! It happens to be a toolbar (!)

;EnumChildWindows_(hTray, @EnumChildProc(), 0)

;Debug EasyClassName(hTray)

Debug "Number of icons:"
Debug SendMessage_(hTray, #TB_BUTTONCOUNT, 0, 0)
For I = 0 To SendMessage_(hTray, #TB_BUTTONCOUNT, 0, 0)
  Button.TBBUTTON
  Debug SendMessage_(hTray, #TB_GETBUTTON, I, @Button) ; explorer.exe crashes??
  Debug "Icon #" + Str(I)
  With Button
    Debug "   " + "iBitmap: " + Str( \iBitmap)
    Debug "   " + "iCommand: " + Str( \idCommand)
    Debug "   " + "fsState: " + Str( \fsState)
    Debug "   " + "fsStyle: " + Str( \fsStyle)
    Debug "   " + "dwData: " + Str( \dwData)
    Debug "   " + "iString: " + Str( \iString)
  EndWith
Next
xgp
Enthusiast
Enthusiast
Posts: 128
Joined: Mon Jun 13, 2005 6:03 pm

Post by xgp »

Thanks Trond!
Haven't tested it yet, but meanwhile, went searching a bit more and found this:
http://www.codeproject.com/tools/ShellTrayInfo.asp

Tested it, and at least the "get the number of buttons" worked.
But i think, this only works on XP, according to the web site.

Bye!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Mine also gets the correct number of icons before it crashes ;) It is supposed to work on XP and Windows 2000.
Post Reply