Solved

invalidate/paint drops update regions

Posted on 2000-04-04
10
380 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 131
Get filename and folder into excel 7 76
Complete beginner needs help making a cron job 9 117
unix example issues 18 90
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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