The MASM Forum

General => The Campus => Topic started by: bf2 on October 17, 2012, 01:35:11 AM

Title: Update, clipping, invalid
Post by: bf2 on October 17, 2012, 01:35:11 AM
What is the difference or relationship between:
- Update region
- Clipping rectangle
- Invalid rectangle.

I see these terms being used in both Petzold and Iczellion but without a precise definition.

Could someone define them and their relationships in plain English please?

Thanks.
Title: Re: Update, clipping, invalid
Post by: TouEnMasm on October 17, 2012, 01:39:19 AM

in "plain english" you have it on msdn with many details,update,samples ....
just type for example "msdn GetUpdateRgn"
Title: Re: Update, clipping, invalid
Post by: bf2 on October 17, 2012, 01:58:51 AM
I have tried MSDN - ended up more confused unfortunately.

For example I cannot tell from MSDN if update region and invalid rectangle are the same.
Title: Re: Update, clipping, invalid
Post by: dedndave on October 17, 2012, 02:34:54 AM
Quote from: bf2 on October 17, 2012, 01:58:51 AM
I have tried MSDN - ended up more confused unfortunately.

i hear ya - lol
there is a lot of material to cover when it comes to painting and drawing
read it - read it again - and again - and again   :P
play with it along the way

the update region is a collection of invalidated regions
the OS keeps track of the update region
you can invalidate a region or a rectangle (usually the latter)
doing so causes the OS to "add that region to the pile", so to speak
when a WM_PAINT message is sent to a window, the collective total rectangle is sent via PAINTSTRUCT
the BeginPaint/EndPaint sequence clears the collective update region
notice that the update region can include things like windows moving on top of each other, as well as you drawing
you can also validate regions or rectangles to remove them from the pile

a clipping rectangle is a more general term that is used in many ways
for example, if i draw text that extends beyond the window boundry, it is clipped
or - if i have 2 child windows that overlap each other, one of them may be clipped

it can help reduce CPU usage if you only update the rectangle specified in PAINTSTRUCT
for beginners, it is convenient to ignore this and just update the entire window
it makes the code easier to write
but, once you have the hang of it, you will want to add code that limits the update to PAINTSTRUCT.rcPaint