Region::GetHRGN method (gdiplusheaders.h)

The Region::GetHRGN method creates a Windows Graphics Device Interface (GDI) region from this region.

Syntax

HRGN GetHRGN(
  [in] const Graphics *g
);

Parameters

[in] g

Type: const Graphics*

Pointer to a Graphics object that contains the world and page transformations required to calculate the device coordinates of this region.

Return value

Type: HRGN

This method returns a Windows handle to a GDI region that is created from this region.

Remarks

It is the caller's responsibility to call the GDI function DeleteObject to free the GDI region when it is no longer needed.

Examples

The following example creates a GDI+ region from a path and then uses the GDI+ region to create a GDI region. The code then uses a GDI function to display the GDI region.

VOID Example_GetHRGN(HDC hdc)
{
   Graphics graphics(hdc);

    Point points[] = {
      Point(110, 20),
      Point(120, 30),
      Point(100, 60),
      Point(120, 70),
      Point(150, 60),
      Point(140, 10)};

   GraphicsPath path;
   path.AddClosedCurve(points, 6);

    // Create a region from a path.
    Region pathRegion(&path);

   // Get a handle to a GDI region.
   HRGN hRegion;
   hRegion = pathRegion.GetHRGN(&graphics);

   // Use GDI to display the region.
   HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0));
   FillRgn(hdc, hRegion, hBrush);

   DeleteObject(hBrush);
   DeleteObject(hRegion);
}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusheaders.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

DeleteObject

Graphics

Rect

Region