标签:idc 右箭头 rac 结构 max psc mask switch bar
实现的结构体为:SCROLLINFO
BOOL CMy4Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMax = 100;
si.nMin = 0;
si.nPage = 10;
m_scrollbar.SetScrollInfo(&si);
}
void CMy4Dlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)// nPos为事件发生的时候,当前Scroll的滚动大小
{
SCROLLINFO sc = { 0 };
sc.cbSize = sizeof(SCROLLINFO);
sc.fMask = SIF_ALL;
m_scrollbar.GetScrollInfo(&sc, true); //初始化窗口中的si结构体赋值给当前sc的结构体
int NewPos = sc.nPos;
switch (nSBCode)
{
case SB_THUMBTRACK: //拖动
NewPos = nPos;
break;
case SB_LINELEFT: //左箭头
NewPos = NewPos - 10;
break;
case SB_LINERIGHT: //右箭头
NewPos = NewPos + 10;
break;
case SB_PAGELEFT: //左拖动行
NewPos = NewPos - sc.nPage;
break;
case SB_PAGERIGHT: //右拖动行
NewPos = NewPos + sc.nPage;
break;
default:
break;
}
bool ret;
ret = m_scrollbar.SetScrollPos(NewPos); //判断是否设置成功
if (NewPos > sc.nMax) {
NewPos = sc.nMax;
}
if (NewPos < sc.nMin) {
NewPos = sc.nMin;
}
wchar_t szbuffer[1024];
SetDlgItemText(IDC_STATIC_1, _itow(NewPos, szbuffer, 10));
CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}
标签:idc 右箭头 rac 结构 max psc mask switch bar
原文地址:https://www.cnblogs.com/zpchcbd/p/12273239.html