tremolux66

[solved] Unable to check SysTreeView32 item's checkbox using ControlTreeView()

2 posts in this topic

#1 ·  Posted (edited)

I'm automating a commercial app that will copy files/folders from an optical disc to a folder on a hard drive, and am unable to check an item in a SysTreeView32 control in the app's main window. The disc and its top-level folders are displayed as a simple tree, and I've written a test script that probes and manipulates the control by calling ControlTreeView(). The script cannot, on its own, check the desired item in the TreeView, but it can check the item with some manual intervention. I need to know if there's something missing, or if a different approach is needed.

The operations currently being tested are:

  1. Waiting until the contents of the TreeView control appear before proceeding (the app can take a long time to display the control contents), and
  2. Checking the first item's checkbox (i.e., the disc itself), thus selecting the entire disc contents for copying.

The test script can complete the first operation successfully, but not the second: there is a side-effect of the first that apparently causes the second one to fail.

When the control's contents eventually become visible, they look like this; note the position of the scrollbar:

SysTreeView321.thumb.PNG.6106f38ddc49fcd

The wait is done by repeatedly selecting the first item until @error=0 using the following code fragment (note: the code has been edited for brevity and to remove certain information):

; Wait for the DM window to become active
; -- _WinWaitActivate() is from AU3 Recorder-generated code
$hWnd1 = _WinWaitActivate($sDMtitle,"")

; Wait for the SysTreeViewList32 control to display its first item
$sCtrlAdvMode = "[CLASS:SysTreeView32; INSTANCE:1]"
$i = 0
$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0")
$iAtError = @error
While $iAtError <> 0
    $i += 1
    If $i > 20 Then ExitLoop
    Sleep(5000)
    $iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Select","#0")
    $iAtError = @error
WEnd
If $i > 20 Then ConsoleWrite("Select: Unable to select 1st item after 20 tries" & @CRLF)

This works - the script successfully loops until the contents are visible, but when the item selection finally succeeds, the control contents scroll horizontally, hiding the checkboxes:

SysTreeView321-obscured.thumb.PNG.dfea66

The script then tries to check the first item by calling ControlTreeView() from the following code fragment (again, edited for brevity, etc.):

; Check the first item
$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Check","#0")
If @error <> 0 Then ConsoleWrite("Check: Unable to check 1st item, return=" & $iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF)

$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"IsChecked","#0")
ConsoleWrite("IsChecked: return=" & $iRetVal & ", @error=" & @error & ", @extended=" & @extended & @CRLF)

The Check call always returns @error=1, and the IsChecked call returns without error, but with a value of False. (The boxes remain unchecked on the screen as well.)

HOWEVER: With some experimentation I discovered that if I put a pause in the test script so that I can manually scroll the TreeView to make the checkboxes visible, then the Check call works - the boxes in the control are all checked, and the IsChecked call returns True.

Any suggestions for making this work under program control (no manual intervention)? The application needs to be completely automated.

