Thanks for the great help, benny!!!
If i stop scrolling when nPos reach (si.nMax-si.nPage), the scroll box never reach the bottom of the scroll bar. But i managed to solve it by using (si.nMax-si.nPage+1) instead.
However, if i want the window to be able to scroll till only the last 'p' is on the screen. What should i do? In fact, i tried (si.nMax-si.nPage+2) for experiment and the endless scrolling problem comes again. The window kept printing '.' after the 'p'. I really dont understand where the '.' come from.
oldPos = si.nPos;
newPos = si.nPos + y;
si.nPos = max(0, min(newPos, (si.nMax-si.nPage+1)));
if(si.nPos != oldPos)
SetScrollInfo (hwnd, SB_VERT, &si, TRUE);