How do I make a scrollable window using windows API? I've sen't the WS_VSCROLL message to my windows so it shows the scrollbar. However the form doesn't actually scroll and everytime I pull the bar down it returns to the top
Printable View
How do I make a scrollable window using windows API? I've sen't the WS_VSCROLL message to my windows so it shows the scrollbar. However the form doesn't actually scroll and everytime I pull the bar down it returns to the top
You have to implement all that, including setting the scroll bar position.
All your doing right now is telling the window to create the scroll bar(s) but the window doesn't know what to do so you'll need to handle the WM_VSCROLL message to suite your needs.
To keep the scrollbar from moving back to 0,
You just need to handle some sub messages within WM_VSCROLL, SB_THUMBPOSITION simply saves the new position in the hi order word of the wParam, after the user finishes dragging.Code:case WM_VSCROLL:
{
static int scrollPos = HIWORD(wParam);
if (LOWORD(wParam) == SB_THUMBPOSITION)
{
scrollPos = HIWORD(wParam);
}
SetScrollPos(hWnd, SB_VERT, scrollPos, TRUE);
return 0;
}break;
scrollPos= HIWORD(wParam);
if (LOWORD(wParam) == SB_THUMBPOSITION)
{
scrollPos = HIWORD(wParam);
s= HIWORD(wParam);
}
SetScrollPos(hwnd, SB_VERT, 15, TRUE);
tried this as well
SetScrollPos(hwnd, SB_CTL, 15, TRUE);
return 0;
It still doesn't set the pos
Did you create the scroll bar by specifying WS_VSCROLL when creating the Window?
Is it a scroll bar of a child window? If so you'll probably need the HWND of that child.
Don't ask me way iall of a sudden it started working again LOL.
case WM_VSCROLL:
if (LOWORD(wParam) == SB_THUMBPOSITION)
{
s= HIWORD(wParam);
}
SetScrollPos(scroll, SB_CTL, s, TRUE);
diff = s - scrollPos;
scrollPos=s;
ScrollWindowEx(dialog,0,-diff,NULL,NULL,NULL,NULL, SW_INVALIDATE);
//SetScrollPos(hwnd, SB_CTL, scrollPos, TRUE);
UpdateWindow(dialog);
break;
Tried SW_ERASE as well
Two issues with this piece of code:
1)The 1st time I click on the scroll to scroll dowmwards it seems to jump down to the bottom then back up again even though I haven't even started dragging yet
2)ScrollWindowEx doesn't scroll smoothly. It leaves marks behind on the window
Idecided to use the setwindowpos to emulate scrolling