Scrollbar snaps back to 0 everytime the value is changed with the mouse

Started by jcmatt, February 21, 2009, 05:55:54 PM

Previous topic - Next topic

jcmatt

Hi,

Example of problem:

I put a vertical scrollbar on a form, give it Min  0, Max 100, SmallChange of 1 and LargeChange of 10.

Run the program and everytime I click the up & down arrows or move the thumbbar it snaps back to 0.

What am I missing?

Jim

TechSupport

Hi Jim,

Sorry for the late response... I didn't notice your post until this morning.

You need to set the scrollbar position in the WM_VSCROLL message handler. There are a couple of posts on the forum about this (I think). Here is code that will handle your vertical scrollbar.


Function FORM1_VSCROLL1_WM_VSCROLL ( _
                                   ControlIndex  As Long,  _  ' index in Control Array
                                   hWndForm      As Dword, _  ' handle of Form
                                   hWndControl   As Dword, _  ' handle of Control
                                   nScrollCode   As Long,  _  ' scroll bar value
                                   nPosition     As Long   _  ' current scroll bar position
                                   ) As Long

   'nScrollCode
   '-----------------------------------------------
   'SB_BOTTOM          Scrolls To the lower Right.
   'SB_ENDSCROLL       Ends scroll.
   'SB_LINEUP          Scrolls Up by one unit.
   'SB_LINEDOWN        Scrolls Down by one unit.
   'SB_PAGEUP          Scrolls Up by the Width Of the window.
   'SB_PAGEDOWN        Scrolls Down by the Width Of the window.
   '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 ScrlInfo As SCROLLINFO   
   Local st       As String
   

   ScrlInfo.cbSize = SizeOf(ScrlInfo)
   ScrlInfo.fMask = %SIF_ALL
   GetScrollInfo hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo)
   
   
   Select Case nScrollCode

      Case %SB_LINEUP:         Decr ScrlInfo.nPos
      Case %SB_LINEDOWN:       Incr ScrlInfo.nPos
      Case %SB_THUMBPOSITION:  ScrlInfo.nPos = nPosition
      Case %SB_PAGEUP:         ScrlInfo.nPos = ScrlInfo.nPos - ScrlInfo.nPage
      Case %SB_PAGEDOWN:       ScrlInfo.nPos = ScrlInfo.nPos + ScrlInfo.nPage

      Case %SB_LINELEFT:
      Case %SB_LINERIGHT:
      Case %SB_PAGELEFT
      Case %SB_PAGERIGHT
      Case %SB_ENDSCROLL

   End Select
   
   SetScrollInfo hWndControl, %SB_CTL, ByVal VarPtr(ScrlInfo), %TRUE
   
   
End Function


jcmatt

Hi Paul,

I was only off by a couple hundred statements in my WM_VSCROLL handler.  I did look at a whole bunch of Forum posts (must have been over at the PowerBasic forum) and saw nothing like the great code you provided but did find one post with the same question that had one or two useless responses.  This learning curve is a killer; just glad you're around.

Jim

TechSupport

Quote from: jcmatt on February 22, 2009, 12:20:37 PM
This learning curve is a killer; just glad you're around.

:)  That's what I'm here for!

You'll be very surprised in a few months time when you look back on where you started and how far you've come. People complain about the Windows API because of it's size and, supposedly, complexity. Everything takes time to learn and learning small pieces at a time quickly grow into a wealth of knowledge in hardly any time at all.

Mark my words, you'll be a winapi programming force to be reckoned with in 6 months!!!  :D

(Oh, and get your hands on POFFS if you have not already done so. I used to spend hours reading old PB Forum posts in that program when I first started. It is amazing how many programming questions are answered there.)