如何让CEdit正确滚动?

时间:2009-10-06 15:36:50

标签: mfc scroll artifacts cedit

我有一个CEdit控件,用于显示诊断输出 有时数据会溢出屏幕大小,因此我自然将Vertical Scroll属性设置为true(MFC对话框编辑器)。

但是,当我尝试滚动窗口中的文本之前没有清除,并且新文本被写在上面。

结果是我滚动过去的一切都很糟糕。

我已经找了一个绘制背景属性或类似的东西,它会在滚动时擦除窗口中的所有内容(在重新绘制新数据之前)。

有什么建议吗?

3 个答案:

答案 0 :(得分:2)

我认为您可能希望将自动VScroll 多行设置为true,将自动HScroll 设置为false。

答案 1 :(得分:1)

我们遇到了类似的问题。当我们得到WM_VSCROLL时,我们最终必须使父窗口的区域无效以使其更新。我试图这样做,因为用户demorge在这里说:

SetBkMode(hdc, TRANSPARENT) doesn't work

但是我们的代码没有使用句柄,我们实际上使用CWnd类,所以我们最终在WindowProc中这样做了:

switch(message)
{
...
case WM_VSCROLL:
case WM_HSCROLL:
  LRESULT answer;
  PAINTSTRUCT ps;
  CDC* pdc;
  CWnd* MyParentHWnd;

  // We want the scroll to work the same way it has always worked for our
  // ancestor class.  Let them handle the scrolling and save off their
  // return.
  answer = AncestorClass::WindowProc(message, wParam, lParam);

  pdc = BeginPaint(&ps);
  // DO NOT change the assignement operator in the conditional below to an
  // equality operator.  We are actually trying to get the parent window and
  // and storing locally, and then verifying that we didn't get back null.
  // This is a purposeful design decision.
  if (MyParentHWnd = GetParent()){
     RECT MyRect;
     GetClientRect(&MyRect);
     ClientToScreen(&MyRect);
     MyParentHWnd->ScreenToClient(&MyRect);
     MyParentHWnd->InvalidateRect(&MyRect);
  }

  EndPaint(&ps);

  return answer;
  break;
...
}

当然,我不得不对它进行一般化。我只是想让你知道是的,还有其他人看到了你的问题,我们找到了解决方法。

答案 2 :(得分:0)

我用VS2005测试了这个,它随MFC 8.0一起提供。我无法复制你的问题。

我在基于对话框的应用程序中添加了一个CEdit和一个CRichEditCtrl。已更改属性Multiline,Auto VSCroll和Vertical Scroll为true。使用SetWindowText方法将loooooong文本字符串放入其中。我启动了应用程序并且文本滚动得很好。

你做了哪些不同的事?

只是为了确定。你没有使用SetCaretPos方法,是吗?在MSDN页面中有一些关于这一点的说明。这是Knowledge Base article

相关问题