void CScrollDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CRect rcClient;
GetClientRect(&rcClient);
int nCurPos = GetScrollPos(SB_VERT);
int nPrevPos = nCurPos;
switch (nSBCode)
{
case SB_TOP:
nCurPos = 0;
break;
case SB_BOTTOM:
nCurPos = GetScrollLimit(SB_VERT) - 1;
break;
case SB_LINEUP:
nCurPos = max(nCurPos - 6, 0);
break;
case SB_LINEDOWN:
nCurPos = min(nCurPos + 6, GetScrollLimit(SB_VERT) - 1);
break;
case SB_PAGEUP:
nCurPos = max(nCurPos - rcClient.Height(), 0);
break;
case SB_PAGEDOWN:
nCurPos = min(nCurPos + rcClient.Height(), GetScrollLimit(SB_VERT) - 1);
break;
case SB_THUMBTRACK:
nCurPos = nPos;
break;
}
ScrollWindow(0, nPrevPos - nCurPos, NULL, NULL);
SetScrollPos(SB_VERT, nCurPos, TRUE);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CScrollDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CRect rcClient;
GetClientRect(&rcClient);
int nCurPos = GetScrollPos(SB_HORZ);
int nPrevPos = nCurPos;
switch( nSBCode )
{
case SB_LEFT:
nCurPos = 0;
break;
case SB_RIGHT:
nCurPos = GetScrollLimit(SB_HORZ) - 1;
break;
case SB_LINELEFT:
nCurPos = max(nCurPos - 6, 0);
break;
case SB_LINERIGHT:
nCurPos = min(nCurPos + 6, GetScrollLimit(SB_HORZ) - 1);
break;
case SB_PAGELEFT:
nCurPos = max(nCurPos - rcClient.Width(), 0);
break;
case SB_PAGERIGHT:
nCurPos = min(nCurPos + rcClient.Width(), GetScrollLimit(SB_HORZ) - 1);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nCurPos = nPos;
break;
}
ScrollWindow(nPrevPos - nCurPos, 0, NULL, NULL);
SetScrollPos(SB_HORZ, nCurPos, TRUE);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}