Hi,
I need to set the client's area of ListBox to a particular scroll position.
I'm using SetScrollInfo. But it is only set the scrollbar's thumb (without redraw). It doesn't move (scroll) the client's area. What do I need to use?
Don't suggest me ListBox.ListIndex (because in my case it should be outside of the range of required scrolling position).
Thanks.
I need to set the client's area of ListBox to a particular scroll position.
I'm using SetScrollInfo. But it is only set the scrollbar's thumb (without redraw). It doesn't move (scroll) the client's area. What do I need to use?
Don't suggest me ListBox.ListIndex (because in my case it should be outside of the range of required scrolling position).
Code:
Option Explicit
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End Type
Private Const SB_CTL As Long = 2&
Private Const SB_HORZ As Long = 0&
Private Const SB_VERT As Long = 1&
Private Const SIF_DISABLENOSCROLL As Long = 8&
Private Const SIF_PAGE As Long = 2&
Private Const SIF_POS As Long = 4&
Private Const SIF_RANGE As Long = 1&
Private Const SIF_TRACKPOS As Long = &H10&
Private Const SIF_ALL As Long = 1 Or 2 Or 4 Or &H10&
Private Declare Function GetScrollInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal nBar As Long, ByVal lpsi As Long) As Long
Private Declare Function SetScrollInfo Lib "user32.dll" (ByVal hwnd As Long, ByVal nBar As Long, ByVal lpsi As Long, redraw As Long) As Long
Private Sub Form_Load()
'fill listbox
Dim i&
For i = 1 To 100: lst.AddItem i: Next
Dim si As SCROLLINFO
si.cbSize = LenB(si)
'doing something... moving scroll to desired position
'saving position
'si.fMask = SIF_TRACKPOS
'GetScrollInfo lst.hWnd, SB_VERT, VarPtr(si)
'...
'breaking position
lst.ListIndex = 0
'
'restoring position
si.fMask = SIF_POS
'si.nPos = si.nTrackPos
si.nPos = 80
SetScrollInfo lst.hwnd, SB_VERT, VarPtr(si), 1&
End Sub