Jump to content

TreeView issues help needed

Recommended Posts

Hi Guys.

Im trying to automate a piece of software we use here, its called window designer,

Basically trying to automate some of the more labor intensive tasks that we do.importing exporting etc,

Basically i need to click an item in the tree then change the highlighted item in the tab on the left


here's my testing code as you can see from the commented out commands ive tried a few options.

#include <Constants.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <GuiTreeView.au3>
#include <GuiTab.au3>

Opt("WinTitleMatchMode", 2)
Opt("GUIDataSeparatorChar", ",")
;Global $sValue = InputBox("Matlist Extraction", "enter the name of the mat list", "", " M")
Global $sValue = "GB70"
Global $format = 1
Global $hWnd = ControlGetHandle("[CLASS:TEditMaterialsForm;TITLE:Edit Materials - " & $sValue & ".MAT]", "", "[CLASS:TTreeView; INSTANCE:1]")
$hWnd_Tab = ControlGetHandle("[CLASS:TEditMaterialsForm;TITLE:Edit Materials - " & $sValue & ".MAT]", "", "[CLASS:TPageControl; INSTANCE:2]")
$searchText = "*** White"

$hItemFound = _GUICtrlTreeView_FindItem($hWnd, $searchText, True)
$name = _GUICtrlTreeView_GetText($hWnd, $hItemFound)
$BranchName = $name
$countmain = _GUICtrlTreeView_GetSiblingCount($hWnd, $hItemFound)
$count = _GUICtrlTreeView_GetChildCount($hWnd, 0)

For $j = 0 To $countmain - 1
    ConsoleWrite("Processing Branch:" & $BranchName & @LF)

    For $i = 0 To $count - 1
        $iOriginal = Opt("MouseCoordMode") ;Get the current MouseCoordMode
        $hItemFound = _GUICtrlTreeView_GetNextVisible($hWnd, $hItemFound)
        $name = _GUICtrlTreeView_GetText($hWnd, $hItemFound)
        ;_GUICtrlTreeView_SelectItem($hWnd, $hItemFound)
        ;_GUICtrlTreeView_SetState($hWnd, $hItemFound, $TVIS_SELECTED)
        ;_GUICtrlTreeView_SetFocused($hWnd, $hItemFound)
        ;_GUICtrlTreeView_BeginUpdate ( $hWnd )
        _GUICtrlTreeView_ClickItem($hWnd, $hItemFound)
        ;ControlTreeView("[CLASS:TEditMaterialsForm;TITLE:Edit Materials - " & $sValue & ".MAT]", "", $hWnd, "Select", "#" & $j & "|#" & $i)
        _GUICtrlTab_SetCurFocus($hWnd_Tab, 3)
        _GUICtrlTab_SetCurFocus($hWnd_Tab, 4)
        ConsoleWrite("#" & $j & "|#" & $i)
        If $i = 0 And $j = 0 Then
        ControlSend("[CLASS:TEditMaterialsForm;TITLE:Edit Materials - " & $sValue & ".MAT]", "", "[CLASS:TInfoComboBox; INSTANCE:1]", "Sacbolts x 2")
        $filename = $name
        ConsoleWrite($filename & @LF)
    $hItemFound = _GUICtrlTreeView_GetNextVisible($hWnd, $hItemFound)
    $count = _GUICtrlTreeView_GetChildCount($hWnd, $hItemFound)
    $name = _GUICtrlTreeView_GetText($hWnd, $hItemFound)
    $BranchName = $name


Problem i have is the software is not behaving as it should to any of the commandclick or treeview select commands.

the mouse click works but im trying to avoid using mouse or keyboard commands where i can

any suggestions??


Link to post
Share on other sites

Have you used the au3info tool to verify the control class?  Inspected your code closer.  Looks like the treeview class in the program you are working with is TTreeView.  I am not familiar with that class...so I think my next statement still stands.

I believe the _GUICtrlTreeView funcs only interact with SysTreeView32 controls.

Maybe someone else will chime in with an idea, but I'm at a loss.

Edited by spudw2k
Link to post
Share on other sites



Thanks for the reply heres the au3info summary.

>>>> Window <<<<
Title:  Edit Materials - GB70.MAT
Class:  TEditMaterialsForm
Position:   -8, 0
Size:   1936, 1080
Style:  0x16CF0000
ExStyle:    0x00010100
Handle: 0x0000000000090C18

>>>> Control <<<<
Class:  TTreeView
Instance:   1
ClassnameNN:    TTreeView1
Advanced (Class):   [CLASS:TTreeView; INSTANCE:1]
ID: 3607626
Position:   12, 51
Size:   313, 803
ControlClick Coords:    223, 124
Style:  0x54210027
ExStyle:    0x00000200
Handle: 0x0000000000370C4A

>>>> Mouse <<<<
Position:   239, 210
Cursor ID:  0
Color:  0x000000


the only issue i have is the clicking of the element at the moment, i think this is a funky issue with the program than with autoit.

for example every command you can see in the code in my first post works as i expected it to. selecting the element, reading the text etc all are fine.

when i click the element with the mouse it changes the data on the right hand side of the window so show data from that element, i cannot replicate this with any of the commands other than mouse click, is there any other commands that maybe worth a try?

thinking they might be using some weird way to detect the click

Works but uses the mouse

_GUICtrlTreeView_ClickItem($hWnd, $hItemFound,"left", False)

Selects item but doesnt update the info





Edited by SccSLtd
Link to post
Share on other sites

Ok, I misunderstood/understand better now. I would've thought that the _ClickItem func would work if the rest are working.  Very strange. 

Not sure how much of a difference it will make, but the _ClickItem func does allow a couple of optional parameters. One in particular is to move the mouse to the control.  I wonder if there is something special about the class that requires the mouse cursor to move on it.  By default, that optional param is False.  Might be worth trying to set it to true and see what happens if you haven't already.

_GUICtrlTreeView_ClickItem($hwnd, $hItemFound, "Left", True)


Link to post
Share on other sites


its a bit of a weird problem, this is the first time ive had issues with using autoit with any app.


the _GUICtrlTreeView_ClickItem command works perfectly. with false or true set.

there must be a difference that im not seeing between controlclick and the treview_cliclitem commands

was wondering if there was any other ways of clicking a control without using the mouse,

i would rather stick to working with the controls directly instead of using the mouse clicks so as not to be reliant on the mouse if possible


thanks again for the help


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...