• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

invalidate/paint drops update regions

Any help appreciated:

Not everything I draw into my memory DC is making it into my window.  I'm sure it all makes it into the memDC because it all shows up if I force a repaint with minimize, or if I cover/uncover with another window.  But without this manual intervention, it looks like OnPaint is dropping a bunch of update rectangles.

Basically, my DrawACircle()-function draws into a memory DC (CDC), and then calls InvalidateRect() with the same coordinates on my CFrameWnd.  CMyFrameWnd::OnPaint() calls GetUpdateRect() and then blit's from the memDC to the window's DC.  Is this setup "right"?  Somewhere in here, if I draw a bunch of stuff right in a row, some of the stuff doesn't get drawn in the window.  I loose parts of lines, or if I draw a bunch of partially overlapping circles in a row, a bunch of them will be missing entirely, and/or displayed but only partially.

I tried wrapping DrawACircle() and OnPaint() with a single CCriticalSection object (keeping them from running concurrently), and everything works fine, but I would rather not fill all my DrawAWhatever() functions with Critical Section Lock's and Unlock's.  Is there another way to solve this?  Even a more articulate description of the problem would be helpful.

Thanks in advance-

Mike
0
ottenm
Asked:
ottenm
  • 4
  • 2
  • 2
  • +2
1 Solution
 
awcoatsCommented:
I think you need to call Invalidate(). InvadlidateRect() says on the next redraw, redraw this rect. The resize window/ an overlapping window will trigger an Invalidate() to be called and thus showing your circle. You should try InvalidateRect() and Invalidate() to draw just the area that has the circle.
0
 
awcoatsCommented:
I think you need to call Invalidate(). InvadlidateRect() says on the next redraw, redraw this rect. The resize window/ an overlapping window will trigger an Invalidate() to be called and thus showing your circle. You should try InvalidateRect() and Invalidate() to draw just the area that has the circle.
0
 
ottenmAuthor Commented:
Invalidate() invalidates the entire client area.  I am drawing a large number of small objects (and in a short time span) so I can not afford to redraw the entire window each time, just the small rectangle(s) I invalidate.  

Please correct me if this is wrong.

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
GlennDeanCommented:
I wonder if the problem could be that multiple calls to InvalidateRect with bErase=1 are occurring between each WM_PAINT message.  With bErase=1 means that the entire update region is erased, not just the one one calls on a particular InvalidateRect call.
   I would try to just see what happens if you change bErase to 0.
   Glenn
0
 
ottenmAuthor Commented:
No luck, all the InvalidateRect calls have bErase=FALSE (I do not want the background drawn, just the new foreground stuff).

Also, when I "catch" the InvalidateRect calls in OnPaint, I call GetUpdateRect, which I believe returns a bounding rectangle that includes the entire invalid region (not just a recent invalidated rect).  i.e., invalidated rect's get added to the invalid region (no longer separate entities).

0
 
vachoohoCommented:
UpdateWindow(); ???
0
 
RONSLOWCommented:
it could be that the corrdinate you are using are not relative to the same origin.

For example, there are screen coordinates (in pixels from corner of screen), window coordinates (from corner of outside of a window) and client coordinates (from inside of border of window).

It could well be that you are getting these confused, and so the wrong rectangle is being updated.

Maybe you also need a GdiFlush call to ensure that the drawing is finished before you call InvalidateRect?
0
 
ottenmAuthor Commented:
UpdateWindow looks like it cleared it up!!  I don't know if this will cost me down the road, I like(d) the idea that the rectangles got batched and drawn together.  At least it seemed like a good idea until I started dropping updates.

Thanks for the tip!
0
 
ottenmAuthor Commented:
Thank you RONSLOW, I did actually run into that same problem a few weeks ago but resolved it.  My memDC and client drawing area are the same size, and the stuff I was loosing wasn't anywhere near the border.

Again, thank you for your input-

Mike
0
 
RONSLOWCommented:
you're welcome .. at least its all fixed.

Don't quite see how UpdateWindow would help .. all that would do is force the painting of direty regions to happen straight away instead of later.

hmmm.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now