0

I have a CEdit control that's used to display a diagnostics output.
Sometimes the data overflows the screen size, so naturally I set the Vertical Scroll property to true (MFC dialog editor).

But then, when I tried to scroll the text that was in the window before isn't cleared and the new text is written over it.

The result is a big mess of everything I have scrolled past.

I've looked for a draw background property or something similar that will erase everything in the window while scrolling (before redrawing the new data).

Any suggestions?

CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140

3 Answers3

2

I think you might want to set Auto VScroll and Multiline to true, and Auto HScroll to false.

djeidot
  • 4,542
  • 4
  • 42
  • 45
1

We were having a similar problem. We ended up having to invalid the region of the parent window to get it to update when we got WM_VSCROLL. I tried to do as user demorge says here:

SetBkMode(hdc, TRANSPARENT) doesn't work

But our code doesn't use handles, we actually use the class CWnd, so we ended up doing this in the WindowProc instead:

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;
...
}

Of course, I had to genericize it a little bit. I just wanted you to know that yes, there are other people that are seeing your problem, and we found how to fix it.

Community
  • 1
  • 1
Charles
  • 31
  • 5
0

I tested this with VS2005, which ships with MFC 8.0. I couldn't replicate your problem.

I added one CEdit and one CRichEditCtrl to a dialog based app. Changed properties Multiline, Auto VSCroll and Vertical Scroll to true. Used SetWindowText-method to put loooooong string of text to both of them. I started the app and text scrolled just fine.

What did you do differently?

Just to be sure. You didn't use the SetCaretPos-method, did you? There was some note about that in the MSDN page. Here's the Knowledge Base article.

Rope
  • 41
  • 1
  • 1
  • 7
  • I seem to recall seeing the SetCaretPos method in the code somewhere, I'll check when I get back to work. Thanks for the tip. – CodeFusionMobile Oct 13 '09 at 02:24
  • Also, I am working with 2003 because it's old code, so that may effect it as well. – CodeFusionMobile Oct 13 '09 at 15:27
  • Added direct link to Knowledge Base article regarding SetCaretPos. Sadly, it doesn't describe possible symptoms of using SetCaretPos in CEdit. Article was written for MFC 4.2 which was used in Visual C++ 4.2, so maybe it has been fixed since then. Try it on and let us know. – Rope Oct 14 '09 at 11:20