Jump to content

Struggling with ControlTreeView


Recommended Posts

I've tried writing my own code to access items in ControlTreeView with zero success.

For the sake of my education example code that navigates the SysTreeView32 in the File explorer and "right clicks" the "Documents" entry would be really helpful.

I can't event get ControlTreeView "Get Text" to work so I don't know how I could "step through" the items to find "Documents".

I'd very much appreciate a working example.

In Windows10Pro File Explorer opens with the bottom left pane being [Class:SysTreeView32;INSTANCE;1]

here is my code

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#AutoIt3Wrapper_UseX64

run ("explorer")

sleep(100)

WinActivate("File Explorer")
sleep (100)

local $ctrHndl = ControlGetHandle("File Explorer","","[Class:SysTreeView32;INSTANCE:1]")                                          

MSGBOX(0,"","Display Control Handle $ctrHndl : "  & $ctrHndl)                                                                                  msgbox displays 0x00000000
$Result1 = ControlTreeView("File Explorer","","[Class:SysTreeView32;INSTANCE:1]","GetItemCount")                
MSGBOX(0,"","Display ControlTreeView Count : "  & $Result1)                                                                                    mgsbox displays "2"

$Result1 = ControlTreeView("File Explorer","","[Class:SysTreeView32;INSTANCE:1]","GetText",1)
MSGBOX(0,"","Display ControlTreeView Text : "  & $Result1)                                                                                      msgbox displays ""

Link to comment
Share on other sites

i dont think the file explorer window is actually named 'File Explorer', it should be named whatever it is open to...

for instance, my file explorer opens to This PC

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

#include <GuiTreeView.au3>
#AutoIt3Wrapper_UseX64

Run ("explorer")
Sleep(500)

Local $hWnd = WinActivate("[CLASS:CabinetWClass]")
MsgBox ($MB_SYSTEMMODAL,"",$hWnd)

Local $ctrHndl = ControlGetHandle($hWnd,"","[Class:SysTreeView32;INSTANCE:1]")

MsgBox ($MB_SYSTEMMODAL,"","Display Control Handle $ctrHndl : "  & $ctrHndl)

Local $Result1 = _GUICtrlTreeView_GetCount($ctrHndl)
MsgBox ($MB_SYSTEMMODAL,"","Display ControlTreeView Count : "  & $Result1)

I got this so far...But I am not sure it is possible to go way further.

Link to comment
Share on other sites

What is the end goal?  There may be an easier way to reach it rather than manipulating UI controls; not to say that is a bad way to go or discourage the approach necessarily, but if the end goal can be reached by other means and with fewer commands (versus simulating clicks and key presses) that should be worth considering.

Having said that, here's more to chew on:

#include <GuiTreeView.au3>
#AutoIt3Wrapper_UseX64

Run ("explorer")
Sleep(500)

Local $hWnd = WinActivate("[CLASS:CabinetWClass]")
;MsgBox ($MB_SYSTEMMODAL,"",$hWnd)

Local $ctrHndl = ControlGetHandle($hWnd,"","[Class:SysTreeView32;INSTANCE:1]")

;MsgBox ($MB_SYSTEMMODAL,"","Display Control Handle $ctrHndl : "  & $ctrHndl)

Local $Result1 = _GUICtrlTreeView_GetCount($ctrHndl)
;MsgBox ($MB_SYSTEMMODAL,"","Display ControlTreeView Count : "  & $Result1)

$iItem = _GUICtrlTreeView_GetFirstItem($ctrHndl)

While $iItem
    $hItem = _GUICtrlTreeView_GetItemHandle($iItem, $iItem)
    $sItem = _GUICtrlTreeView_GetText($ctrHndl, $hItem)
    ConsoleWrite($hItem & @TAB & $sItem & @CRLF)

    $iChild = _GUICtrlTreeView_GetChildCount($ctrHndl, $iItem)
    If $iChild <> -1 Then
        $iItem = _GUICtrlTreeView_GetFirstChild($ctrHndl, $iItem)
    Else
        $iItem = _GUICtrlTreeView_GetNext($ctrHndl, $iItem)
    EndIf
WEnd

 

Link to comment
Share on other sites

11 hours ago, spudw2k said:

What is the end goal?  There may be an easier way to reach it rather than manipulating UI controls; not to say that is a bad way to go or discourage the approach necessarily, but if the end goal can be reached by other means and with fewer commands (versus simulating clicks and key presses) that should be worth considering.

Having said that, here's more to chew on:

#include <GuiTreeView.au3>
#AutoIt3Wrapper_UseX64

Run ("explorer")
Sleep(500)

Local $hWnd = WinActivate("[CLASS:CabinetWClass]")
;MsgBox ($MB_SYSTEMMODAL,"",$hWnd)

Local $ctrHndl = ControlGetHandle($hWnd,"","[Class:SysTreeView32;INSTANCE:1]")

;MsgBox ($MB_SYSTEMMODAL,"","Display Control Handle $ctrHndl : "  & $ctrHndl)

