3
votes

I am trying to use ControlGet, List, to get the contents of a listview in AutoHotKey. This listview is in a simple VB6 app that I wrote. I am using:

ControlGet, List, List,, ListViewWndClass1, WindowTitle

ListViewWndClass1 is the class name I got from ActiveWindowInfo.

When I look at the return value for List, it is blank. Also ErrorLevel is 1.

I also tried:

ControlGet, List, List, Selected, SysListView321, Downloads

to get the contents of an Explorer window (Downloads) and this returned an ErrorLevel 1.

Any ideas what I am doing wrong here?

I am happy to use PostMessage / SendMessage or DllCall( "SendMessage", to get the contents of the list control.

Has anyone successfully gotten the contents of a listview control using AHK?

1

1 Answers

0
votes

Some current controls look like listviews, but are different from the old standard listview controls. For example, Windows XP folders did use standard listviews, but Windows 7 does not.

Presuming you are using an up-to-date version of AutoHotkey, on a standard listview control, it should be able to retrieve the text, unless it belongs to a program that deliberately prevents retrieval of the text (although you should still be able to get a count of the listview items).

If AutoHotkey's AccViewer can retrieve the text of a listview/listview-like control, then this means that you should be able to retrieve it via Acc.ahk and its functions.

If a control is a standard listview, you have to get the ControlGet parameters exactly right or the text retrieval won't work:

;get window by title
ControlGet, vText, List, , SysListView321, Media Player Classic Home Cinema

;get window by class
ControlGet, vText, List, , SysListView321, ahk_class MediaPlayerClassicW

;get active window
ControlGet, vText, List, , SysListView321, A

;display the text
MsgBox %vText%

;put the text on the clipboard
Clipboard := vText

;e.g. get text via the Acc library
;note: requires Acc.ahk library in AutoHotkey\Lib folder
;https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk
;on right of screen right-click Raw, Save target as...

^q::
ControlGet, hCtl, Hwnd, , SysListView321, A
if !hCtl
Return
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
Loop, % oAcc.accChildCount
if (Acc_Role(oAcc, A_Index) = "list item")
vText .= oAcc.accName(A_Index) "`r`n"
Clipboard := vText
MsgBox %vText%
Return