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
Solved

invalidate/paint drops update regions

Posted on 2000-04-04
10
381 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 802
conditional code and condition difference 9 84
post4 challenge 28 104
x-bar in Google Sheets 2 71
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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