• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetEmpty

Started by José Roca, June 28, 2008, 01:57:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a region from a rectangle and paints it with a brush. Then the code makes the region empty and paints the region with a different color to show that the region occupies no space on the display device.

C++


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

   Rect rect(65, 15, 70, 45);
   SolidBrush redBrush(Color(255, 255, 0, 0));
   SolidBrush blueBrush(Color(255, 0, 0, 255));

   // Create a region, and fill it with a red brush.
   Region rectRegion(rect);
   graphics.FillRegion(&redBrush, &rectRegion);

   // Make the region empty, and then fill it with a blue brush.
   rectRegion.MakeEmpty();
   graphics.FillRegion(&blueBrush, &rectRegion);
}


PowerBASIC


SUB GDIP_SetEmpty (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pRedBrush AS DWORD
   LOCAL pBlueBrush AS DWORD
   LOCAL pRectRegion AS DWORD

   LOCAL rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pRedBrush)
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 255), pBlueBrush)

   ' // Create a region, and fill it with a red brush.
   hStatus = GdipCreateRegionRectI(rc, pRectRegion)
   hStatus = GdipFillRegion(pGraphics, pRedBrush, pRectRegion)

   ' // Make the region empty, and then fill it with a blue brush.
   hStatus = GdipSetEmpty(pRectRegion)
   hStatus = GdipFillRegion(pGraphics, pBlueBrush, pRectRegion)

   ' // Cleanup
   IF pRedBrush THEN GdipDeleteBrush(pRedBrush)
   IF pBlueBrush THEN GdipDeleteBrush(pBlueBrush)
   IF pRectRegion THEN GdipDeleteRegion(pRectRegion)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


The following illustration shows the output of the preceding code.