Jump to content
Sign in to follow this  

WinExists is nice... is there a ControlExists somewhere?

Recommended Posts

G'day everyone

Well, no, there isn't a "ControlExists", but can one mimick such an action fairly easily?

See, I need to navigate down a tree view and take screenshots of the leaf nodes. The nodes themselves do not have unique names in the Window Spy, so I have to rely on other methods to tell the script that a downarrow-movement has reached a leaf node. Fortunately, at every leaf node, there is a control (a button) present in the window which is not present when the focus is on a non-leaf item. Now I had wished that I could have told the script to press downarrow until ControlExists... but can you think of any other method which might do the trick?

Attached are two screenshots of the tree view.

I can also not find any way to determine how many leaf nodes exist in the tree (except counting them by hand), but if I could use ControlExists, then I could tell the script that the end of the tree has been reached if the control keeps on "existing" even though the downarrow is being pressed... because in the tree, the leaf nodes never follow each other directly (there is always at least one (sometimes two) non-leaf between the leaf nodes).

Thanks in advance


Share this post

Link to post
Share on other sites

O, wait, I can easily determine the end of the end of the tree, because the last node always contains the visible window text "version info". But I would still have to figure out a way to know when to take the screenshots (and I don't want to take screenshots of everything).

Share this post

Link to post
Share on other sites

Decided to make a _ControlExists() UDF...

Opt('WinTitleMatchMode', 4)
If _ControlExists('classname=SciTEWindow', '', 'Scintilla2') Then MsgBox(64, 'Info:', 'Control exist')
If Not _ControlExists('classname=SciTEWindow', '', 'Something') Then MsgBox(64, 'Info:', 'Control does not exist')

Func _ControlExists($hWin, $sText = '', $hCID = '')
    If $hCID = '' Then Return SetError(1, 0, 0)
    If IsString($hWin) Then $hWin = WinGetHandle($hWin)
    $hCID = ControlGetHandle($hWin, '', $hCID)
    If $hCID = '' Then SetError(2, 0, 0)
    Local $hCtrlWnd, $sClassList = WinGetClassList($hWin)
    Local $sSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF)
    For $iCount = UBound($sSplitClass) - 1 To 1 Step - 1
        Local $nCount = 0
        While 1
            $nCount += 1
            $hCtrlWnd = ControlGetHandle($hWin, '', $sSplitClass[$iCount] & $nCount)
            If $hCtrlWnd = '' Then ExitLoop
            If $hCID = $hCtrlWnd Then Return 1
    Return SetError(3, 0, 0)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post

Link to post
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
Sign in to follow this  

  • Create New...