Jump to content

Read and match words in app screen


ardeshir
 Share

Recommended Posts

Hello All.

I am a new bee in this. do have some programing experience. My goal is to automate an export function in a third party application. I have done most of what i need to do. there is one part that is giving me a hard time.

The third party application has a win explorer style look. I need to be able to read the name of the file so i can highlight and right click to export. the right click and export are not an issue, I am stuck on how to read the file name and pass it to get highlighted, I thought I probably need to use some kind of loop and regular expression and once match high light and run the export move. keep in mind that the files always change as new ones get added to the directory. any help is appreciated...

post-61460-0-41842300-1290626623_thumb.j

Link to comment
Share on other sites

If that control class is SysTreeView32 you'll be able to use the _GUICtrlTreeView UDF.

Could you use AU3Info from the tools menu of SciTE to check what the controls class is?

(If you don't have the version of SciTE with the extra tools run AU3Info.exe from the autoit installation dir.

Link to comment
Share on other sites

If that control class is SysTreeView32 you'll be able to use the _GUICtrlTreeView UDF.

Could you use AU3Info from the tools menu of SciTE to check what the controls class is?

(If you don't have the version of SciTE with the extra tools run AU3Info.exe from the autoit installation dir.

The Control is [CLASS:SysTreeView32;INSTANCE:1]. I couldn't find any help on _GUICtrlTreeView. is that a bultin function. under what topic I can find this in the help files......
Link to comment
Share on other sites

It's a UDF function so you have to look in the UDF help file.

Thanks for your help, But I still haven't been able to find any reference to exploring the tree.

Most of the stuff I see in the help file is related to IE web browser, I don't see any reference to any control for TreeView(Explorer). do you know of a key word other than UDF that I can use to search or if you know the control name that would help too. .....CtrlTreeView also is not returning anything.......

Link to comment
Share on other sites

_GUICtrlTreeView_GetFirstItem() and _GUICtrlTreeView_GetNext() can be used to iterate through each item from first to last. Giving you a basic way of exploring the treeview. Related functions can be used to expand on that.

Finding an item in a treeview is simplified by the _GUICtrlTreeView_FindItem and _GUICtrlTreeView_FindItemEx functions that have the treeview exploration build in, however both functions appear to be pretty slow for larger treeviews, especially to find items near the bottom of the control.

I think _GUICtrlTreeView_FindIteEx can be modified for greater speed, but here is an example of how you can can use the functions:

Old, slow script using the UDF function. faster, modified version below.

#include <GuiTreeView.au3>
Global $hWnd, $hCtrl, $hItem
Global $sWndIdentify = "Test GUI" ;replace with something to identify your window.
Global $sCtrlIdentify = "[CLASS:SysTreeView32; INSTANCE:1]" ;identifyer for the control.
Global $sItemIdentify = "File_1" ;text of the item you want to select

$hWnd = WinGetHandle($sWndIdentify) ;get the handle of the window.
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching window found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching window with handle: " & $hWnd & @CRLF)


$hCtrl = ControlGetHandle($hWnd,"",$sCtrlIdentify) ;get the handle of the control
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching control found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching control with handle: " & $hCtrl & @CRLF)

$hItem = _GUICtrlTreeView_FindItem($hCtrl,$sItemIdentify) ;get the handle of the item
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching item found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching item with handle: " & $hItem & @CRLF)

_GUICtrlTreeView_EnsureVisible($hCtrl,$hItem) ;scroll and expand the treeview if needed to get the item visible
_GUICtrlTreeView_ClickItem($hCtrl,$hItem) ;click the item.

Edit: Well that was easy. Seems like the slow functions spend most of their time calling __GUICtrlTreeView_ExpandItem, which in my test case didn't even do anything. I might have introduced a bug, but the speed of the function has improved a lot.

#include <GuiTreeView.au3>
Global $hWnd, $hCtrl, $hItem
Global $sWndIdentify = "Test GUI" ;replace with something to identify your window.
Global $sCtrlIdentify = "[CLASS:SysTreeView32; INSTANCE:1]" ;identifyer for the control.
Global $sItemIdentify = "Home|Dir_1|Sub_Dir_2|File_1" ;path of the item you want to select

$hWnd = WinGetHandle($sWndIdentify) ;get the handle of the window.
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching window found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching window with handle: " & $hWnd & @CRLF)


$hCtrl = ControlGetHandle($hWnd,"",$sCtrlIdentify) ;get the handle of the control
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching control found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching control with handle: " & $hCtrl & @CRLF)

$hItem = _GUICtrlTreeView_FindItemExFast($hCtrl,$sItemIdentify) ;get the handle of the item
If @error Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - No matching item found" & @CRLF)
    Exit
EndIf
ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC & " - Matching item with handle: " & $hItem & @CRLF)

_GUICtrlTreeView_EnsureVisible($hCtrl,$hItem) ;scroll and expand the treeview if needed to get the item visible
_GUICtrlTreeView_SelectItem($hCtrl,$hItem) ;select the item.


;same as _GUICtrlTreeView_FindItemEx, but with 2 lines commented out for speed.
Func _GUICtrlTreeView_FindItemExFast($hWnd, $sPath, $hStart = 0)
    Local $sDelimiter = Opt("GUIDataSeparatorChar")

    Local $iIndex = 1
    Local $aParts = StringSplit($sPath, $sDelimiter)
    If $hStart = 0 Then $hStart = _GUICtrlTreeView_GetFirstItem($hWnd)
    While ($iIndex <= $aParts[0]) And ($hStart <> 0x00000000)
        If StringStripWS(_GUICtrlTreeView_GetText($hWnd, $hStart), 3) = StringStripWS($aParts[$iIndex], 3) Then
            If $iIndex = $aParts[0] Then Return $hStart
            $iIndex += 1
;~          This function slows the process down by a lot. I'm sure there is a reason why it's in there, but it seems like there should at least be a flag to disable it.
;~          (perhaps the underlying controls might not exist untill they parent item is expanded for certain treeviews?)
;~          __GUICtrlTreeView_ExpandItem($hWnd, $TVE_EXPAND, $hStart)
            $hStart = _GUICtrlTreeView_GetFirstChild($hWnd, $hStart)
        Else
            $hStart = _GUICtrlTreeView_GetNextSibling($hWnd, $hStart)
;~          Same as above.
;~          __GUICtrlTreeView_ExpandItem($hWnd, $TVE_COLLAPSE, $hStart)
        EndIf
    WEnd
    Return $hStart
EndFunc   ;==>_GUICtrlTreeView_FindItemExFast
Edited by Tvern
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...