 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
HugoV
Joined: 27 May 2007 Posts: 378
|
Posted: Fri May 09, 2008 3:38 pm Post subject: [Example] Endless scrolling in a listbox |
|
|
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.
| Code: | ; 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
|
|
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 360
|
Posted: Fri May 09, 2008 3:49 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 378
|
Posted: Fri May 09, 2008 4:05 pm Post subject: |
|
|
| 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 ... |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 378
|
Posted: Tue May 13, 2008 8:34 am Post subject: |
|
|
edit: see below...
Last edited by HugoV on Thu May 15, 2008 3:23 pm; edited 1 time in total |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 378
|
Posted: Tue May 13, 2008 8:39 am Post subject: |
|
|
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.
| Code: | ; 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
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|