Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar moves back after WM_VSCROLL

Tags:

c++

c

winapi

I have a window with its own H and V scrolling. I'm handling the event like this:

case WM_VSCROLL:

        SetScrollPos(hWnd, SB_VERT, (int)HIWORD(wParam), TRUE);

        break;

all I want is for the position of the scroll bar to stay once I release my mouse but what it's doing is just going back to the top after. What am I doing wrong?

Thanks

like image 530
jmasterx Avatar asked Oct 19 '25 00:10

jmasterx


1 Answers

The wParam parameter of the WM_VSCROLL message is either SB_TOP, SB_BOTTOM, SB_PAGEUP, SB_PAGEDOWN, SB_LINEUP, SB_LINEDOWN, SB_THUMBPOSITION, or SB_THUMBTRACK, where the names ought to explain themselves.

  • SB_TOP and SB_BOTTOM means that the scrolling window is to go to the top or bottom, respectively. These messages can be sent by right-clicking a vertical scroll bar and selecting "Top" and "Bottom". (Look in Windows Notepad, Win XP+, for instance.)

  • SB_PAGEUP and SB_PAGEDOWN means a page (screen) up or down. These are sent if you click somwhere on the scrollbar beside on the thumb or the up or down arrows, or if you use the scrollbar's right-click menu.

  • SB_LINEUP and SB_LINEDOWN are sent when the user clicks the up and down buttons on the scrollbar, or selects the appropriate right-click menu commands.

  • SB_THUMBTRACK is sent continuously when the user scrolls by dragging the thumb of the scrollbar.

  • SB_THUMBPOSITION is sent when the user has released the thumb.

See the MSDN article WM_VSCROLL for more information.

So, when you receive a WM_VSCROLL message, you first need to do the scrolling itself. If, for instance, you are writing a text editor, then you need to redraw the text, but with a different row at the top of the window. Then you need to update the scrollbar to its new position, preferably by means of SetScrollInfo, but you can also use the old SetScrollPos function.

like image 142
Andreas Rejbrand Avatar answered Oct 21 '25 16:10

Andreas Rejbrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!