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
The
wParamparameter of theWM_VSCROLLmessage is eitherSB_TOP,SB_BOTTOM,SB_PAGEUP,SB_PAGEDOWN,SB_LINEUP,SB_LINEDOWN,SB_THUMBPOSITION, orSB_THUMBTRACK, where the names ought to explain themselves.SB_TOPandSB_BOTTOMmeans 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_PAGEUPandSB_PAGEDOWNmeans 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_LINEUPandSB_LINEDOWNare sent when the user clicks the up and down buttons on the scrollbar, or selects the appropriate right-click menu commands.SB_THUMBTRACKis sent continuously when the user scrolls by dragging the thumb of the scrollbar.SB_THUMBPOSITIONis 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.