[How To] Scroll listbox, listview and edit controls

Helpful script writing tricks and HowTo's
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

[How To] Scroll listbox, listview and edit controls

16 Nov 2013, 19:36

... and probably any edit control with a scrollbar.
Note: since this is sendmessage, it'll work on most windows, not just AHK GUI's.

Code: Select all

#SingleInstance force

Gui, add, edit,     x6 y6  w400 r5 hwndhEdit vedit,
Gui, add, listview, x6 y+5 wp   r5 hwndhlv   vlv, aaa|bbb|ccc
Gui, add, listbox,  x6 y+5 wp   r5 hwndhlb   vlb,
gui, add, button, x6 y+10 gAAS1, Add 1 and Scroll down 1
gui, add, button, x6 y+1  gAAS2, Add 1 and Scroll to bottom
gui, show
return


AAS1:
AAS2:
	Gui, Submit, NoHide
	counter+=1
	GuiControl,, edit, % trim(edit "`nNewline " counter, "`r`n")
	LV_Add("", "Newline " counter)
	LV_ModifyCol(),LV_ModifyCol(2, "autohdr"),LV_ModifyCol(3, "autohdr")
	GuiControl,, lb, Newline %counter%
	
	if (A_ThisLabel="AAS1") ; Scroll down 1
	{		
		sendmessage, 0x115, 1, 0,, ahk_id %hEdit%
		sendmessage, 0x115, 1, 0,, ahk_id %hlv%
		sendmessage, 0x115, 1, 0,, ahk_id %hlb%
	}
	else if (A_ThisLabel="AAS2") ; Scroll to bottom
	{
		sendmessage, 0x115, 7, 0,, ahk_id %hEdit%
		sendmessage, 0x115, 7, 0,, ahk_id %hlv%
		; alternatively for listview:
		; LV_Modify(LV_GetCount(), "Vis")
		sendmessage, 0x115, 7, 0,, ahk_id %hlb%
	}
return


GuiClose:
esc::
	ExitApp
return
Some more technical info (Thanks Blackholyman!)
http://msdn.microsoft.com/en-us/library ... s.85).aspx
WM_VSCROLL = &H115
Public Enum WM_HSCROLL_low As Short
SB_ENDSCROLL = 8
SB_LEFT = 6
SB_RIGHT = 7
SB_LINELEFT = 0
SB_LINERIGHT = 1
SB_PAGELEFT = 2
SB_PAGERIGHT = 3
SB_THUMBPOSITION = 4
SB_THUMBTRACK = 5
End Enum
Public Enum WM_VSCROLL_low As Short
SB_BOTTOM = 7
SB_ENDSCROLL = WM_HSCROLL_low.SB_ENDSCROLL
SB_LINEDOWN = 1
SB_LINEUP = 0
SB_PAGEDOWN = 3
SB_PAGEUP = 2
SB_THUMBPOSITION = WM_HSCROLL_low.SB_THUMBPOSITION
SB_THUMBTRACK = WM_HSCROLL_low.SB_THUMBTRACK
SB_TOP = 6
End Enum
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
Sjc1000
Posts: 39
Joined: 02 Oct 2013, 02:07

Re: [How To] Scroll listbox, listview and edit controls

17 Nov 2013, 02:38

Nice trick. I also saw this from you on IRC, though i did not fully try it out. Good job. Totally bookmarked this page. :D
Please find me on the IRC if you have any questions, I'm never on the forum anymore.
User avatar
paulrrogers
Posts: 5
Joined: 23 Oct 2014, 15:05
Contact:

Re: [How To] Scroll listbox, listview and edit controls

17 Nov 2014, 14:14

Any way to make this work with Java swing GUIs such as J-edit?
PaulRRogers.com
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: [How To] Scroll listbox, listview and edit controls

17 Nov 2014, 15:11

I have absolutely no idea.
Though, Java GUI's are known to be extremely stubborn and hard to get working with AHK, due to the non-standard controls (thus, they don't really listen to standard events Windows has setup)
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
Guest

Re: [How To] Scroll listbox, listview and edit controls

21 Nov 2014, 13:37

Understood. Thanks for taking the time to share it regardless.

FWIW, also seems that scrolling to top and bottom within an IE page does not recognize these commands.

Return to “Tutorials (v1)”

Who is online

Users browsing this forum: No registered users and 64 guests