Jump to content

ControlListView GetText


Recommended Posts

Hello,

I am using this for the first time and i am having some difficulties. Actually i didnt even know this function exists, hence i have been using autoit for some years :D
 

So this is my code:

#include <MsgBoxConstants.au3>
Local $hWin = WinGetHandle("Libraries")
Local $hwnd = ControlGetHandle($hWin, "", "DirectUIHWND3")
;ConsoleWrite("Window handle: " & $hWin & @LF)
;ConsoleWrite("Control handle: " & $hwnd & @LF)
WinActivate($hWin)
Send("{down}{down}{down}")    ;;;select a random item
Sleep(250)
Local $GetSelected = ControlListView($hWin, "", $hwnd, "GetSelected")
Local $GetText = ControlListView($hWin, "", $hwnd, "GetText", $GetSelected)
;ConsoleWrite("Selected: " & $GetSelected & @LF)
ConsoleWrite("Text: " & $GetText & @LF)

I am trying to get the text of the selected item. I read the help files and did a little research but couldn't make it work.
Any idea what is wrong?



 

Edited by AutID
Link to comment
Share on other sites

Not sure it says in the help file that you can use the window handle of the control in it's ID parameter.

 

Sorry i am not understanding. I am using a control handle in the controlID parameter and a window handle in the text parameter. I dont think there is anything wrong with that.

Both window and control returns a handle. The right handles.

 

 

DirectUIHWND <> ListView32, you can't access it in that way like Windows XP

Easy way:

; Johnmcloud 2014
ClipPut("") ;empty the clipboard

Local $hWin = WinGetHandle("Libraries")
Local $hWnd = ControlGetHandle($hWin, "", "DirectUIHWND3")
WinActivate($hWin)
ControlSend($hWnd, "", "", "{DOWN}")
ControlSend($hWnd, "", "", "{F2}")
ControlSend($hWnd, "", "", "^c")
ControlSend($hWnd, "", "", "{ESC}")
ConsoleWrite("Text: " & ClipGet() & @CRLF)

 hmmm this way seems nasty. It is effective but don't know. Would you rely on a solution like this?

It is better than not working in any case.

Link to comment
Share on other sites

hmmm this way seems nasty. It is effective but don't know. Would you rely on a solution like this?

It is better than not working in any case.

 

I'll repeat, from Vista there is a DirectUIHWND class control that doesn't accept the listview32 messages, there isn't a easy way to automate that control ( maybe using UI Automation Framework or Windows Object )

See post #8

Instead if i need a particular file or a filelist i'll use _FileListToArray or UDF alternative, not opening/waiting for a folder and get the selected file

Edited by johnmcloud
Link to comment
Share on other sites

Local $hWin = WinGetHandle("Untitled - Notepad")
Local $hWnd = ControlGetHandle($hWin, "", "Edit1")
ControlSend($hWin, "", $hWnd, "Test")

 

I'll repeat, from Vista there is a DirectUIHWND class control that doesn't accept the listview32 messages, there isn't a easy way to automate that control ( maybe using UI Automation Framework or Windows Object ) so i have posted that working example, if someone has a "nicer" one i'm curious to see it

I'll never use a solution like what i have posted, it works but i don't have any valid reason to use a solution like that :D

Instead if i need a particular file or a filelist i'll use _FileListToArray or UDF alternative, not opening/waiting for a folder and get the selected file

Well this is not what i would personally do but i am obligated to interact the libraries window as it is in the example.

The tree view on the left is a SysTreeView321. I guess this also is different from ListView32 since it doesn't work neither.

Anyway thanks for the informations ;)

 

Link to comment
Share on other sites

The tree view on the left is a SysTreeView321. I guess this also is different from ListView32 since it doesn't work neither.

 

No, is different from ListView because isn't a ListView but is a standard TreeView control

Example for how get the selected item:

; Johnmcloud 2014
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y ; NOTE --> you need it if your system is x64 bit!
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiTreeView.au3>

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hWnd = ControlGetHandle($hWin, "", "DirectUIHWND3")
Local $hItem = "", $hSelection, $hTree, $sText
WinActivate($hWin)

$hTree = ControlGetHandle($hWin, "", "[CLASS:SysTreeView32; INSTANCE:1]")

While ControlGetHandle($hWin, "", "DirectUIHWND3")
    $hSelection = _GUICtrlTreeView_GetSelection($hTree)
    If $hSelection <> $hItem Then
        $hItem = $hSelection
        $sText = _GUICtrlTreeView_GetText($hTree, $hItem)
        ConsoleWrite("Item selected: " & $sText & @CRLF)
    EndIf
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

