在对话框中增加一个滚动条控件,添加相应的相应消息的时候,碰到一个效果。
BOOL CTestDialogProDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
//
SetScrollRange(SB_HORZ, 0, 10);
return TRUE; // return TRUE unless you set the focus to a control
}
竟然出现了整个对话框的滚动条。实际上,就是我使用滚动条错误造成的,在初始化中要改。不是上面代码。
要写成下面的
((CScrollBar*)GetDlgItem(IDC_SCROLLBAR1))->SetScrollRange(0, 10);
滚动条的消息函数就参考MSDN上的示例些就好了。示例代码如下
void CMdiView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// Get the minimum and maximum scroll-bar positions.
int minpos;
int maxpos;
GetScrollRange(SB_HORZ, &