Win32 Scrolling Examples

Can someone point me (or provide?) Some nice, clear examples of how to implement scrolling in Win32? Obviously, Google reveals a lot of things, but most of the examples seem too simple or too complicated for me to be sure that they demonstrate the correct way to do things. I am using LispWorks CAPI (cross-platform Common Lisp GUI lib) in my current project, and on Windows I have a hard-to-scroll scroll error; basically I want to do some tests directly through the Win32 API to see if I can shed some light on the situation.

Thanks a lot, Christopher

+5
source share
1 answer

I think you say, for example, how to handle the WM_VSCROLL / WM_HSCROLL event. If this is the first step, you need to handle this event. You should not use the HIWORD value (wParam) of this call, but use the GetScrollInfo, GetScrollPos, and GetScrollRange functions instead.

The following is an example of code cut off by MSDN - using scrollbars . xCurrentScroll is defined before by calling, for example, GetScrollPos ().

int xDelta; // xDelta = new_pos - current_pos int xNewPos; // new position int yDelta = 0; switch (LOWORD(wParam)) { // User clicked the scroll bar shaft left of the scroll box. case SB_PAGEUP: xNewPos = xCurrentScroll - 50; break; // User clicked the scroll bar shaft right of the scroll box. case SB_PAGEDOWN: xNewPos = xCurrentScroll + 50; break; // User clicked the left arrow. case SB_LINEUP: xNewPos = xCurrentScroll - 5; break; // User clicked the right arrow. case SB_LINEDOWN: xNewPos = xCurrentScroll + 5; break; // User dragged the scroll box. case SB_THUMBPOSITION: xNewPos = HIWORD(wParam); break; default: xNewPos = xCurrentScroll; } [...] // New position must be between 0 and the screen width. xNewPos = max(0, xNewPos); xNewPos = min(xMaxScroll, xNewPos); [...] // Reset the scroll bar. si.cbSize = sizeof(si); si.fMask = SIF_POS; si.nPos = xCurrentScroll; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); 
0
source

Source: https://habr.com/ru/post/1308607/


All Articles