Local $Result1 = _GUICtrlTreeView_GetCount($ctrHndl)
;MsgBox ($MB_SYSTEMMODAL,"","Display ControlTreeView Count : "  & $Result1)

$iItem = _GUICtrlTreeView_GetFirstItem($ctrHndl)

While $iItem
    $hItem = _GUICtrlTreeView_GetItemHandle($iItem, $iItem)
    $sItem = _GUICtrlTreeView_GetText($ctrHndl, $hItem)
    ConsoleWrite($hItem & @TAB & $sItem & @CRLF)

    $iChild = _GUICtrlTreeView_GetChildCount($ctrHndl, $iItem)
    If $iChild <> -1 Then
        $iItem = _GUICtrlTreeView_GetFirstChild($ctrHndl, $iItem)
    Else
        $iItem = _GUICtrlTreeView_GetNext($ctrHndl, $iItem)
    EndIf
WEnd

 

I need to write a script to do a "soak test" to repeatedly download a process automation controller.  The software used to initiate this download lists the controllers in a system tree.  I need to select a specific controller, "right click it" and then select a specific type of download from the options presented when the right-click is made.  Instead of asking my question in the context of a specific application that fewer people would be aware of, I chose File Explorer to request as an example of how to actually use ControlTreeView.

One of the criteria of this soak test is that I mimic the user's keystrokes as accurately as possible.

1000 thanks.  I am grateful to all of you!

Link to comment
Share on other sites

@DenisB I disagree.  I used _GetText in the example I made above that you quoted, and _GetSelected works for me in this demo:

#include <GuiTreeView.au3>
#include <Array.au3>
#AutoIt3Wrapper_UseX64

Run ("explorer")
Sleep(500)

Local $hWnd = WinActivate("[CLASS:CabinetWClass]")
Local $hTreeView = ControlGetHandle($hWnd,"","[Class:SysTreeView32;INSTANCE:1]")
Local $iTreeViewItemCount = _GUICtrlTreeView_GetCount($hTreeView)

Local $aTreeViewContents[1][3]=[["Item_Handle","Item_Text","Item_Selected"]]
ReDim $aTreeViewContents[$iTreeViewItemCount+1][3]

$iIdx = 1
$hItem = _GUICtrlTreeView_GetFirstItem($hTreeView)

While $hItem
    $aTreeViewContents[$iIdx][0] = $hItem
    $aTreeViewContents[$iIdx][1] = _GUICtrlTreeView_GetText($hTreeView, $hItem)
    $aTreeViewContents[$iIdx][2] = _GUICtrlTreeView_GetSelected($hTreeView, $hItem)

    $iChild = _GUICtrlTreeView_GetChildCount($hTreeView, $hItem)
    If $iChild <> -1 Then
        $hItem = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
    Else
        $hItem = _GUICtrlTreeView_GetNext($hTreeView, $hItem)
    EndIf
    $iIdx += 1
WEnd

_ArrayDisplay($aTreeViewContents)
MsgBox(0,"Currently Selected TreeView Item",_GUICtrlTreeView_GetText($hTreeView,_GUICtrlTreeView_GetSelection($hTreeView)))

@Nine  Sorry, I'm a little confused.  You wrote the example above that I built on, so I assume my example would have worked for you as well.  The examples I made work for me on Win 10 1809.

Edited by spudw2k
Link to comment
Share on other sites

No need to be sorry.  It was Just a simple observation.  That's why I was "not sure it is possible to go way further".  Maybe it will work on w10,  I didn't invest time to find out. But I must agree with you that going by that road is not the approach I would use...

Link to comment
Share on other sites

Thank you spudw2k.  I've got no ego investment here and evidently I'm deficient.  I'm on Windows10 Pro and I'll dig back into this later today.  If I'm still stuck I'll give much more information for you all to help me (if you haven't come to the realization that I'm beyond help by then.)

Again 1000 thanks for your help and patience.

Link to comment
Share on other sites

Certainly.  I'm not being judgmental or anything (at least that is not my intent), just pointing out that it should be capable of working.  If it isn't, there is something else going on that hopefully can be resolved.  Let us know when/where you get stuck.

Link to comment
Share on other sites

Here is a screen cap of what I get when I run the code posted by spudw2k 20190806_18:25.

I tried to redact 3 nodes in the tree since this is my work computer.

spudw2k_TreeView_code_20190806_1825.JPG.4a2c8fef5b54d5f7ca50aad1cecf2a1b.JPGHere is a screen cap of what I get when I run the code posted

 

 

Edited by DenisB
Link to comment
Share on other sites

interesting.  Attached is a screenshot of it on my PC.  

I notice your item handles look like they are 32-bit compared to mine.  Are you sure you are running the x64 AutoIt Interpreter?

Perhaps correcting the Usex64 wrapper as follows will help: #AutoIt3Wrapper_UseX64=y. 

I corrected it above.  I suspect without the =y it is being omitted. The default interpreter on my machine is x64, whereas it is x32 on yours...my hunch. 

Untitled.png

Edited by spudw2k
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...