• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetBrushType

Started by José Roca, June 22, 2008, 01:17:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a solid brush, checks the type of the object, and then, if the type is BrushTypeSolidColor, uses the brush to fill a rectangle.

C++


VOID Example_GetType(HDC hdc)
{
   Graphics graphics(hdc);
   // Create a SolidBrush object.
   SolidBrush solidBrush(Color(255, 0, 0, 255));
   // Get the type of solidBrush.
   BrushType type = solidBrush.GetType();
   //If the type of solidBrush is BrushTypeSolidColor, use it to fill a rectangle.
   if (type == BrushTypeSolidColor)
       graphics.FillRectangle(&solidBrush, Rect(0, 0, 100, 100));
}


PowerBASIC


SUB GDIP_GetBrushType (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pBrush AS DWORD
   LOCAL pType AS LONG
   LOCAL pixelColor AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create an ARGB color
   pixelColor = GDIP_ARGB(255, 0, 0, 255)

   ' // Create a SolidBrush
   hStatus = GdipCreateSolidFill(pixelColor, pBrush)

   ' // Get the type of solid brush
   hStatus = GdipGetBrushType(pBrush, pType)

   ' // If the type of solidBrush is BrushTypeSolidColor, use it to fill a rectangle.
   IF pType = %BrushTypeSolidColor THEN
      hStatus = GdipFillRectangleI(pGraphics, pBrush, 0, 0, 100, 100)
   END IF

   ' // Cleanup
   IF pBrush THEN GdipDeleteBrush(pBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB