在对话框里加入滚动条,实现滚动效果,想了个简单的调试滚动条消息的方法,先记录下
char * GetScrollText(UINT nSBCode)
{
switch(nSBCode)
{
case SB_ENDSCROLL: // End scroll.
return "结束滚动";
case SB_LINEDOWN: // Scroll one line down.
return "向下一行";
case SB_LINEUP: // Scroll one line up.
return "向上一行";
case SB_PAGEDOWN: // Scroll one page down.
return "向下翻页";
case SB_PAGEUP: // Scroll one page up.
return "向上翻页";
case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
return "滚动到绝对位置,当前位置由nPos给出";
case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
return "拖动到设定位置,当前位置由nPos给出";
case SB_BOTTOM: // Scroll to bottom.
return "滚动到底部";
case SB_TOP: // Scroll to top.
return "滚动到顶部";
default:
return "其他动作";
}
}
void CChannelSetDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
char str[512] = { 0 };
int nCurPos = GetScrollPos(SB_VERT);
int nOffset = 0;
int i = 0;
int nMix, nMax;
bool bDid = false;
SCROLLINFO scrollInfo;
GetScrollInfo(SB_VERT, &scrollInfo);
nMix = scrollInfo.nMin, nMax = scrollInfo.nMax;
sprintf( str, "OnVScroll(UINT %s, UINT %d, GetScrollPos = %d\n", GetScrollText(nSBCode), nPos, nCurPos );
OutputDebugString(str);
switch(nSBCode)
{
case SB_ENDSCROLL: // End scroll.
bDid = true;
break;
case SB_LINEDOWN: // Scroll one line down.
if( nMax == nCurPos )
break;
nOffset = 10;
bDid = true;
break;
case SB_LINEUP: // Scroll one line up.
if( nMix == nCurPos )
break;
nOffset = -10;
bDid = true;
break;
case SB_PAGEDOWN: // Scroll one page down.
nOffset = m_nScrollPageSize;
bDid = true;
break;
case SB_PAGEUP: // Scroll one page up.
nOffset = -m_nScrollPageSize;
bDid = true;
break;
case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
nOffset = nPos - nCurPos;
bDid = true;
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
nOffset = nPos- nCurPos;
bDid = true;
break;
}
nCurPos += nOffset;
SetScrollPos(SB_VERT, nCurPos);
if( true == bDid)
{
for( i = 0; i < m_arrayChannelCtrl.GetSize(); i++ )
{
CChannelCtrl * pChannelCtrl = m_arrayChannelCtrl.GetAt(i);
pChannelCtrl->MoveWindow(this, -nOffset);
};
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
char * GetScrollText(UINT nSBCode)
{
switch(nSBCode)
{
case SB_ENDSCROLL: // End scroll.
return "结束滚动";
case SB_LINEDOWN: // Scroll one line down.
return "向下一行";
case SB_LINEUP: // Scroll one line up.
return "向上一行";
case SB_PAGEDOWN: // Scroll one page down.
return "向下翻页";
case SB_PAGEUP: // Scroll one page up.
return "向上翻页";
case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
return "滚动到绝对位置,当前位置由nPos给出";
case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
return "拖动到设定位置,当前位置由nPos给出";
case SB_BOTTOM: // Scroll to bottom.
return "滚动到底部";
case SB_TOP: // Scroll to top.
return "滚动到顶部";
default:
return "其他动作";
}
}
void CChannelSetDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
char str[512] = { 0 };
int nCurPos = GetScrollPos(SB_VERT);
int nOffset = 0;
int i = 0;
int nMix, nMax;
bool bDid = false;
SCROLLINFO scrollInfo;
GetScrollInfo(SB_VERT, &scrollInfo);
nMix = scrollInfo.nMin, nMax = scrollInfo.nMax;
sprintf( str, "OnVScroll(UINT %s, UINT %d, GetScrollPos = %d\n", GetScrollText(nSBCode), nPos, nCurPos );
OutputDebugString(str);
switch(nSBCode)
{
case SB_ENDSCROLL: // End scroll.
bDid = true;
break;
case SB_LINEDOWN: // Scroll one line down.
if( nMax == nCurPos )
break;
nOffset = 10;
bDid = true;
break;
case SB_LINEUP: // Scroll one line up.
if( nMix == nCurPos )
break;
nOffset = -10;
bDid = true;
break;
case SB_PAGEDOWN: // Scroll one page down.
nOffset = m_nScrollPageSize;
bDid = true;
break;
case SB_PAGEUP: // Scroll one page up.
nOffset = -m_nScrollPageSize;
bDid = true;
break;
case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
nOffset = nPos - nCurPos;
bDid = true;
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
nOffset = nPos- nCurPos;
bDid = true;
break;
}
nCurPos += nOffset;
SetScrollPos(SB_VERT, nCurPos);
if( true == bDid)
{
for( i = 0; i < m_arrayChannelCtrl.GetSize(); i++ )
{
CChannelCtrl * pChannelCtrl = m_arrayChannelCtrl.GetAt(i);
pChannelCtrl->MoveWindow(this, -nOffset);
};
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
转载于:https://blog.51cto.com/xulin/65569