Solved

invalidate/paint drops update regions

Posted on 2000-04-04
10
376 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now