ListView control tester

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Scoox
Posts: 125
Joined: 11 May 2014, 09:12
Location: China

ListView control tester

07 Oct 2014, 09:05

Here's a little script I wrote this morning to help me better understand what ListView events are triggered in real time as I interact with a list view control:

Image

You can interact with the top listview (white background) using the mouse and keyboard and the resulting A_EventInfo and A_GuiEvent values are displayed in the bottom listview (black background) in real time. Here's the code:

Code: Select all

#NoEnv
#NoTrayIcon
#SingleInstance Force

LogMaxRows := 10 ;log this many rows

Gui, Margin, 10, 10
Gui, Add, ListView, cBlue Checked AltSubmit -ReadOnly +Grid w229 r10 vLV_TestArea gLV_TestArea, A|B|C|D|E
Gui, Add, ListView, +Multi BackgroundBlack c00FF00 wp r%LogMaxRows% vLV_Log, A_EventInfo|A_GuiEvent|ErrorLevel
Gui, Add, Button, gClearLog w110 h30, Clear log
Gui, Add, Button, gCopyLog wp h30 x+9 yp, Copy selected

Gui, ListView, LV_TestArea
LV_ModifyCol(1, "100")
Loop 4
	LV_Add("", "Edit this text", A_Index, A_Index, A_Index, A_Index)

Gui, ListView, LV_Log
LV_ModifyCol(1, "75")
LV_ModifyCol(2, "75")
LV_ModifyCol(3, "75")

Gui, Show,, ListView Tester
Return

LV_TestArea:
	Critical
	Gui, ListView, LV_Log
	If (LV_GetCount() = LogMaxRows) ;trim log
		LV_Delete(1)
	LV_Modify(LV_Add("", A_EventInfo, A_GuiEvent,ErrorLevel), "Vis")
Return

GuiClose:
	ExitApp
Return

ClearLog:
	Gui, ListView, LV_Log
	LV_Delete()
Return

CopyLog:
	Gui, ListView, LV_Log
	LogText :=
	RowNumber := 0
	Loop
	{
		RowNumber := LV_GetNext(RowNumber)
		If !RowNumber
			Break
		RowText :=
		Loop, 3
		{
			LV_GetText(Text, RowNumber, A_Index)
			RowText .= Text "`t"
		}
		LogText .= RowText "`n"
	}
	Clipboard := LogText
Return
Last edited by Scoox on 18 Oct 2014, 06:47, edited 1 time in total.
User avatar
joedf
Posts: 8959
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: ListView control tester

07 Oct 2014, 14:25

Very neat! ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
jballi
Posts: 724
Joined: 29 Sep 2013, 17:34

Re: ListView control tester

08 Oct 2014, 04:24

This is an excellent learning tool. Thanks for sharing. :) You definitely want to add ErrorLevel to your table. Something like this.

Code: Select all

#NoEnv
#NoTrayIcon
#SingleInstance Force

LogMaxRows = 10

Gui, Margin, 10, 10
Gui, Add, ListView, cBlue AltSubmit -ReadOnly +Grid w304 r10 vLV_TestArea gLV_TestArea, A|B|C|D|E
Gui, Add, ListView, BackgroundBlack c00FF00 w304 r10 vLV_Log, A_EventInfo|A_GuiEvent|ErrorLevel

Gui, ListView, LV_TestArea
LV_ModifyCol(1, "100")
Loop 4
    LV_Add("", A_Index, A_Index, A_Index, A_Index, A_Index)

Gui, ListView, LV_Log
LV_ModifyCol(1, "100")
LV_ModifyCol(2, "100")
LV_ModifyCol(3, "100")

Gui, Show,, ListView Tester
Return

LV_TestArea:
    Gui, ListView, LV_Log
    If (LV_GetCount() = LogMaxRows) ;trim log
        LV_Delete(1)
    LV_Modify(LV_Add("", A_EventInfo, A_GuiEvent,ErrorLevel), "Vis")
Return

GuiClose:
    ExitApp
Return
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ListView control tester

08 Oct 2014, 04:57

I'd suggest to add Critical at the top of the LV_TestArea subroutine.
User avatar
Scoox
Posts: 125
Joined: 11 May 2014, 09:12
Location: China

Re: ListView control tester

18 Oct 2014, 06:49

Thanks for your suggestions, I've added them to the code at the top of this thread plus checkboxes and a couple of buttons to clear the log and copy selected log rows to the clipboard.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 186 guests