SDI, ScrollView, add OnPaint() for scrollview
in OnPaint()
the problem is when I scroll the view, the background will become dirty.Code:dc.FillSolidRect(CRect(0, 0, 78, 30), RGB(0xff, 0, 0xff));
how to avoid this?
Printable View
SDI, ScrollView, add OnPaint() for scrollview
in OnPaint()
the problem is when I scroll the view, the background will become dirty.Code:dc.FillSolidRect(CRect(0, 0, 78, 30), RGB(0xff, 0, 0xff));
how to avoid this?
Dirty? What do you mean by dirty? Anyway, in an MFC app which uses doc/view, you should do the drawing in OnDraw(), not OnPaint().Quote:
Originally posted by niry
the problem is when I scroll the view, the background will become dirty.
dirty: the background is painted by the same color as the rectQuote:
Originally posted by gstercken
Dirty? What do you mean by dirty? Anyway, in an MFC app which uses doc/view, you should do the drawing in OnDraw(), not OnPaint().
yes, in OnDraw, drawing is performed in device screen, so scroll will not cause background ditry
But in OnPaint, drawing is in logic screen. The drawing area disgards current scroll position. so will make background ditry when scrolling.
I 've solved the problem, that is throught call Invalidate to force the client area invalidate.
you have helped me solving lots of question, really thanks:)
You probably mean device units and logical units. ;) But that's not the reason: It is rather that CView's implementation of OnPaint() call's OnPrepareDC() before calling OnDraw(), which does a lot of additional things in CScrollView's implementation. That's why you shouldn't implement OnPaint() yourself, or you'll never get CScrollView working correctly.Quote:
Originally posted by niry
yes, in OnDraw, drawing is performed in device screen, so scroll will not cause background ditry
But in OnPaint, drawing is in logic screen. The drawing area disgards current scroll position. so will make background ditry when scrolling.
I 've get the scrollview working correctly:)Quote:
Originally posted by gstercken
You probably mean device units and logical units. ;) But that's not the reason: It is rather that CView's implementation of OnPaint() call's OnPrepareDC() before calling OnDraw(), which does a lot of additional things in CScrollView's implementation. That's why you shouldn't implement OnPaint() yourself, or you'll never get CScrollView working correctly.
Call Invalidate in OnPaint()
I know OnPrepareDC(), it just transform logic units to device units, if in CView, it does nothing.
No, no, no. It just seems to work correctly. And you should never, ever call Invalidate() in OnPaint()!. If you handle OnPaint() as you are doing in a SCrollView, you'll get a lot of problems later, believe me.Quote:
Originally posted by niry
I 've get the scrollview working correctly:)
Call Invalidate in OnPaint()
No, that's not true, it does a lot more: It does some sanity checks in debug builds, it sets the mapping mode as needed for scrolling, handles scale-to-fit, sets the viewport origin and extension, and corretly sets up the DC for printing.Quote:
Originally posted by niry
I know OnPrepareDC(), it just transform logic units to device units
That's not true either: It handles the page count when OnDraw() is called during printing.Quote:
Originally posted by niry
if in CView, it does nothing.
I don't understand why you keep doing it the wrong way. Just move your drawing code to OnDraw(), remove your OnPaint() implementation, and your code will work fine - also in the future, and for printing.
I'm having a similar problem where I'm trying to draw rectangles but they incorrectly draw over themselves when I scroll in either direction. I call my function to draw the rectangles in OnDraw. It works to redraw the rectangles when I minimize and restore a window but the origin moves upon scrolling as if there scrolling never happened. My code to draw the rectangles is
CRect TempRect = pDoc->GetNode(i); // The points for the rectangle
OnPrepareDC(pDC);
pDC->DPtoLP(&TempRect);
pDC->Rectangle(TempRect);
and my code to set scroll sizes is in OnInitialUpdate as
CSize Workspace(1000, 1000);
SetScrollSizes(MM_LOENGLISH, Workspace);
I have tried a variety of things in OnPrepareDC to fix including setting mapping modes and setting the origin to 0,0.
Any ideas?