Jump to content

TreeView Click by text


DIMM_V2
 Share

Go to solution Solved by DIMM_V2,

Recommended Posts

Hello , can someone please help me with my code , im trying to click on "Home" by  text but this is  not working ,thx 

ps - it's working by index , but not by text .

based on this example = https://www.autoitscript.com/wiki/ControlTreeView

image.png.7fb3e550ba227acb1340366363702dbf.png

my code

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
; Run the Everything application
Run('C:\Program Files\Everything\Everything.exe')
Sleep(1000)
Send("^p")
; Get the handle of the SysTreeView32 control in the Everything window
Local $hTreeView = ControlGetHandle("Everything Options", "", "[CLASS:SysTreeView32; INSTANCE:1]")
; Select the third item in the TreeView
ControlTreeView("","", $hTreeView, " Expand", "General") ;  
ControlTreeView("","", $hTreeView, " Select", "General|Home") ; this is not working home
Sleep(2500)
ControlTreeView("", "", $hTreeView, "Select", "#0|#1") ;  this is home #0|#1
Sleep(2000)
; Find the index of the item with the text "General" in the TreeView
;~ Local $itemIndex = ControlTreeView("Everything Options", "", $hTreeView, "FindString", "View")
ControlTreeView("Everything Options", "", $hTreeView, "Select", "#4")
Sleep(2000)
;~ ControlTreeView("Everything Options", "", $hTreeView, "Select", "#0|#1") ; home
Local $homeItemIndex = ControlTreeView("Everything Options", "", $hTreeView, "FindString", "*Home*")

 

Link to comment
Share on other sites

22 minutes ago, Danp2 said:

In the example, the window handle is passed as the first parameter to ControlTreeView. You aren't doing that, so I don't know how you expect this to work.

P.S. You should check the value of @error following the command that you think is failing, which will help you understand what is happening.

* this code is working , but this is by index , i want to do that by text,so im not sure that the problem is in  "parameter"

ControlTreeView("", "", $hTreeView, "Select", "#0|#1") ;  this is home #0|#1

if i understand well , it should be something like this ==>  right ? because in my case i don't create any gui's .

ControlTreeView($hTreeView, "",  "Select", "#General|#Home") ; this is not working home
ControlTreeView($hTreeView, "",  "Select", "General|Home") ; this is not working home
Edited by DIMM_V2
addional info
Link to comment
Share on other sites

No, you can't just drop or move the parameters around. I may have been wrong about the need for the window handle. However, you should still check for errors following the command to better understand what is occurring. Have you done that?

Also, see the Remarks section in the help file entry for ControlTreeView. I have no idea if this applies to your situation since you haven't provided the necessary details. You may want to take a look at the GuiTreeView functions in the help file to see if they are able to better interact with the target control.

Link to comment
Share on other sites

16 minutes ago, Danp2 said:

No, you can't just drop or move the parameters around. I may have been wrong about the need for the window handle. However, you should still check for errors following the command to better understand what is occurring. Have you done that?

Also, see the Remarks section in the help file entry for ControlTreeView. I have no idea if this applies to your situation since you haven't provided the necessary details. You may want to take a look at the GuiTreeView functions in the help file to see if they are able to better interact with the target control.

how to check for errors , by debug to console from Scite ? 

if yes there is nothing special : "ever.au3"(19,293) : error: syntax error"

for the second point : I have tryed with 32 bit versions for "Everything" the same result . 

necessary details : im trying to click to "General > Home" as on my picture .

os :  ( win11 @  [Version 10.0.22621.2715]) 

 

Edited by DIMM_V2
Link to comment
Share on other sites

2 minutes ago, DIMM_V2 said:

how to check for errors , by debug to console from Scite ? 

Yes, that is one method. There are other options, such as using the Debug UDF that comes with AutoIt.

Quote

if yes there is nothing special : "ever.au3"(19,293) : error: syntax error"

No idea what you are trying to say here. That error message indicates an issue with whatever is on line 19 in your script.

Link to comment
Share on other sites

3 minutes ago, Danp2 said:

Yes, that is one method. There are other options, such as using the Debug UDF that comes with AutoIt.

No idea what you are trying to say here. That error message indicates an issue with whatever is on line 19 in your script.

@@ Debug(32) : Failed to select item. Error code: 1 ,      this info i had already . 🤯

Link to comment
Share on other sites

That's great... but you hadn't shared these details here, so were we supposed to know this by telekinesis? FWIW, my crystal ball is at the shop for repair. 🔮😁

I again recommend that you take a look at the _GuiTreeView* functions, as they may be better able to interact with the SysTreeView32 control.

