Jump to content

Get text from specific toolbar tray icon.


Recommended Posts

#Include <GuiToolBar.au3>

; Get handle of taskbar



$hWnd = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32;INSTANCE:1]") ; <<<<< If it does not work check the INSTANCE
; Get number of buttons
$iCount = _GUICtrlToolbar_ButtonCount($hWnd)
; Loop through buttons
For $i = 1 To $iCount - 1 Step 1 ; <<<<< You may need single step
    $iCmdID = _GUICtrlToolbar_IndexToCommand($hWnd, $i)
    $sText = _GUICtrlToolbar_GetButtonText($hWnd, $iCmdID)
    ConsoleWrite($sText & @CRLF)
 Next

$string = $sText
$searchstring1 = "Desktop 1"

If StringInStr($string, $searchstring1) Then
   Msgbox(0,"","OK")
EndIf

This script get text from toolbars on tray, and this is what the script write on console:

image.png.a5833fe615d0afa772ad9a9fb96958ea.png

Im trying read just the message "Desktop 1", so i did:

$string = $sText
$searchstring1 = "Desktop 1"

If StringInStr($string, $searchstring1) Then
   Msgbox(0,"","OK")
EndIf

But this is what $sText is storing:

image.png.c61a37abdae9c747fadb3969f3f59db2.png

I need read just that tray, with icon 1, but each time new tray icon is opened or pc is restarted, it changes her oder in the taskbar, and values index and command id changes;

image.png.c8297c7b827329503a9df3bac2a2d7ed.png

How i could store all results in different strings ? If so i could compare all they using StringinStr.

 

Edited by c7aesa7r
Link to comment
Share on other sites

You could store them in the array or check during the loop example of both:

#include <Array.au3>
#include <GuiToolBar.au3>
Global $g_aTaskBar[0]
Global $g_iInstance = 1
Global $g_hWnd, $g_iCount, $g_iCmdID, $g_iSearch, $g_sSearch = "Desktop 1"
While 1
    $g_hWnd = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "[CLASS:ToolbarWindow32;INSTANCE:" & $g_iInstance& "]") ; <<<<< If it does not work check the INSTANCE
    ;~ Get number of buttons
    $g_iCount = _GUICtrlToolbar_ButtonCount($g_hWnd)
        If $g_iCount > 1 Then ExitLoop
    $g_iInstance += 1
WEnd
;~ Loop through buttons
For $i = 1 To $g_iCount
    $g_iCmdID = _GUICtrlToolbar_IndexToCommand($g_hWnd, $i)
    ;~ Check during the loop
    If StringInStr(_GUICtrlToolbar_GetButtonText($g_hWnd, $g_iCmdID), $g_sSearch) Then Exit MsgBox(4096, "Success", "Item found" & @CRLF & "Index: " & $g_iCmdID & @CRLF & "Array Item: " & _GUICtrlToolbar_GetButtonText($g_hWnd, $g_iCmdID))
    ;~ Add the item to an array
    _ArrayAdd($g_aTaskBar, _GUICtrlToolbar_GetButtonText($g_hWnd, $g_iCmdID))
Next

_ArrayDisplay($g_aTaskBar)
$g_iSearch = _ArraySearch($g_aTaskBar,$g_sSearch)
    If @error Then Exit MsgBox(4096, "Failure", "Unable to find Desktop 1")
Msgbox(4096,"Success","Item found" & @CRLF & "Array Index: " & $g_iSearch & @CRLF & "Array Item: " & $g_aTaskBar[$g_iSearch])

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...