Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Example] Endless scrolling in a listbox


  • Please log in to reply
3 replies to this topic
SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
This is something I came up with, if there is a better way feel free to modify. It uses various sendmessages to get the position in the listbox and change it.
; an example of an listbox which you can endlessly scroll, after
; it reaches the last item in the listbox it jumps back the 
; first and vice versa
; 
GUITitle=Endless Listbox
Loop, 25 ; create test list
	{
	ListBoxItems.= A_Index "|"
	}
StringTrimRight, ListBoxItems, ListBoxItems, 1 ; trim trailing |

Gui, Add, ListBox, x5 y5 w100 h200,%ListBoxItems%
Gui, Show,, %GUITitle%
Return

#IfWinActive, Endless Listbox
Up::
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
PreviousPos:=ErrorLevel+1
ControlSend, ListBox1, {Up}, %GUITitle%
SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
ItemsInList:=ErrorLevel
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
ChoicePos:=ErrorLevel+1
If (ChoicePos = PreviousPos)
	{
	SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
	SendMessage, 390, (Errorlevel-1), 0, ListBox1, %GUITitle%  ; LB_SETCURSEL = 390
	}
Return

Down::
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
PreviousPos:=ErrorLevel+1
SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
ItemsInList:=ErrorLevel
ControlSend, ListBox1, {Down}, %GUITitle%
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
ChoicePos:=ErrorLevel+1
If (ChoicePos = PreviousPos)
	SendMessage, 390, 0, 0, ListBox1, %GUITitle%  ; LB_SETCURSEL = 390 - position 'one'
Return

GuiEscape:		; ESC
GuiClose:		; Program is closed
ExitApp

Edit: See also

[Example] Endless scrolling in a listview
<!-- m -->http://www.autohotke...ic.php?p=272892<!-- m -->

TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
Can you make it so that the scroll wheel does this as well? By this I mean, the scroll wheel still controls the scroll bar, but when it reaches the end of the list it just to the beginning.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
If there is a way to get the position of the scrollbar so we can check if it has reached the end I'm sure it could be done. I'll have a look at the SB_ wm_commands ...

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Here is an example with wheel Up & Down. Uses the same "method".
Currently I use A Loop to move the scrollbar to the top/bottom.
Perhaps there is SendMessage that does this in one go.
; an example of a listbox which you can endlessly scroll, after
; it reaches the last item in the listbox it jumps back the 
; first and vice versa
; 
GUITitle=Endless Listbox
Loop, 25 ; create test list
	{
	ListBoxItems.= A_Index "|"
	}
StringTrimRight, ListBoxItems, ListBoxItems, 1 ; trim trailing |

Gui, Add, ListBox, x5 y5 w100 h200,%ListBoxItems%
Gui, Show,, %GUITitle%
Return

#IfWinActive, Endless Listbox

WheelDown::
ControlGet, ChildHWND, Hwnd,, ListBox1, %GUITitle%
PreviousScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
SendMessage, 0x115, 1, 0, ListBox1, %GUITitle% ;  Scroll down (0x115 is WM_VSCROLL).
CurrentScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
If (CurrentScrollPos = 0)
  Return 
If (CurrentScrollPos = PreviousScrollPos)
  Loop
  {
  SendMessage, 0x115, 0, 0, ListBox1, %GUITitle% ; Scroll up (0 vs. 1 causes SB_LINEUP vs. DOWN)
  CurrentScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
  If (CurrentScrollPos = 0)
    Break 
  }
Return

WheelUp::
ControlGet, ChildHWND, Hwnd,, ListBox1, %GUITitle%
PreviousScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
SendMessage, 0x115, 0, 0, ListBox1, %GUITitle% ; Scroll up (0 vs. 1 causes SB_LINEUP vs. DOWN)
CurrentScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
If (CurrentScrollPos = 0)
  Loop
  {
  PreviousScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
  SendMessage, 0x115, 1, 0, ListBox1, %GUITitle% ;  Scroll down (0x115 is WM_VSCROLL).
  CurrentScrollPos:=DllCall("GetScrollPos", "UInt", ChildHWND, "Int", 1)  ;  Last parameter is 1 for SB_VERT, 0 for SB_HORZ.
  If (CurrentScrollPos = PreviousScrollPos)
    Break 
  }
Return

Up::
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
PreviousPos:=ErrorLevel+1
ControlSend, ListBox1, {Up}, %GUITitle%
SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
ItemsInList:=ErrorLevel
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
ChoicePos:=ErrorLevel+1
If (ChoicePos = PreviousPos)
	{
	SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
	SendMessage, 390, (Errorlevel-1), 0, ListBox1, %GUITitle%  ; LB_SETCURSEL = 390
	}
Return

Down::
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
PreviousPos:=ErrorLevel+1
SendMessage, 0x18b, 0, 0, ListBox1, %GUITitle%  ; 0x18b is LB_GETCOUNT (for a ListBox).
ItemsInList:=ErrorLevel
ControlSend, ListBox1, {Down}, %GUITitle%
SendMessage, 0x188, 0, 0, ListBox1, %GUITitle%  ; 0x188 is LB_GETCURSEL (for a ListBox).
ChoicePos:=ErrorLevel+1
If (ChoicePos = PreviousPos)
	SendMessage, 390, 0, 0, ListBox1, %GUITitle%  ; LB_SETCURSEL = 390 - position 'one'
Return

GuiEscape:		; ESC
GuiClose:		; Program is closed
ExitApp