case WM_VSCROLL:
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_VERT, &si);
iVertPos = si.nPos;
switch (LOWORD(wParam))
{
case SB_TOP:
si.nPos = si.nMin;
break;
case SB_BOTTOM:
si.nPos = si.nMax;
break;
case SB_LINEUP:
si.nPos -= 1;
break;
case SB_LINEDOWN:
si.nPos += 1;
break;
case SB_PAGEUP:
si.nPos -= cyClient / cyChar;
break;
case SB_PAGEDOWN:
si.nPos += cyClient / cyChar;
break;
case SB_THUMBTRACK:
si.nPos = si.nTrackPos;
break;
default:break;
}
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
if (si.nPos != iVertPos)
{
ScrollWindow(hwnd, 0, cyChar*(iVertPos - si.nPos), NULL, NULL);
UpdateWindow(hwnd);//為什麼這兒用了update後面沒有用 這兒刪除 效果上感覺沒有變化。
}
return 0;
case WM_HSCROLL:
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_HORZ, &si);
iHorzPos = si.nPos;
switch (LOWORD(wParam))
{
case SB_TOP:
si.nPos = si.nMin;
break;
case SB_BOTTOM:
si.nPos = si.nMax;
break;
case SB_LINELEFT:
si.nPos -= 1;
break;
case SB_LINERIGHT:
si.nPos += 1;
break;
case SB_PAGELEFT:
si.nPos -= cxClient / cxChar;
break;
case SB_PAGERIGHT:
si.nPos += cxClient / cxChar;
break;
case SB_THUMBPOSITION:
si.nPos = si.nTrackPos;
break;
default:
break;
}
si.fMask = SIF_POS;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
GetScrollInfo(hwnd, SB_HORZ, &si);
if (si.nPos != iHorzPos)
{
ScrollWindow(hwnd, cxChar*(iHorzPos - si.nPos), 0, NULL, NULL);//此處有疑問 為什麼不需要update而前面需要。
}
return 0;
估計是作者忘記刪除上面的了。這兩個代碼,一個是垂直滾動,一個是水平滾動,僅僅這點差異。