Link to comment
Share on other sites

1 hour ago, Danp2 said:

That's great... but you hadn't shared these details here, so were we supposed to know this by telekinesis? FWIW, my crystal ball is at the shop for repair. 🔮😁

I again recommend that you take a look at the _GuiTreeView* functions, as they may be better able to interact with the SysTreeView32 control.

really ? this is my second line on the start of this post    ==>  .ps - it's working by index , but not by text .

After some tests this is working only with their own gui which is created by autoit, it can't run with external soft , or there is a bug ... so for me the function "ControlTreeView" present some bugs  or not fully compatible.

this is working code (this can change values in General , Home,Red,Green but fully useless

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>




Example()
Func Example()
    Local $hGUI, $idTreeView
    ; Create a GUI
    $hGUI = GUICreate("TreeView Example", 300, 200)
    $idTreeView = GUICtrlCreateTreeView(10, 10, 280, 180)
    ; Add items to the TreeView
    Local $idRoot = GUICtrlCreateTreeViewItem("General", $idTreeView)
    Local $idChild1 = GUICtrlCreateTreeViewItem("Home", $idRoot)
    Local $idChild2 = GUICtrlCreateTreeViewItem("Red", $idRoot)
    Local $idChild3 = GUICtrlCreateTreeViewItem("Green", $idRoot)
    ; Show the GUI
    GUISetState(@SW_SHOW, $hGUI)
    ; Select the "Home" item
    _GUICtrlTreeView_SelectItem($idTreeView, $idChild1)



WinActive("TreeView Example")
$hWnd  = WinGetHandle("TreeView Example")
; Get the handle of the SysTreeView32 control  
Local $hTreeView = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")
Sleep(2500)



ControlTreeView($hWnd, "", $hTreeView, "Select", "General|Red")
Sleep(1200)
ControlTreeView($hWnd, "", $hTreeView, "Select", "General|Green")
    ; Run the GUI until the user closes it
    Do
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete($hGUI)
EndFunc

 

this should work but this is not working

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
; Run the Everything application
Run('Everything.exe')
Sleep(1000)
Send("^p")
Sleep(1000)
; Get the handle of the SysTreeView32 control in the Everything window
$hWnd  = WinGetHandle("Everything Options")
Local $hTreeView = ControlGetHandle("Everything Options", "", "[CLASS:SysTreeView32; INSTANCE:1]")
; Select the third item in the TreeView
 

;~ ControlTreeView($hGUI, "", $hTreeView_1, "Select", "Root|Item 4") ;  example 

ControlTreeView($hWnd , "", "Select", "General|Home")
ControlTreeView($hTreeView , "", "Select", "General|Home")

 

 

Link to comment
Share on other sites

23 minutes ago, DIMM_V2 said:

really ? this is my second line on the start of this post    ==>  .ps - it's working by index , but not by text .

Yes... really. Stating that something "doesn't work" isn't helpful when you don't include additional details like the value of @error following the function call. 🙄

Quote

this is working code (this can change values in General , Home,Red,Green but fully useless : 

It's useful IMO because it accomplishes two things --

  • it allows anyone to run it without needing additional software to perform the test
  • it demonstrates that ControlTreeView is working for at least basic SysTreeView32 controls.
Quote

this should work but this is not working : 

Nope. AFAICS, you aren't calling ControlTreeView with the correct parameters in this code.

Link to comment
Share on other sites

18 minutes ago, Danp2 said:

Yes... really. Stating that something "doesn't work" isn't helpful when you don't include additional details like the value of @error following the function call. 🙄

It's useful IMO because it accomplishes two things --

  • it allows anyone to run it without needing additional software to perform the test
  • it demonstrates that ControlTreeView is working for at least basic SysTreeView32 controls.

Nope. AFAICS, you aren't calling ControlTreeView with the correct parameters in this code.

can you give an example ,that should work ?  with ControlTreeView  ?

Link to comment
Share on other sites

You already posted a working example above with your General, Home, Red, Green one. This is one of the lines from there --

ControlTreeView($hWnd, "", $hTreeView, "Select", "General|Red")

Now compare that to the ones from your next script --

ControlTreeView($hWnd , "", "Select", "General|Home")
ControlTreeView($hTreeView , "", "Select", "General|Home")

Notice any difference between those two lines and the first one? 🤔

Link to comment
Share on other sites

10 hours ago, Danp2 said:

You already posted a working example above with your General, Home, Red, Green one. This is one of the lines from there --

ControlTreeView($hWnd, "", $hTreeView, "Select", "General|Red")

Now compare that to the ones from your next script --

ControlTreeView($hWnd , "", "Select", "General|Home")
ControlTreeView($hTreeView , "", "Select", "General|Home")

Notice any difference between those two lines and the first one? 🤔

$hWnd  = WinGetHandle("Everything Options")

ControlTreeView ( "title", "text", controlID, "command" [, option1] ) ==> this is official info , how to use .

ControlTreeView($hWnd,"", $hTreeView,  "Select", "General|ui") ; ==> this is working .

why this one is not working ==> ControlTreeView("Everything Options", $hTreeView,  "Select", "General|Home")  ==> i have the title here , right ?

i dont't understand .

 

Link to comment
Share on other sites

2 hours ago, DIMM_V2 said:

ControlTreeView($hWnd,"", $hTreeView,  "Select", "General|ui") ; ==> this is working .

Are you sure? It doesn't work for me.

Local $hWnd  = WinGetHandle("Everything Options")
    Local $hTreeView = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")
    ControlTreeView($hWnd , "", $hTreeView, "Select", "General|ui")
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ControlTreeView = Error code: ' & @error & @CRLF)

This is my output --

@@ Debug(143) : ControlTreeView = Error code: 1

 

Link to comment
Share on other sites

  • Solution

 

29 minutes ago, Danp2 said:

Are you sure? It doesn't work for me.

Local $hWnd  = WinGetHandle("Everything Options")
    Local $hTreeView = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")
    ControlTreeView($hWnd , "", $hTreeView, "Select", "General|ui")
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ControlTreeView = Error code: ' & @error & @CRLF)

This is my output --

@@ Debug(143) : ControlTreeView = Error code: 1

 

Version :  Everything 1.4.1.935 (x64)

Version : Win 10 , build 2004 

 

* maybe it is not working on windows 11, all my past tests are done on windows 11 ; except the last one , i will retest it later on win11.

* for your test you must have the window Opened with label "Everything Options" , so it is not a main page .

yes these lines are working ; full working code

Run('Everything.exe')
Sleep(1000)
Send("^p")
Sleep(1000)
; Get the handle of the SysTreeView32 control in the Everything window
$hWnd  = WinGetHandle("Everything Options")
$hTreeView = ControlGetHandle("Everything Options", "", "[CLASS:SysTreeView32; INSTANCE:1]")
Sleep(1000)
ControlTreeView($hWnd,"", $hTreeView,  "Select", "General|ui") ;   kk
Sleep(1000)
ControlTreeView($hWnd,"", $hTreeView,  "Select", "General|Home") ; kk

Check Proof -) 

RDCMan_HDZsTWpNeN.gif

Edited by DIMM_V2
Link to comment
Share on other sites

FWIW, that was only a subset of the code (just enough to show the origin of the variables being used). Based on your test above, it appears to work on Win10 but not Win11. I believe the issue is related to failure to retrieve the text from the items.

I wonder if this is a known issue? Maybe @jpm or another user will chime in here with some ideas.

Link to comment
Share on other sites

Ok... so this appears to be the same issue as described in this prior thread. Running the script in x64 mode works for me.

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

; Run the Everything application
Run('C:\Program Files\Everything\Everything.exe')
Sleep(1000)
Send("^p")
Sleep(1000)

; Get the handle of the SysTreeView32 control in the Everything window
Local $hWnd  = WinGetHandle("Everything Options")
Local $hTreeView = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")

ControlTreeView($hWnd , "", $hTreeView, "Select", "General|Home")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ControlTreeView = Error code: ' & @error & @CRLF)

 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

FWIW, that was only a subset of the code (just enough to show the origin of the variables being used). Based on your test above, it appears to work on Win10 but not Win11. I believe the issue is related to failure to retrieve the text from the items.

I wonder if this is a known issue? Maybe @jpm or another user will chime in here with some ideas.

why this one is not working ==> ControlTreeView("Everything Options", $hTreeView,  "Select", "General|Home")  ==> i have the title here , right ?

i dont't understand .

* yes it works well on windows 11 too, 

image.png.4fb76f769881e68dc9c4dde794ccd2a9.png

Link to comment
Share on other sites

Start allways with checking the example in the helpfile for ControlTreeView

titles can be frustrating with invisible characters, upper en lowercase. Use the spyingtools to help.

why this one is not working ==> ControlTreeView("Everything Options", $hTreeView,  "Select", "General|Home")  ==> i have the title here , right ?

ControlTreeView("Everything Options", $hTreeView,  "Select", "General|Home") 

ControlTreeView("Everything Options", "", $hTreeView,  "Select", "General|Home") 

the first is not working as you miss a parameter

 

 

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