I am using a HSCROLL control with WM_HSCROLL to pick up the nPosition of the scrollbar. However, when the app is running, i can drag the scroller to the right, but it resets to the left (0) everytime i let go. How can i make it stay?
Is your code returning %TRUE or some other thing that it is doing that could cause the message to either not be received by Windows or changed?
Please have a look at the following code to see if this helps.
Place this code or what you wish to extract in your WM_HSCROLL Event.
Function FORMMAIN_HSCROLL1_WM_HSCROLL (ControlIndex As Long, hWndForm As Dword, hWndControl As Dword, nScrollCode As Long, nPosition As Long) As Long
'nScrollCode =
'SB_BOTTOM Scrolls To the lower Right.
'SB_ENDSCROLL Ends scroll.
'SB_LINELEFT Scrolls Left by one unit.
'SB_LINERIGHT Scrolls Right by one unit.
'SB_PAGELEFT Scrolls Left by the Width Of the window.
'SB_PAGERIGHT Scrolls Right by the Width Of the window.
'SB_THUMBPOSITION Scrolls To the absolute position. The current position is specified by the nPos parameter.
'SB_THUMBTRACK Drags scroll box To the specified position. The current position is specified by the nPos parameter.
'SB_TOP Scrolls To the upper Left.
Local di, ScrollPos As Long
Local ScrlInfo As SCROLLINFO
'If Large Change Val = 10 then set nMin to 1 and nMax to 109
'to get ScrollPos output of 1 - 100
ScrlInfo.cbSize = SizeOf(ScrlInfo)
ScrlInfo.fMask = %SIF_ALL
di = GetScrollInfo(hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo))
Select Case nScrollCode
Case %SB_LINELEFT
If ScrlInfo.nPos > ScrlInfo.nMin Then Decr ScrlInfo.nPos
Case %SB_LINERIGHT
If ScrlInfo.nPos < ScrlInfo.nMax Then Incr ScrlInfo.nPos
Case %SB_THUMBPOSITION
ScrlInfo.nPos = nPosition
ScrollPos = nPosition
Case %SB_PAGELEFT
If ScrlInfo.nPos > ScrlInfo.nMin + 10 Then
ScrlInfo.nPos = ScrlInfo.nPos - 10
Else
ScrlInfo.nPos = ScrlInfo.nMin
End If
Case %SB_PAGERIGHT
If ScrlInfo.nPos < ScrlInfo.nMax - 10 Then
ScrlInfo.nPos = ScrlInfo.nPos + 10
Else
ScrlInfo.nPos = ScrlInfo.nMax
End If
Case %SB_ENDSCROLL
ScrollPos = GetScrollPos(hWndControl, %SB_CTL)
g_HscrollVal(0) = ScrollPos - 1: 'g_DrawMode = 2
End Select
di = SetScrollInfo(hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo), %True)
End Function
Using the API SetScrollInfo function will ensure the slider remains set at the position identified by the variable ScrollPos.
Regards and good luck
Gian Young
Dataman Barcode Systems Australia