CombineRgn (gdi32)
Last changed: anon-198.36.39.181

.
Summary

C# Signature:

[DllImport("gdi32.dll")]
static extern int CombineRgn(IntPtr hrgnDest, IntPtr hrgnSrc1,
   IntPtr hrgnSrc2, int fnCombineMode);

VB.Net Signature:

<DllImport("gdi32.dll")>
Private Shared Function CombineRgn(ByVal hrgnDest As IntPtr,
   ByVal hrgnSrc1 As IntPtr, ByVal hrgnSrc2 As IntPtr,
   ByVal fnCombineMode As Integer) As Integer
End Function

User-Defined Types:

public enum CombineRgnStyles:int
{
    RGN_AND         =1,
    RGN_OR          =2,
    RGN_XOR         =3,
    RGN_DIFF        =4,
    RGN_COPY        =5,
    RGN_MIN         =RGN_AND,
    RGN_MAX         =RGN_COPY
}

Return Values:

public const int ERROR = 0;
public const int NULLREGION = 1;
public const int SIMPLEREGION = 2;
public const int COMPLEXREGION = 3;

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

// This Sample xors the two different shapes and redraw the complete window by the resultant shapes

    [DllImport("gdi32.dll")]
    public static extern IntPtr CreateEllipticRgn(int nLeftRect, int nTopRect,int nRightRect, int nBottomRect);

    [DllImport("user32.dll")]
    static extern System.UInt16  SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

    [DllImport("gdi32.dll")]
    static extern int CombineRgn(IntPtr hrgnDest, IntPtr hrgnSrc1,IntPtr hrgnSrc2, int fnCombineMode);

// And the code lies here

InitializeComponent();

            IntPtr r1 = CreateEllipticRgn(0,0,300,300);
            IntPtr r2 = CreateEllipticRgn(100,100,300,300);
            IntPtr r3= CreateEllipticRgn(100,100,300,300);
            CombineRgn(r3,r1,r2,0);
            SetWindowRgn(this.Handle,r3,true);

// by - S.C.

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
CombineRgn on MSDN