Something like this?
The gadget generates a #WM_NOTIFY message when a scroll starts with a NMHDR\Code value of #LVN_BEGINSCROLL or #LVN_ENDSCROLL when one ends. An #WM_NOTIFY/#LVN_ENDSCROLL message occurs when an arrow is clicked or a non-grip (page scroll) click occurs. I've then used GetScrollInfo_ to obtain the current state of the scroll. See
https://learn.microsoft.com/en-us/windo ... scrollinfo and
https://learn.microsoft.com/en-us/windo ... crollinfo
.
If the position (SCROLLINFO\nPos) is over 75% of the current maximum (SCROLLINFO\nMax) I generate a custom event to call for more data.
In practice you will need to be a little more refined than this solution:
1) You'll need to adjust your threshold value. It will need to be lower when there are a small number of entries in the list, otherwise you might not trigger an event. But you'll want to make it tighter when there are larger numbers of entries, otherwise you will generate a request too early.
2) You'll need to 'debounce' the event, otherwise dragging the slider to the end of the bar will generate multiple events in a row.
3) You'll need to differentiate on hWnd too, you'll be getting #WM_Notify messages from other sources as well.
Code: Select all
#ProportionOfMax = 0.75
#Custom_Event_MoreData = #PB_Event_FirstCustomValue
Global Window_0, ListIcon_0, Counter
Declare ResizeGadgetsWindow_0()
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
; Windows fills the parameter automatically, which we will use in the callback...
Define.SCROLLINFO ListScrollInfo
Define.NMHDR *nm
If uMsg = #WM_NOTIFY
*nm = LParam
If *nm\code = #LVN_ENDSCROLL
ListScrollInfo\fMask = #SIF_ALL
GetScrollInfo_(GadgetID(ListIcon_0), #SB_VERT, @ListScrollInfo)
If ListScrollInfo\nPos >= (ListScrollInfo\nMax * #ProportionOfMax)
PostEvent(#Custom_Event_MoreData, Window_0, ListIcon_0)
EndIf
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu)
ListIcon_0 = ListIconGadget(#PB_Any, 10, 10, 580, 380, "Column 1", 200)
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(Window_0)
FormWindowHeight = WindowHeight(Window_0)
ResizeGadget(ListIcon_0, 10, 10, FormWindowWidth - 20, FormWindowHeight - 20)
EndProcedure
Procedure AddMore()
Debug "More stuff needed!"
For x = 1 To 100
AddGadgetItem(ListIcon_0, -1, "This is item #" + StrU(Counter) + ".")
Counter + 1
Next x
EndProcedure
OpenWindow_0(50, 50)
AddMore()
SetWindowCallback(@WinCallback())
Repeat
Event = WaitWindowEvent()
If Event = #Custom_Event_MoreData
AddMore()
EndIf
Until Event = #PB_Event_CloseWindow