dialog框的滚动条事件问题

laojintt 2005-07-15 10:30:03
我在我的dialog框的OnVScroll方法内写了下面的事件,用来处理在滚动条变化时刷新屏幕,第一次屏幕显示时不会出现问题,第二次以后,拉动滚动条,屏幕刷新就出问题了,屏幕上方出现了一片空白,请大家帮我看看哪里出问题了,或者哪位有正确的代码,贴出来看看阿.
void CJdcxcfjds::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
int minpos;
int maxpos;
int postmp1;
LPRECT rects=new RECT;
CRect rect;
CDC hdc,memDC;
//CDialog::GetWindowRect(rects);

// int len=((rects->bottom) - (rects->top));

CDialog::SetScrollRange(SB_VERT,0,330,true);
CDialog::GetScrollRange(SB_VERT,&minpos, &maxpos);
maxpos = CDialog::GetScrollLimit(SB_VERT);
//maxpos = pScrollBar->GetScrollLimit();




static int curpos = CDialog::GetScrollPos(SB_VERT);
//curaddlian=&curpos;
SCROLLINFO info;


switch (nSBCode)
{
case SB_TOP: // Scroll to far left.

curpos = minpos;

CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
break;

case SB_BOTTOM: // Scroll to far right.
curpos = maxpos;

CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
break;

case SB_ENDSCROLL: // End scroll.
break;

case SB_LINEUP: // Scroll left.
if (curpos > minpos)
{
curpos-=10;

CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
break;

case SB_LINEDOWN: // Scroll right.
//if(maxpos==101){AfxMessageBox(_T("i am here"));}
if (curpos < maxpos)
{
curpos+=10;
//AfxMessageBox(_T("ok here"));

CDialog::ScrollWindowEx(0,nPos-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
//AfxMessageBox(_T("linedown"));
break;

case SB_PAGEUP: // Scroll one page left.
// Get the page size.

//pScrollBar->GetScrollInfo(&info, SIF_ALL);
CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL);

if (curpos > minpos)
{
//curpos = max(minpos, curpos - (int) info.nPage);
curpos = max(minpos, curpos - 10);

CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
break;

case SB_PAGEDOWN: // Scroll one page right.
//pScrollBar->GetScrollInfo(&info, SIF_ALL);
CDialog::GetScrollInfo(SB_VERT,&info, SIF_ALL);

if (curpos < maxpos)
{
curpos = min(maxpos, curpos + (int) info.nPage);

curpos = min(maxpos, curpos + 10);
CDialog::ScrollWindowEx(0,-10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
break;

case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
postmp1=nPos;
if(curpos<postmp1)
{

curpos = nPos; // of the scroll box at the end of the drag
// operation.

CDialog::ScrollWindowEx(0,-10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
if(curpos>postmp1)
{

curpos = nPos; // of the scroll box at the end of the drag
// operation.

CDialog::ScrollWindowEx(0,10,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
}
break;

case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is
int postmp2=curpos;
curpos = nPos; // position that the scroll box has been dragged
// to.

CDialog::ScrollWindowEx(0,postmp2-curpos,NULL,NULL,NULL,NULL,SW_SCROLLCHILDREN);
CDialog::UpdateWindow();
CDialog::SetScrollPos(SB_VERT,curpos,true);
break;
}

UpdateData(FALSE);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}


请帮忙解决一下,我对vc还不是很熟悉.
...全文
199 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
allenhiman 2005-07-16
没有重绘窗口的问题
在最后的UpdateDate(false)
后加上
Invalidate();
回复
laojintt 2005-07-15
没人啊
回复
快乐鹦鹉 2005-07-15
代码太长了。看起来不方便。
不如将代码发到happyparrot@126.com
直接调试比较清楚
回复
相关推荐
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2005-07-15 10:30
社区公告
暂无公告