Note: I have tried another method for the wait-loop (getting the first item's checkbox value), hoping it would achieve the desired result without scrolling the tree. However, the IsChecked call returns with @error=0 (and False) on the first call, long before the tree was visible.

 

Edited by tremolux66
Found a workaround

Share this post


Link to post
Share on other sites



Problem solved:

Collapsing the tree brings the checkbox into view, so the script can check the box using ControlTreeView():

$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Collapse","#0")
   :
$iRetVal = ControlTreeView($hWnd1,"",$sCtrlAdvMode,"Check","#0")

For this case, it's a workable solution since - fortunately - we're copying the entire disc and need only check the first item.

[I am a bit troubled that the ability to manipulate the control depends on the visibility of portions of its content, but perhaps this should not be surprising.]

Now, on to the next challenge...

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

  • Similar Content

    • ur
      By ur
      if ControlClick("[CLASS:MsiDialogCloseClass]"," ","[CLASS:SysTreeView32; INSTANCE:1]") Then $htreeview=ControlGetHandle($hwnd,"","[CLASS:SysTreeView32; INSTANCE:1]") ControlTreeView($hwnd," ",$htreeview,"Select","#4") The above code worked well to enable the martupgrade feature on windows 7.
      As part of our Installation Testing Automation before delivering the installer to end user.To confirm whether all the screens are working good.

      But it is not working on windows 10.
       
      $h= ControlTreeView($hwnd," ",$htreeview,"Select","#4") The $h is getting value 1,which means error.
    • antonioj84
      By antonioj84
      ;Hi there I am trying to to search a specific path c:\Documents and settings\rogers\Local Settings ;the code below work but can someone point how to define the path directly, instead of searching the folder then click to select and so on ; this code below work, it finds each folder click until Local settings $hWnd5 = WinGetHandle($Title,"") Sleep(300) $hlist = ControlGetHandle($hWnd5, "", "SysListView322") $listid = _GUICtrlListView_FindText($hlist,"Documents and Settings" ) _GUICtrlListView_ClickItem($hlist, $listid, "left", False, 2) Sleep(100) $hlist = ControlGetHandle($hWnd5, "", "SysListView322") $listid = _GUICtrlListView_FindText($hlist,"rogers" ) _GUICtrlListView_ClickItem($hlist, $listid, "left", False, 2) Sleep(100) $hlist = ControlGetHandle($hWnd5, "", "SysListView322") $listid = _GUICtrlListView_FindText($hlist,"Local Settings" ) _GUICtrlListView_ClickItem($hlist, $listid, "left", False, 1) **************************************************************************************************************************************************************** ;This code below does Not work some ideas ;$spath = "C:\" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select", $spath) ;$spath = "C:\ | Documents and Settings" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select", $spath) ;$spath = "Documents and Settings | rogers" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select", $spath) ;$spath = "Documents and Settings | rogers| Local Settings" ;$sgettext = ControlTreeView($Title,"","SysTreeView322", "select", $spath) ;ConsoleWrite($spath &@CRLF) ;$Selectall = ControlListView($hWnd5, "", "SysListView322", $sgettext) ;$Finditem = ControlListView($hWnd5, "", "SysListView322", "Finditem", "Local Settings") ;$Select = ControlListView($hWnd5, "", "SysListView322", "Select",$Finditem) ; consolewrite($Select)                                                             
       
       
       

    • kcvinu
      By kcvinu
      Hi all,
      I am experimenting with ControlTreeView function. But when i try this code, it is not doing anything.
      ControlTreeView("PhraseExpress Freeware v10.5.41f","",132066,"Select","PhraseExpress|Ahat|#3") Please see this image. I have use "WinActivate" function before this code. But no way.

    • PoojaKrishna
      By PoojaKrishna
      Hi Friends,
      I want to expand and click on some items on a tree view control. The AutoIT window info tool identifies the control as [CLASS:SysTreeView32; INSTANCE:1] but I failed to get the control handle to use with GuiTreeView methods. 
      Please see the code below. On execution it always fails with ControlGetHandle method.
      Please help.
      #RequireAdmin #include <Process.au3> #Include <GuiTreeView.au3> ;Execute group policy editor If Not WinExists("Local Group Policy Editor") Then _RunDOS ( 'gpedit.msc') EndIf WinwaitActive("Local Group Policy Editor") sleep(500) ;Select 'Administartive Template' from the tree view $nTreeView = ControlGetHandle ( "Local Group Policy Editor", "", "[CLASS:SysTreeView32; INSTANCE:1]" ) If @error = 0 Then MsgBox(0,"Error", "Couldn't get tree view control handle.") ControlTreeView ( "Local Group Policy Editor", "", "[CLASS:SysTreeView32; INSTANCE:1]" , "Expand", "#0" ) If @error = 0 Then MsgBox(0,"Error", "Couldn't expand tree view.")
    • Brian39
      By Brian39
      Hi,
      I have made a script for SAP application. I use the "MouseClick" to click on the arrow left of "HR" to expand tree. Then "MouseClick" to double click on "Tidsregistrering". This work fine but I would like to use something like "ControlTreeView" to expand the "HR" folder and "ControlClick" to activate "Tidsregistrering".
      I have attached a screendump with "Autoit window info". But I cant get it to work.
      To expand the "HR" folder I use: ControlTreeView("SAP Easy Access", "", "[iD:100]", "Expand")
      To enter "Tidsregistrering" menu I use: ControlClick("SAP Easy Access", "", "[iD:100]")

      Hopefully someone could point me in the right direction