Alex Rivera | Logout

correct usage of GetClipRgn?

Asked 2010-08-13T15:09:01.553
10

I want to write a function that needs to set the clipping region on a DC but restore any existing clipping region on the DC when it is done.

So I found GetClipRgn which sounds like exactly what I want but seems confusing. I couldn't find any examples of using it and Petzold had nothing to offer.

What I came up with was this:

void DrawStuff( HDC hDC )
{
    HRGN restoreRegion = CreateRectRgn( 0, 0, 0, 0 );
    if (GetClipRgn( hDC, restoreRegion ) != 1)
    {
        DeleteObject( restoreRegion );
        restoreRegion = NULL;
    }

    // 
    // Set new region, do drawing
    //

    SelectClipRgn( hDC, restoreRegion );
    if (restoreRegion != NULL)
    {
        DeleteObject( restoreRegion );
    }
}

It just seems weird that I need to create a region in order to get the current region.

Is this correct usage?

Is there are better way to achieve the same effect?

Edit
Report

1 Answer

5

Well the closest thing to a correct answer is Hans Passant's comment:

Yeah, it's a weird function. Your code looks okay.

answered 2011-09-12T13:56:49.620

Your Answer