VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code is designed to give you the position and text associated to each of the task tray icons.

by Stevan Mitrovic (2 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 24th February 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code is designed to give you the position and text associated to each of the task tray icons.

API Declarations


'Created by Stevan Mitrovic.

'First you will need to add a reference to the project. So click on "Project"
'in the menu and select "References..." from the drop dowm list. Once the
'references dialog box pops up, click on the "Browse.." button. A "Add Reference"
'dialog box will pop up. Goto your system32 folder and find "oleacc.dll", select
'it and then press the open button. You should now see a checked off "Accessibility"
'in the list. Click on the "OK" button and your ready to go.

'The next things you'll need to add, are to your form. You will need a
'"Command button" (Command1), a "Label" (Label1), a "textbox" (Text1) and
'a "Listbox" (List1). Now cut and paste the following code into your Form1
'and run it.


'Region Toolbar button styles
Private Const TBSTYLE_BUTTON = &H0
Private Const TBSTYLE_SEP = &H1
Private Const TBSTYLE_CHECK = &H2
Private Const TBSTYLE_GROUP = &H4
Private Const TBSTYLE_CHECKGROUP = (TBSTYLE_GROUP Or TBSTYLE_CHECK)
Private Const TBSTYLE_DROPDOWN = &H8
Private Const TBSTYLE_AUTOSIZE = &H10
Private Const TBSTYLE_NOPREFIX = &H20
Private Const TBSTYLE_TOOLTIPS = &H100
Private Const TBSTYLE_WRAPABLE = &H200
Private Const TBSTYLE_ALTDRAG = &H400
Private Const TBSTYLE_FLAT = &H800
Private Const TBSTYLE_LIST = &H1000
Private Const TBSTYLE_CUSTOMERASE = &H2000
Private Const TBSTYLE_REGISTERDROP = &H4000
Private Const TBSTYLE_TRANSPARENT = &H8000&
Private Const TBSTYLE_DRAWDDARROWS = &H1




Private Const WM_USER = &H400&
'Region ToolBar Messages
Private Const TB_ENABLEBUTTON = (WM_USER + 1)
Private Const TB_CHECKBUTTON = (WM_USER + 2)
Private Const TB_PRESSBUTTON = (WM_USER + 3)
Private Const TB_HIDEBUTTON = (WM_USER + 4)
Private Const TB_INDETERMINATE = (WM_USER + 5)
Private Const TB_MARKBUTTON = (WM_USER + 6)
Private Const TB_ISBUTTONENABLED = (WM_USER + 9)
Private Const TB_ISBUTTONCHECKED = (WM_USER + 10)
Private Const TB_ISBUTTONPRESSED = (WM_USER + 11)
Private Const TB_ISBUTTONHIDDEN = (WM_USER + 12)
Private Const TB_ISBUTTONINDETERMINATE = (WM_USER + 13)
Private Const TB_ISBUTTONHIGHLIGHTED = (WM_USER + 14)
Private Const TB_SETSTATE = (WM_USER + 17)
Private Const TB_GETSTATE = (WM_USER + 18)
Private Const TB_ADDBITMAP = (WM_USER + 19)
Private Const TB_ADDBUTTONSA = (WM_USER + 20)
Private Const TB_INSERTBUTTONA = (WM_USER + 21)
Private Const TB_ADDBUTTONS = (WM_USER + 20)
Private Const TB_INSERTBUTTON = (WM_USER + 21)
Private Const TB_DELETEBUTTON = (WM_USER + 22)
Private Const TB_GETBUTTON = (WM_USER + 23)
Private Const TB_BUTTONCOUNT = (WM_USER + 24)
Private Const TB_COMMANDTOINDEX = (WM_USER + 25)
Private Const TB_SAVERESTOREA = (WM_USER + 26)
Private Const TB_CUSTOMIZE = (WM_USER + 27)
Private Const TB_ADDSTRINGA = (WM_USER + 28)
Private Const TB_GETITEMRECT = (WM_USER + 29)
Private Const TB_BUTTONSTRUCTSIZE = (WM_USER + 30)
Private Const TB_SETBUTTONSIZE = (WM_USER + 31)
Private Const TB_SETBITMAPSIZE = (WM_USER + 32)
Private Const TB_AUTOSIZE = (WM_USER + 33)
Private Const TB_GETTOOLTIPS = (WM_USER + 35)
Private Const TB_SETTOOLTIPS = (WM_USER + 36)
Private Const TB_SETPARENT = (WM_USER + 37)
Private Const TB_SETROWS = (WM_USER + 39)
Private Const TB_GETROWS = (WM_USER + 40)
Private Const TB_GETBITMAPFLAGS = (WM_USER + 41)
Private Const TB_SETCMDID = (WM_USER + 42)
Private Const TB_CHANGEBITMAP = (WM_USER + 43)
Private Const TB_GETBITMAP = (WM_USER + 44)
Private Const TB_GETBUTTONTEXTA = (WM_USER + 45)
Private Const TB_REPLACEBITMAP = (WM_USER + 46)
Private Const TB_SETINDENT = (WM_USER + 47)
Private Const TB_SETIMAGELIST = (WM_USER + 48)
Private Const TB_GETIMAGELIST = (WM_USER + 49)
Private Const TB_LOADIMAGES = (WM_USER + 50)
Private Const TB_GETRECT = (WM_USER + 51)
Private Const TB_SETHOTIMAGELIST = (WM_USER + 52)
Private Const TB_GETHOTIMAGELIST = (WM_USER + 53)
Private Const TB_SETDISABLEDIMAGELIST = (WM_USER + 54)
Private Const TB_GETDISABLEDIMAGELIST = (WM_USER + 55)
Private Const TB_SETSTYLE = (WM_USER + 56)
Private Const TB_GETSTYLE = (WM_USER + 57)
Private Const TB_GETBUTTONSIZE = (WM_USER + 58)
Private Const TB_SETBUTTONWIDTH = (WM_USER + 59)
Private Const TB_SETMAXTEXTROWS = (WM_USER + 60)
Private Const TB_GETTEXTROWS = (WM_USER + 61)
Private Const TB_GETOBJECT = (WM_USER + 62)
Private Const TB_GETBUTTONINFOW = (WM_USER + 63)
Private Const TB_SETBUTTONINFOW = (WM_USER + 64)
Private Const TB_GETBUTTONINFOA = (WM_USER + 65)
Private Const TB_SETBUTTONINFOA = (WM_USER + 66)
Private Const TB_INSERTBUTTONW = (WM_USER + 67)
Private Const TB_ADDBUTTONSW = (WM_USER + 68)
Private Const TB_HITTEST = (WM_USER + 69)
Private Const TB_SETDRAWTEXTFLAGS = (WM_USER + 70)
Private Const TB_GETHOTITEM = (WM_USER + 71)
Private Const TB_SETHOTITEM = (WM_USER + 72)
Private Const TB_SETANCHORHIGHLIGHT = (WM_USER + 73)
Private Const TB_GETANCHORHIGHLIGHT = (WM_USER + 74)
Private Const TB_GETBUTTONTEXTW = (WM_USER + 75)
Private Const TB_SAVERESTOREW = (WM_USER + 76)
Private Const TB_ADDSTRINGW = (WM_USER + 77)
Private Const TB_MAPACCELERATORA = (WM_USER + 78)
Private Const TB_GETINSERTMARK = (WM_USER + 79)
Private Const TB_SETINSERTMARK = (WM_USER + 80)
Private Const TB_INSERTMARKHITTEST = (WM_USER + 81)
Private Const TB_MOVEBUTTON = (WM_USER + 82)
Private Const TB_GETMAXSIZE = (WM_USER + 83)
Private Const TB_SETEXTENDEDSTYLE = (WM_USER + 84)
Private Const TB_GETEXTENDEDSTYLE = (WM_USER + 85)
Private Const TB_GETPADDING = (WM_USER + 86)
Private Const TB_SETPADDING = (WM_USER + 87)
Private Const TB_SETINSERTMARKCOLOR = (WM_USER + 88)
Private Const TB_GETINSERTMARKCOLOR = (WM_USER + 89)
Private Const TB_GETSTRINGW = (WM_USER + 91)
Private Const TB_GETSTRINGA = (WM_USER + 92)


' Reserved IDs for system objects
Private Const OBJID_WINDOW = &H0&
Private Const OBJID_SYSMENU = &HFFFFFFFF
Private Const OBJID_TITLEBAR = &HFFFFFFFE
Private Const OBJID_MENU = &HFFFFFFFD
Private Const OBJID_CLIENT = &HFFFFFFFC
Private Const OBJID_VSCROLL = &HFFFFFFFB

Rate This code is designed to give you the position and text associated to each of the task tray icons.




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

Download this snippet    Add to My Saved Code

This code is designed to give you the position and text associated to each of the task tray icons. Comments

No comments have been posted about This code is designed to give you the position and text associated to each of the task tray icons.. Why not be the first to post a comment about This code is designed to give you the position and text associated to each of the task tray icons..

Post your comment

Subject:
Message:
0/1000 characters