EDIT: This example instead get the select item like the previus one i have posted but in a better way. Based on this >example by LarsJ

; Johnmcloud 2014 --> LarsJ 

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hItem = "", $hSelection, $sText
WinActivate($hWin)

; Shell object
$oShell = ObjCreate("Shell.Application")

; Find window
For $oWindow In $oShell.Windows()
    If $oWindow.HWND() = $hWin Then ExitLoop
Next

; Selected items
For $oItem In $oWindow.Document.SelectedItems()
    $hItem = $oItem.Name()
Next

While WinExists("Libraries")
    For $oItem In $oWindow.Document.SelectedItems()
        If $oItem.Name() <> $hItem Then
            ConsoleWrite("Item selected: " & $oItem.Name() & @CRLF)
             $hItem = $oItem.Name()
        EndIf
    Next
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit
Edited by johnmcloud
Link to comment
Share on other sites

Local $hWin = WinGetHandle("Untitled - Notepad")
Local $hWnd = ControlGetHandle($hWin, "", "Edit1")
ControlSend($hWin, "", $hWnd, "Test")

Ace.

Should be listed in the help file that a handle can be used.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Developers

Ace.

 

Should be listed in the help file that a handle can be used.

It is already at the bottom of this page which is linked :

http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

 

No, is different from ListView because isn't a ListView but is a standard TreeView control

Example for how get the selected item:

; Johnmcloud 2014
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y ; NOTE --> you need it if your system is x64 bit!
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiTreeView.au3>

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hWnd = ControlGetHandle($hWin, "", "DirectUIHWND3")
Local $hItem = "", $hSelection, $hTree, $sText
WinActivate($hWin)

$hTree = ControlGetHandle($hWin, "", "[CLASS:SysTreeView32; INSTANCE:1]")

While ControlGetHandle($hWin, "", "DirectUIHWND3")
    $hSelection = _GUICtrlTreeView_GetSelection($hTree)
    If $hSelection <> $hItem Then
        $hItem = $hSelection
        $sText = _GUICtrlTreeView_GetText($hTree, $hItem)
        ConsoleWrite("Item selected: " & $sText & @CRLF)
    EndIf
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

EDIT: This example instead get the select item like the previus one i have posted but in a better way. Based on this '?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>>example by LarsJ

; Johnmcloud 2014 --> LarsJ 

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hItem = "", $hSelection, $sText
WinActivate($hWin)

; Shell object
$oShell = ObjCreate("Shell.Application")

; Find window
For $oWindow In $oShell.Windows()
    If $oWindow.HWND() = $hWin Then ExitLoop
Next

; Selected items
For $oItem In $oWindow.Document.SelectedItems()
    $hItem = $oItem.Name()
Next

While WinExists("Libraries")
    For $oItem In $oWindow.Document.SelectedItems()
        If $oItem.Name() <> $hItem Then
            ConsoleWrite("Item selected: " & $oItem.Name() & @CRLF)
             $hItem = $oItem.Name()
        EndIf
    Next
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Good examples.

Here is an examples using LarsJ's Automating Windows Explorer UDF listing all files and selecting them

Opt( "MustDeclareVars", 1 )
#include "Includes\AutomatingWindowsExplorer.au3"
#include "Example\ExampleFunctions.au3"

Example()

