ExtSelectClipRgn
The
ExtSelectClipRgn
function combines the
specified region with the
current Clip Region
using the specified mode. If
you would like more details
on how the different modes
will affect the current
Clip Region, refer to
this guide:
Guide to WIN32 Regions.
Collapse
Copy Code
int ExtSelectClipRgn(
HDC hdc, HRGN hrgn, int fnMode );
The dimensions that this
function return are in
device coordinates for the
current DC. The return value
will indicate the current
region type that is
stored in the Clip Region.
IntersectClipRect
The
IntersectClipRect
function creates a new
Clip Region from the
intersection of the current
Clip Region and the
specified rectangle. Unless
one of the other clipping
functions has been called to
modify the initial Clip
Region, this function
will have not effect as the
default Clip Region
includes the entire DC.
Collapse
Copy Code
int IntersectClipRect(
HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect );
ExcludeClipRect
The
ExcludeClipRect
function creates a new
Clip Region that
consists of the existing
Clip Region minus the
specified rectangle.
Collapse
Copy Code
int ExcludeClipRect(
HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect );
OffsetClipRgn
The
OffsetClipRgn
function moves the Clip
Region of a device
context by the specified
offsets.
Collapse
Copy Code
int OffsetClipRgn(
HDC hdc, int nXOffset, int nYOffset );
SelectClipPath
The
SelectClipPath
function selects the current
path as a Clip Region
for a device context,
combining the new region
with any existing Clip
Region using the
specified mode.
Collapse
Copy Code
BOOL SelectClipPath(
HDC hdc, int iMode );
Meta Region Functions
At first glance the set of
Meta Region functions
may seem a little meager
with only two. However, when
a Meta Region is set,
it will combine the
intersection of the current
Meta Region, with the
current clip region. The
Clip Region will then be
reset to the entire DC. This
in effect allows the Meta
Region to use all of the
Clip region functions in
order to create itself. It
is highly likely that this
function could be
implemented in terms of
GetRandomRgn
by simply passing in a 2 to
the iNum parameter.
It is however, very
important that
SaveDC
is used to save the state of
the DC before a meta region
is set into the DC. Because
when a Meta Region is
created, it is intersected
with the current Meta
Region. Once a Meta
Region region is reduced
from the default client
rectangle, then the region
cannot be returned back to
its original state except by
restoring a previously saved
DC context.
GetMetaRgn
The
GetMetaRgn
function retrieves the
current meta region for the
specified device context.
Collapse
Copy Code
int GetMetaRgn(
HDC hdc, HRGN hrgn );
SetMetaRgn
The
SetMetaRgn
function intersects the
current Clip Region
for the specified device
context with the current
meta region and saves the
combined region as the new
meta region for the
specified device context.
The Clip Region is
reset to a null region. The
only way to reset the
Meta Region to its
original state is to return
to a previously saved
version of the DC with
SaveDC
.
Collapse
Copy Code
int SetMetaRgn(
HDC hdc );
Application of the DC
Regions
The regions that are a part
of the DC are used
extensively. Quite often an
application will use these
regions and not be unaware
of this fact. By
understanding the regions
that are used, and what
these regions accomplish, a
developer can possibly
design their system around
these features in order to
create a more efficient
program. This fact is
especially true when an
application or control is
implemented that does not
follow the normal design for
WIN32 development.
BeginPaint
This is probably the most
common use of the regions
that are involved the DC.
Internally
BeginPaint
makes a call to
GetDCEx
in order to create the DC
that finally gets used. The
current update region for
the target window is used as
the clipping region in
GetDCEx
.
This final result is the
System Region is
equivalent to the Update
Region of the window for the
paint DC. When the
application attempts to
paint on the paint DC, only
the regions that have been
invalidated will be
repainted.
At this point the
application could call
GetRandomRgn
in order to get the region
that needs to be repainted,
and factor out all of the
unnecessary painting
increasing the efficiency of
the paint routine. Even if
the application sends the
entire window to be
repainted upon each paint
message, the display
ultimately experiences less
flicker because of the
automatic clipping that is
experienced by the System
Region. In order to see
a demonstration of the
flicker that would occur
with out this feature, make
a call to
InvalidateRect
before
BeginPaint
in your paint handler.
Collapse
Copy Code
InvalidateRect(hWnd, NULL, TRUE);
This will have the effect of
invalidating the entire
target window, and
eliminating any benefit that
System Region
provides.