Jump to content

ControlTreeView GetText doesn't work in C# 64-bit


MathieuT
 Share

Recommended Posts

Hi all,

 

While building a program in C# with the inclusion of AutoItX, I discovered an issue with ControlTreeView GetText.

Normally I start testing some AutoIt functionality in AutoIt itself (using SciTE-Lite), before implementing it in my code in C#. There is a SysTreeView32 in the application I'm trying to automate, so did some testing using the ControlTreeView function. The function and all the commands I tried are working perfectly.

Then I moved to C#, everything seems okay until I tried the GetText command. This always returns an empty string and it sets the AutoItX.ErrorCode() to 1.

 

So I did some more testing in AutoIt, executing the GetText command in SciTE-Lite and AutoIt3.exe works perfectly, but it doesn't in AutoIt3_x64.exe.

So apparently the GetText command doesn't work when executing the AutoIt code as 64-bit. Obviously, my C# program is also 64-bit and the AutoItX source code checks for 32 or 64-bit and then executes the corresponding code (AU3_ControlTreeView64 vs AU3_ControlTreeView32).

If it matters, the application that contains the SysTreeView32 is 32-bit.

 

Forgive me if it is a stupid question, but is it possible to get the GetText command working without changing my C# program to 32-bit?

Thank you in advance.

Link to comment
Share on other sites

I'm also using AutoIt 3.3.16.1.

This is the code I tested in AutoIt, this prints the first first three levels of the TreeView to the console (I know the code can be cleaner and shorter 😛). I added the message box to get some feedback while running the script using AutoIt3.exe and AutoIt3_x64.exe. As I said earlier, it works in SciTE-Lite and AutoIt3.exe, but not in AutoIt3_x64.exe.

The other commands work fine in SciTE-Lite, AutoIt3.exe and AutoIt3_x64.exe.

#include <Array.au3>

Example()
Exit

Func Example()
    Local $aWinList = WinList("[REGEXPTITLE:(?i)(.*Program name*)]")
    
    ; Iterate through all windows
    For $iCount = 1 To $aWinList[0][0]
        ; Activate window
        WinActivate($aWinList[$iCount][1])
        WinWaitActive($aWinList[$iCount][1])    
        
        Local $aPos = WinGetPos($aWinList[$iCount][0])
        ConsoleWriteLine("Window is at x: " & $aPos[0] & ", y: " & $aPos[1] & ", w: " & $aPos[2] & ", h: " & $aPos[3])      
                
        Local $treeViewHandle = ControlGetHandle($aWinList[$iCount][1], "", "[CLASS:SysTreeView32; INSTANCE:1]")
        if ($treeViewHandle > 0) Then
            ; Root folder
                $itemExists = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Exists", "#0")
            if ($itemExists == 1) Then      
                $itemText = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "GetText", "#0")
                ConsoleWriteLine("#0 - " & $itemText)
                $itemCount0 = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "GetItemCount", "#0")
                
                For $i = 0 To $itemCount0
                    $itemExists = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Exists", "#0|#" & $i)
                    if ($itemExists == 1) Then
                        $itemText = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "GetText", "#0|#" & $i)
                        ConsoleWriteLine("#0|#" & $i & " - " & $itemText)
                        $itemCount1 = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "GetItemCount", "#0|#" & $i)
                        
                        ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Expand", "#0|#" & $i)
                        
                        For $j = 0 To $itemCount1
                            $itemExists = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Exists", "#0|#" & $i & "|#" & $j)
                            if ($itemExists == 1) Then
                                $itemText = ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "GetText", "#0|#" & $i & "|#" & $j)
                                ConsoleWriteLine("#0|#" & $i & "|#" & $j & " - " & $itemText)
                                MsgBox($MB_SYSTEMMODAL, "Test", "#0|#" & $i & "|#" & $j & " - " & $itemText)
                            EndIf                               
                        Next    

                        ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Collapse", "#0|#" & $i)                        
                    EndIf                       
                Next    
                
                ControlTreeView($aWinList[$iCount][1], "", $treeViewHandle, "Expand", "#0|#0")
            EndIf               
        EndIf
    Next        
EndFunc   ;==>Example

; ConsoleWriteLine
Func ConsoleWriteLine($vVar)
    ConsoleWrite($vVar & @CRLF)
EndFunc   ;==>ConsoleWriteLine

 

Some examples I use in C#:

AutoItX.ControlTreeView(windowHandle, treeviewHandle, "Select", currentTreeViewItem, ""); // works as expected
int count = int.Parse(AutoItX.ControlTreeView(windowHandle, treeviewHandle, "GetItemCount", currentTreeViewItem, "")); // works as expected

string treeviewItemText = AutoItX.ControlTreeView(windowHandle, treeviewHandle, "GetText", treeviewPosition, ""); // doesn't work as expected, returns an empty string

I also tried the alternative function which takes "string title, string text, string control..." instead of "IntPtr winHandle, IntPtr controlHandle...".

Edited by MathieuT
Link to comment
Share on other sites

1 hour ago, Danp2 said:

I was hoping that you would post a short snippet of code that demonstrated your claim that GetText fails in 64 bit mode. FWIW, my previous tests were performed with a modified version of the help file example for ControlTreeView.

Thank you for the suggestion.

 

I used the help file example for ControlTreeView and made the following script to manipulate the TreeView created in the ControlTreeView example.

Example()

Func Example()
    Local $hGUI = WinGetHandle("ControlTreeView Example")
        Local $hTreeView_1 = ControlGetHandle($hGUI, "", "[CLASS:SysTreeView32; INSTANCE:1]")   
    WinActivate($hGUI)
    
    ControlTreeView($hGUI, "", $hTreeView_1, "Collapse", "Root|Item 4")
        
EndFunc   ;==>Example

 

When both scripts are run in the same mode, Item 4 is collapsed. If one is run in 32-bit and the other in 64-bit Item 4 is not collapsed. Repeat for other commands.

It is strange that none of the ControlTreeView commands are working when mixing 32-bit and 64-bit. Because using AutoItX in C# (64-bit), I'm able to use most of the commands on a TreeView in a 32-bit application. Except of course the GetText command.

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...