Func Example()
 $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
 If Not $hExplorer Then
  MsgBox( $MB_SYSTEMMODAL + $MB_ICONERROR, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." )
  Return
 EndIf
 GetIShellBrowser( $hExplorer )
 If Not IsObj( $oIShellBrowser ) Then
  MsgBox( $MB_SYSTEMMODAL + $MB_ICONERROR, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." )
  Return
 EndIf
 ; Get other interfaces
 GetShellInterfaces()
 Local $sitems = CountItems()
 ConsoleWrite($sitems & @LF)
 For $i = 0 To $sitems -1
  ConsoleWrite(GetItems()[$i] & @LF)
 Next
 For $i = 0 To $sitems -1
  SetSelectedItem($i)
  ;SetSelectedItem($i, False)  Deselect
 Next
 Cleanup()
EndFunc

Link to topic: '?do=embed' frameborder='0' data-embedContent>?do=embed' frameborder='0' data-embedContent>>

Edited by AutID
Link to comment
Share on other sites

 

No, is different from ListView because isn't a ListView but is a standard TreeView control

Example for how get the selected item:

; Johnmcloud 2014
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y ; NOTE --> you need it if your system is x64 bit!
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GuiTreeView.au3>

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hWnd = ControlGetHandle($hWin, "", "DirectUIHWND3")
Local $hItem = "", $hSelection, $hTree, $sText
WinActivate($hWin)

$hTree = ControlGetHandle($hWin, "", "[CLASS:SysTreeView32; INSTANCE:1]")

While ControlGetHandle($hWin, "", "DirectUIHWND3")
    $hSelection = _GUICtrlTreeView_GetSelection($hTree)
    If $hSelection <> $hItem Then
        $hItem = $hSelection
        $sText = _GUICtrlTreeView_GetText($hTree, $hItem)
        ConsoleWrite("Item selected: " & $sText & @CRLF)
    EndIf
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

EDIT: This example instead get the select item like the previus one i have posted but in a better way. Based on this >example by LarsJ

; Johnmcloud 2014 --> LarsJ 

HotKeySet("{ESC}", "_Exit")

ShellExecute("shell:Libraries")
Do
    Sleep(10)
Until WinExists("Libraries")

Local $hWin = WinGetHandle("Libraries")
If Not $hWin Then Exit

Local $hItem = "", $hSelection, $sText
WinActivate($hWin)

; Shell object
$oShell = ObjCreate("Shell.Application")

; Find window
For $oWindow In $oShell.Windows()
    If $oWindow.HWND() = $hWin Then ExitLoop
Next

; Selected items
For $oItem In $oWindow.Document.SelectedItems()
    $hItem = $oItem.Name()
Next

While WinExists("Libraries")
    For $oItem In $oWindow.Document.SelectedItems()
        If $oItem.Name() <> $hItem Then
            ConsoleWrite("Item selected: " & $oItem.Name() & @CRLF)
             $hItem = $oItem.Name()
        EndIf
    Next
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

And here is a list with all the properties you can get

HotKeySet("{ESC}", "_Exit")
Do
    Sleep(10)
Until WinExists("[REGEXPCLASS:^(Cabinet|Explore)WClass$]")
Local $hWin = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
If Not $hWin Then Exit
Local $hItem = "", $hSelection, $sText
WinActivate($hWin)
; Shell object
$oShell = ObjCreate("Shell.Application")
; Find window
For $oWindow In $oShell.Windows()
    If $oWindow.HWND() = $hWin Then ExitLoop
Next
; Selected items
For $oItem In $oWindow.Document.SelectedItems()
    $hItem = $oItem.Name()
Next
While WinExists("[REGEXPCLASS:^(Cabinet|Explore)WClass$]")
    For $oItem In $oWindow.Document.SelectedItems()
        If $oItem.Name() <> $hItem Then
            ConsoleWrite("Name: " & $oItem.Name & @CRLF) ;Sets or gets the item's name.
   ConsoleWrite("Type: " & $oItem.Type & @CRLF) ;Contains a string representation of the item's type.
   ConsoleWrite("Path: " & $oItem.Path  & @CRLF) ;Contains the item's full path and name.
   ConsoleWrite("IsLink: " & $oItem.IsLink  & @CRLF)   ;Indicates whether the item is a shortcut.
   ConsoleWrite("IsFolder: " & $oItem.IsFolder & @CRLF) ;Indicates whether the item is a folder.
   ConsoleWrite("IsFileSystem: " & $oItem.IsFileSystem & @CRLF) ;Indicates if the item is part of the file system.
   ConsoleWrite("IsBrowsable : " & $oItem.IsBrowsable & @CRLF) ;Indicates if the item can be hosted inside a browser or Windows Explorer frame.
   ConsoleWrite("GetLink : " & $oItem.GetLink  & @CRLF) ;Contains the item's ShellLinkObject object, if the item is a shortcut.
   ConsoleWrite("GetFolder : " & $oItem.GetFolder & @CRLF) ;Contains the item's Folder object, if the item is a folder.
   ConsoleWrite("Application : " & $oItem.Application  & @CRLF) ;Contains the Application object of the folder item.
   ConsoleWrite("Date: " & $oItem.ModifyDate  & @CRLF)   ;yy/mm/dd hh/nn/ss
   ConsoleWrite("Size: " & $oItem.Size & " bytes"& @CRLF) ;Contains the item's size.
   ;ConsoleWrite("Type: " & Round($oItem.Size / 1000) & " KB"& @CRLF)
            $hItem = $oItem.Name()
        EndIf
    Next
    Sleep(100)
WEnd
ConsoleWrite("Exit" & @LF)
Func _Exit()
    Exit
EndFunc   ;==>_Exit
Just added this for future references and help.
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...