Jump to content

Is there a way of finding the elements of a control?


Recommended Posts

do you mean the windows info tool that shows controls but no elements?!?

I wouldn't post here without searching and reading the help file first! :D

Basically, the window info tool gives me the class name, instance, text etc. But for example, in the image shown, the tool strip and the menu down the side, have 'elements' to them - the individual buttons or menu items. Each of these have roles, names etc.

From what I can see, there is no way of utilising these within AutoIt, but i figured that after viewing thes forums for a while now someone smater could give me a yes (and how to do it) or a no.

So erezlevi, i shall bite my tongue and not respond with any sort of arsey comment, as that helps no one. Maybe i should have clearly stated that I had a) read the help file, b.) read the forum, c) been using AutoIt for a little while now, d) now trying to use it to help with a new product in development that's slightly more complex than notepad!

Image:

Posted Image

Edited by testMunky
Link to comment
Share on other sites

at very least, a free bump until someone else notices

what class names are reported for menu and toolbar?

try adapting this with class name and text for your toolbar

comment out the run explorer line

From AutoLib3 by PaulIA - updated for v3.2.10.0

reads menu and toolbar information from an explorer window

returns index and command ids for buttons and state info

Note: toolbar separators have index values, show as blank button text

Edit: when updating from old function names I incorrectly named _GUICtrlMenuGetItemChecked() to _GUICtrlMenu_SetItemChecked()

guess I was too fast on the find replace or auto name completion in SciTE.

