Reprinted: How to traverse the icons on the taskbar

Source: Internet
Author: User

'This Code is designed to give you the text associated to each of the task tray icons.
'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
'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 shoshould 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
'"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_setconsumer id = (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
Private const objid_hscroll = & hfffffffa
Private const objid_sizegrip = & hfffffff9
Private const objid_caret = & hfffffff8
Private const objid_cursor = & hfffffff7
Private const objid_alert = & hfffffff6
Private const objid_sound = & hfffffff5
Private const objid_queryclassnameidx = & hfffffff4
Private const objid_nativeom = & hfffffff0

Private type tbbutton
Ibitmap as long
Idcommand as long
Fsstate as byte
Fsstyle as byte
Breserved1 as byte
Breserved2 as byte
Dwdata as long
Istring as long
End type

Private type UUID
Data1 as long
Data2 as integer
Data3 as integer
Data4 (0 to 7) as byte
End type

'Winapi declarations
Private declare sub copymemory lib "Kernel32" alias "rtlmovememory" (pdst as any, psrc as any, byval bytelen as long)
Private declare function sendmessage lib "USER32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
Private declare function findwindow lib "USER32" alias "find0000wa" (byval lpclassname as string, byval lpwindowname as string) as long
Private declare function find1_wex lib "USER32" alias "find1_wexa" (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as long

'Active accessibility declarations
Private declare function accessibleobjectfromwindow lib "oleacc" (byval hwnd as long, byval dwid as long, riid as UUID, ppvobject as object) as long
Private declare function accessiblechildren lib "oleacc" (byval pacccontainer as iaccessible, byval ichildstart as long, byval cChildren as long, rgvarchil1_as variant, pcobtained as long) as long
Private declare function getroletext lib "oleacc" alias "getroletexta" (byval dwrole as long, byval szrle as string, byval cchrolemax as integer) as long
Private declare function getstatetext lib "oleacc" alias "getstatetexta" (byval dwstatebit as long, byval szstate as string, byval cchstatebitmax as integer) as long

Private sub commandementclick ()

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

List1.clear

Hwndtray = findwindow ("shell_traywnd", vbnullstring)
Hwndtray2 = find1_wex (hwndtray, 0, "traypolicywnd", vbnullstring)
Hwndtoolbar = find1_wex (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

Original connection: http://www.vbcode.com/Asp/showsn.asp? Theid = 11610.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.