Control handle for SysTreeView32

3 posts in this topic

PoojaKrishna 1

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.

Share this post

Link to post

Share on other sites

BrewManNH 1,007

@error = 0 means there was no error, and if the function fails the return is 0, and @error is set to something other than 0. Your error check is wrong for both ControlGetHandle and for ControlTreeview.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

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:
Waiting until the contents of the TreeView control appear before proceeding (the app can take a long time to display the control contents), and
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:

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:

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.