Scrollbar moves back after WM_VSCROLL
I have a window with its own H and V scrolling. I'm handling the event like this:
case WM_VSCROLL:
S开发者_Go百科etScrollPos(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 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
andSB_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
andSB_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
andSB_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.
In the case section, the system is processing a WM_VSCROLL message. It will run the default window procedure after your SetScrollPos. In the default window procedure, the system itself will set the scroll bar's thumb position. So, although SetScrollPos takes effects, the system change the thumb position after that anyway. I think you should do your SetScrollPos after calling the default window procedure, i.e., maybe after returning this funciton, and then you can SetScrollPos.
精彩评论