这段代码不是做水平滚动而是做垂直滚动,请给我任何建议我做错了什么。我想做水平滚动。
void CFormGridColumnPreviewDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int nDelta;
int nMaxPos = m_rcOriginalRect.Width() - m_nCurWidth;
switch (nSBCode)
{
case SB_LINERIGHT:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos);
break;
case SB_LINELEFT:
if (m_nScrollPos <= 0)
return;
nDelta = -min(max(nMaxPos/20,5),m_nScrollPos);
break;
case SB_PAGERIGHT:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(max(nMaxPos/10,5),nMaxPos-m_nScrollPos);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_nScrollPos;
break;
case SB_PAGELEFT:
if (m_nScrollPos <= 0)
return;
nDelta = -min(max(nMaxPos/10,5),m_nScrollPos);
break;
default:
return;
}
m_nScrollPos += nDelta;
SetScrollPos(SB_HORZ,m_nScrollPos,TRUE);
ScrollWindow(0,-nDelta);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CFormGridColumnPreviewDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_nCurWidth = cx;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMin = 0;
si.nMax = m_rcOriginalRect.Width();
si.nPage = cx;
si.nPos = 0;
SetScrollInfo(SB_HORZ, &si, TRUE);
}