#include <GuiMenu.au3>
#include <GuiToolbar.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Opt("MustDeclareVars", 1)
; ===============================================================================
; Description ...: Toolbar test script
; Author ........: Paul Campbell (PaulIA)
; Notes .........: This script MUST be run in SciTE in order to see the results.
; ===============================================================================
; Global variables
; ===============================================================================
Global $hToolbar1, $hToolbar2, $aCommand1, $aCommand2
Global $gaPopups[1][3] = [[0, 0]]
; ===============================================================================
; Main
; ===============================================================================
Run("explorer.exe /root, ,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
WinWaitActive("[CLASS:CabinetWClass]")
$hToolbar1 = _GUICtrlToolbar_FindToolbar("[CLASS:CabinetWClass]", "&File")
$hToolbar2 = _GUICtrlToolbar_FindToolbar("[CLASS:CabinetWClass]", "Folders")
$aCommand1 = GetCommands($hToolbar1)
$aCommand2 = GetCommands($hToolbar1)

Test() ; performs a few tests on toolbar
ShowToolbar($hToolbar1) ; List explorer menu items
ShowToolbar($hToolbar2) ; List explorer toolbar buttons
ShowFavorites() ; List drop down menu items
; ===============================================================================
; Decode the global popup array and show the menu/toolbar details
; ===============================================================================
Func Decode()
    Local $iI, $iType
    Local $hMenu, $hParent

    For $iI = 1 To $gaPopups[0][0]
        $hMenu = _Lib_PopupGetHwnd($iI)
        $iType = _Lib_PopupGetType($iI)
        $hParent = _Lib_PopupGetParent($iI)
        Select
            Case $iType = 1
                ShowMenu($hMenu, $hParent)
            Case $iType = 2
                ShowToolbar($hMenu)
        EndSelect
    Next
EndFunc   ;==>Decode
; ===============================================================================
; Open the Favorites and list the contents
; ===============================================================================
Func GetCommands($hToolbar)
    Local $iI, $iCount
    $iCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    Local $aCommand[$iCount + 1]
    For $iI = 0 To $iCount - 1
        $aCommand[$iI] = _GUICtrlToolbar_IndexToCommand($hToolbar, $iI)
    Next
    Return $aCommand
EndFunc   ;==>GetCommands
; ===============================================================================
; Open the Favorites and list the contents
; ===============================================================================
Func ShowFavorites()
    _GUICtrlToolbar_ClickAccel($hToolbar1, "a", "left", False)
    _GUICtrlToolbar_ClickIndex(_Lib_PopupGetHwnd(), 0, "left", False)
    Decode()
    _Lib_PopupClose()
EndFunc   ;==>ShowFavorites
; ===============================================================================
; Show information about a menu item
; ===============================================================================
Func ShowMenu($hMenu, $hParent)
    Local $iI, $iCount, $sItem, $aRect
    $iCount = _GUICtrlMenu_GetItemCount($hMenu)
    ConsoleWrite("Parent handle .........: " & $hParent & @CRLF)
    ConsoleWrite("Menu handle ...........: " & $hMenu & @CRLF)
    ConsoleWrite("Menu item count .......: " & $iCount & @CRLF)
    ConsoleWrite(@CRLF)
    For $iI = 0 To $iCount - 1
        If $iI < 10 Then
            $sItem = "Item  " & $iI & " "
        Else
            $sItem = "Item " & $iI & " "
        EndIf
        $aRect = _GUICtrlMenu_GetItemRect($hParent, $hMenu, $iI)
        ConsoleWrite($sItem & "string ........: " & _
                _GUICtrlMenu_GetItemText($hMenu, $iI) & @CRLF)
        ConsoleWrite($sItem & "checked .......: " & _
                _GUICtrlMenu_GetItemChecked($hMenu, $iI) & @CRLF) ; was  _GUICtrlMenu_SetItemChecked()
        ConsoleWrite($sItem & "disabled ......: " & _
                _GUICtrlMenu_GetItemDisabled($hMenu, $iI) & @CRLF)
        ConsoleWrite($sItem & "grayed ........: " & _
                _GUICtrlMenu_GetItemGrayed($hMenu, $iI) & @CRLF)
        ConsoleWrite($sItem & "rectangle .....: [" & $aRect[1] & _
                ", " & $aRect[2] & ", " & $aRect[3] & ", " & $aRect[4] & "]" & @CRLF)
        ConsoleWrite(@CRLF)
    Next
EndFunc   ;==>ShowMenu
; ===============================================================================
; Show information about the toolbar and it's buttons
; ===============================================================================
Func ShowToolbar($hToolbar)
    Local $iCount, $iCommandID, $iIndex, $aMark, $aMetrics, $aRect, $aSize
    $iCount = _GUICtrlToolbar_ButtonCount($hToolbar)
    $aMark = _GUICtrlToolbar_GetInsertMark($hToolbar)
    $aMetrics = _GUICtrlToolbar_GetMetrics($hToolbar)
    $aSize = _GUICtrlToolbar_GetButtonSize($hToolbar)
    ConsoleWrite("Toolbar button count ..........: " & $iCount & @CRLF)
    ConsoleWrite("Toolbar anchor highlight ......: " & _
            _GUICtrlToolbar_GetAnchorHighlight($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar bitmap flags ..........: " & _
            _GUICtrlToolbar_GetBitmapFlags($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar button height .........: " & $aSize[0] & @CRLF)
    ConsoleWrite("Toolbar button width ..........: " & $aSize[1] & @CRLF)
    ConsoleWrite("Toolbar disabled image list ...: 0x" & _
            Hex(_GUICtrlToolbar_GetDisabledImageList($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar extended style ........: 0x" & _
            Hex(_GUICtrlToolbar_GetExtendedStyle($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar hot image list ........: 0x" & _
            Hex(_GUICtrlToolbar_GetHotImageList($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar hot item index ........: " & _
            _GUICtrlToolbar_GetHotItem($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar image list ............: 0x" & _
            Hex(_GUICtrlToolbar_GetImageList($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar insert mark: Color.....: 0x" & _
            Hex(_GUICtrlToolbar_GetInsertMarkColor($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar insert mark: Index ....: " & $aMark[0] & @CRLF)
    ConsoleWrite("Toolbar insert mark: Relate ...: " & $aMark[1] & @CRLF)
    ConsoleWrite("Toolbar metrics: Button X .....: " & $aMetrics[0] & @CRLF)
    ConsoleWrite("Toolbar metrics: Button Y .....: " & $aMetrics[1] & @CRLF)
    ConsoleWrite("Toolbar metrics: Space X ......: " & $aMetrics[2] & @CRLF)
    ConsoleWrite("Toolbar metrics: Space Y ......: " & $aMetrics[3] & @CRLF)
    ConsoleWrite("Toolbar rows ..................: " & _
            _GUICtrlToolbar_GetRows($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar style .................: 0x" & _
            Hex(_GUICtrlToolbar_GetStyle($hToolbar)) & @CRLF)
    ConsoleWrite("Toolbar text rows .............: " & _
            _GUICtrlToolbar_GetTextRows($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar tool tips .............: " & _
            _GUICtrlToolbar_GetToolTips($hToolbar) & @CRLF)
    ConsoleWrite("Toolbar unicode ...............: " & _
            _GUICtrlToolbar_GetUnicodeFormat($hToolbar) & @CRLF)
    ConsoleWrite(@CRLF)
    For $iIndex = 0 To $iCount - 1
        $iCommandID = _GUICtrlToolbar_IndexToCommand($hToolbar, $iIndex)
        $aRect = _GUICtrlToolbar_GetButtonRect($hToolbar, $iCommandID)
        ConsoleWrite("Button index ..................: " & $iIndex & @CRLF)
        ConsoleWrite("Button command ID .............: " & $iCommandID & @CRLF)
        ConsoleWrite("Button bitmap index ...........: " & _
                _GUICtrlToolbar_GetButtonBitmap($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button param ..................: " & _
                _GUICtrlToolbar_GetButtonParam($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state ..................: " & _
                _GUICtrlToolbar_GetButtonState($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: checked .........: " & _
                _GUICtrlToolbar_IsButtonChecked($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: enabled .........: " & _
                _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: hidden ..........: " & _
                _GUICtrlToolbar_IsButtonHidden($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: highlighted .....: " & _
                _GUICtrlToolbar_IsButtonHighlighted($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: indeterminate ...: " & _
                _GUICtrlToolbar_IsButtonIndeterminate($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button state: pressed .........: " & _
                _GUICtrlToolbar_IsButtonPressed($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button style ..................: " & _
                _GUICtrlToolbar_GetButtonStyle($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite("Button rectangle ..............: [" & _
                $aRect[0] & ", " & $aRect[1] & ", " & $aRect[2] & ", " & $aRect[3] & "]" & @CRLF)
        ConsoleWrite("Button text ...................: " & _
                _GUICtrlToolbar_GetButtonText($hToolbar, $iCommandID) & @CRLF)
        ConsoleWrite(@CRLF)
    Next
EndFunc   ;==>ShowToolbar
; ===============================================================================
; Tests
; ===============================================================================
Func Test()
    Local $aMark
    $aMark = _GUICtrlToolbar_InsertMarkHitTest($hToolbar1, 32, 0)
    ConsoleWrite("Add string ....................: " & _
            _GUICtrlToolbar_AddString($hToolbar1, "Auto3Lib") & @CRLF)
    ConsoleWrite("Auto size .....................: " & _
            _GUICtrlToolbar_AutoSize($hToolbar1) & @CRLF);_SendMessage($hToolbar1, $TB_AUTOSIZE)
    ;  ConsoleWrite("Delete button .................: "  & _
    ; _GUICtrlToolbar_DeleteButton  ($hToolbar1, 5) & @CRLF)
    ConsoleWrite("Enable button (False) .........: " & _
            _GUICtrlToolbar_EnableButton($hToolbar1, 4, False) & @CRLF)
    ConsoleWrite("Get string ....................: " & _
            _GUICtrlToolbar_GetString($hToolbar1, 0) & @CRLF)
    ;  ConsoleWrite("Hide button ...................: "  & _
    ; _GUICtrlToolbar_HideButton    ($hToolbar1, $aCommand1[5]) & @CRLF)
    ConsoleWrite("Hit test ......................: " & _
            _GUICtrlToolbar_HitTest($hToolbar1, 32, 0) & @CRLF)
    ConsoleWrite("Insert button .................: " & _
            _GUICtrlToolbar_InsertButton($hToolbar1, 6, 0, 0, "Auto3Lib") & @CRLF)
    ConsoleWrite("Insert mark test: Index .......: " & $aMark[0] & @CRLF)
    ConsoleWrite("Insert mark test: Relate ......: " & $aMark[1] & @CRLF)
    ConsoleWrite("Map accelerator (F) ...........: " & _
            _GUICtrlToolbar_MapAccelerator($hToolbar1, "F") & @CRLF)
    ConsoleWrite("Move button (0 to 1) ..........: " & _
            _GUICtrlToolbar_MoveButton($hToolbar1, 0, 1) & @CRLF)
    ConsoleWrite(@CRLF)
EndFunc   ;==>Test

Func _Lib_PopupClose()
    While 1
        _Lib_PopupScan()
        If $gaPopups[0][0] = 0 Then Return
        _Lib_Send("{ESC}")
    WEnd
EndFunc   ;==>_Lib_PopupClose

Func _Lib_PopupGetHwnd($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][0]
EndFunc   ;==>_Lib_PopupGetHwnd

Func _Lib_PopupGetParent($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][2]
EndFunc   ;==>_Lib_PopupGetParent

Func _Lib_PopupGetType($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][1]
EndFunc   ;==>_Lib_PopupGetType

Func _Lib_PopupScan()
    Local $iI, $sClass, $hWnd, $hMenu
    ReDim $gaPopups[1][3]
    $gaPopups[0][0] = 0
    ReDim $winapi_gaWinList[64][2]
    $winapi_gaWinList[0][0] = 0
    $winapi_gaWinList[0][1] = 64
    _WinAPI_EnumWindowsPopup()
    For $iI = 1 To $winapi_gaWinList[0][0]
        $hWnd = $winapi_gaWinList[$iI][0]
        $sClass = $winapi_gaWinList[$iI][1]
        Select
            Case $sClass = "#32768"
                $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
                _Lib_PopupAdd($hMenu, 1, $hWnd)
            Case $sClass = "ToolbarWindow32"
                _Lib_PopupAdd($hWnd, 2, _WinAPI_GetParent($hWnd))
            Case $sClass = "ToolTips_Class32"
                _Lib_PopupAdd($hWnd, 3, _WinAPI_GetParent($hWnd))
        EndSelect
    Next
EndFunc   ;==>_Lib_PopupScan

Func _Lib_PopupWait()
    Local $iLoop = 0
    While $iLoop < 50
        If $gaPopups[0][0] > 0 Then Return
        Sleep(100)
        _Lib_PopupScan()
        $iLoop += 1
    WEnd
    ConsoleWrite("Timeout waiting for popup window to appear" & @CRLF)
EndFunc   ;==>_Lib_PopupWait

Func _Lib_Send($sKeys, $iDelay = 10, $iFlag = 0)
    Send($sKeys, $iFlag)
    Sleep($iDelay)
EndFunc   ;==>_Lib_Send

Func _Lib_PopupAdd($hWnd, $iType, $hParent)
    Local $iCount
    $gaPopups[0][0] += 1
    $iCount = $gaPopups[0][0]
    ReDim $gaPopups[$iCount + 1][3]
    $gaPopups[$iCount][0] = $hWnd
    $gaPopups[$iCount][1] = $iType
    $gaPopups[$iCount][2] = $hParent
EndFunc   ;==>_Lib_PopupAdd
Edited by rover

I see fascists...

Link to comment
Share on other sites

Thanks rover, i'll have a bash about with that later and see what it does.

Edit: Still looking...have a report to write on automation and test tools :D and my other harness to fix yet. But ran the script quickly and it gave a couple of errors regarding missing stuff.

Anyhow.... found a solution posted (originally started Dec'07) here:

Edited by testMunky
Link to comment
Share on other sites

Edit: ..ran the script quickly and it gave a couple of errors regarding missing stuff.

Anyhow.... found a solution posted (originally started Dec'07) here:

sorry about that, I'm running 3.2.11.0 beta (production still v3.2.8.1 for the moment on machine I updated that script on)

3.2.10.0 on other machine so I missed that problem

hopefully your toolbars and menu are not custom controls.

I see fascists...

Link to comment
Share on other sites

hopefully your toolbars and menu are not custom controls.

No problem. Well this is what I feared.

..had a quick run through, and got nothing! it may be something i've done but i'm thinking not. Our developers are using Infragistics controls and it's causing me all sorts of problems creating tools for the test team! :D

I'll take another look tomorrow, but i'm gonna guess that it's probably not possible to do :P

Edited by testMunky
Link to comment
Share on other sites

UPDATE:Haven't got around to checking this out properly due to having to look at another tool :) but not holding out any hope as our dev's are using Infragistics controls. :)

Has anyone had any luck at automating infragistics (3rd party .Net) controls? I can't see a way around it at present and the only way i'm thinking at the moment is to use AutoItX with my harness that im building (using C#). Oh well!

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...