Author : Stevan Mitrovic
Date Submitted : 2/24/2005
Category : API Call
Compatibility : VB 6
This code has been accessed 9596 times.
Task : This code is designed to give you the position and text associated to each of the task tray icons.
Declarations
Code
Private Sub Command1_Click()
On Error Resume Next
Dim iTrayButtonsCount As Long
Dim hWndTray As Long
Dim hWndTray2 As Long
Dim hWndToolBar As Long
Dim iBtnIndex As Integer
Dim iTextLen As Integer
Dim lRet As Long
Dim Av() As Variant
Dim UID1 As UUID
Dim Ob As IAccessible
Dim lStart As Long
Dim LNum As Long
With UID1
.Data1 = &H618736E0
.Data2 = &H3C3D
.Data3 = &H11CF
.Data4(0) = &H81
.Data4(1) = &HC
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H38
.Data4(6) = &H9B
.Data4(7) = &H71
End With
List1.Clear
hWndTray = FindWindow("Shell_TrayWnd", vbNullString)
hWndTray2 = FindWindowEx(hWndTray, 0, "TrayNotifyWnd", vbNullString)
hWndToolBar = FindWindowEx(hWndTray2, 0, "ToolbarWindow32", vbNullString)
If hWndToolBar Then
lRet = AccessibleObjectFromWindow(ByVal hWndToolBar, OBJID_CLIENT, UID1, Ob)
iTrayButtonsCount = SendMessage(hWndToolBar, TB_BUTTONCOUNT, 0, 0)
Text1.Text = Str(iTrayButtonsCount)
LNum = Ob.accChildCount
ReDim Av(0 To LNum) As Variant
lRet = AccessibleChildren(Ob, lStart, LNum, Av(0), LNumRet)
For iBtnIndex = 0 To iTrayButtonsCount
'Getting the text length.
iTextLen = SendMessage(hWndToolBar, TB_GETBUTTONTEXTW, iBtnIndex, 0)
If iTextLen >= 0 Then List1.AddItem Str(iBtnIndex) & " - " & Str(iTextLen) & vbTab & " - " & Ob.accName(Av(iBtnIndex))
Next iBtnIndex
Set Ob = Nothing
End If
End Sub