Click to See Complete Forum and Search --> : Scrollable window
crapdev
December 15th, 2007, 05:34 PM
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
kirants
December 15th, 2007, 11:50 PM
You have to implement all that, including setting the scroll bar position.
Notsosuperhero
December 16th, 2007, 12:08 AM
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 (http://msdn2.microsoft.com/en-us/library/bb787577.aspx) message to suite your needs.
To keep the scrollbar from moving back to 0,
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;
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.
crapdev
December 16th, 2007, 12:10 PM
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
Notsosuperhero
December 16th, 2007, 12:48 PM
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.
crapdev
December 16th, 2007, 04:58 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.