Solved

invalidate/paint drops update regions

Posted on 2000-04-04
10
382 Views
Last Modified: 2013-11-20
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
Comment
Question by:ottenm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 

Expert Comment

by:awcoats
ID: 2685374
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
 

Expert Comment

by:awcoats
ID: 2685383
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
 

Author Comment

by:ottenm
ID: 2685477
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:GlennDean
ID: 2685624
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
 

Author Comment

by:ottenm
ID: 2685661
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
 
LVL 5

Accepted Solution

by:
vachooho earned 50 total points
ID: 2687605
UpdateWindow(); ???
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2688431
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
 

Author Comment

by:ottenm
ID: 2688477
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
 

Author Comment

by:ottenm
ID: 2688489
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2688495
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 911
sumDigits challenge 9 172
modThree challenge 4 103
withoutTen challenge 14 137
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question