初始化:
//设置水平滚动条的范围
m_sbHori.SetScrollRange(1, 100);
m_sbHori.SetScrollPos(1);
//设置编辑框初始值数
//SetDlgItemText(IDC_EDIT_V, L"1");
SetDlgItemInt(IDC_EDIT_V, 1);
void CCSrollBarProjectDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
int pos = m_sbHori.GetScrollPos(); //获取水平滚动条当前位置
switch (nSBCode)
{
case SB_LINELEFT: pos = pos - 1; break;
case SB_LINERIGHT: pos = pos + 1; break;
case SB_LEFT: pos = 1; break;
case SB_RIGHT: pos = 100; break;
case SB_THUMBPOSITION: pos = nPos; break;//拖拽最后的位置
case SB_THUMBTRACK: //拖拽过程中
{
SetDlgItemInt(IDC_EDIT_V, nPos);
m_sbHori.SetScrollPos(nPos);
}
break;
default:
{
SetDlgItemInt(IDC_EDIT_V, pos);
m_sbHori.SetScrollPos(pos);
return;
}
}
m_sbHori.SetScrollPos(pos);
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}