• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetHatchStyle

Started by José Roca, July 02, 2008, 12:24:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example sets up two hatch styles: horiz and current (initialized to HatchStyleDiagonalCross). A rectangle that uses horiz as the hatch style is painted. Then the GdipGetHatchStyle function is used to get the current hatch style of the brush (which at the time is HatchStyleHorizontal). The address of the current HatchStyle object (initialized to HatchStyleDiagonalCross) is passed as the return point for the call to GdipGetHatchStyle. When the rectangle is painted again, notice that the hatch style is again HatchStyleHorizontal (not HatchStyleDiagonalCross). This shows that the call to GdipGetHatchStyle was successful.

C++


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

   // Set colors.
   Color blue(255, 0, 0, 255);        // foreground
   Color turquoise(255, 0, 255, 255); // background

   // Set hatch styles.
   HatchStyle horiz(HatchStyleHorizontal);
   HatchStyle current(HatchStyleDiagonalCross);

   // Set and then draw the first hatch style.
   HatchBrush brush(horiz, blue, turquoise);
   graphics.FillRectangle(&brush, 20, 20, 100, 50);

   // Get the current hatch style of the brush.
   current = brush.GetHatchStyle();

   // Draw the rectangle again using the current hatch style.
   HatchBrush brush2(current, blue, turquoise);
   graphics.FillRectangle(&brush2, 130, 20, 100, 50);
}


PowerBASIC


SUB GDIP_GetHatchStyle (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pColorBlue AS DWORD
   LOCAL pColorTurquoise AS DWORD
   LOCAL horizStyle AS LONG
   LOCAL currentStyle AS LONG
   LOCAL pBrush AS DWORD
   LOCAL pBrush2 AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Set colors.
   pColorBlue = GDIP_ARGB(255, 0, 0, 255)          ' foreground
   pColorTurquoise = GDIP_ARGB(255, 0, 255, 255)   ' background

   ' // Set hatch styles.
   horizStyle = %HatchStyleHorizontal
   currentStyle = %HatchStyleDiagonalCross

   ' // Set and then draw the first hatch style.
   hStatus = GdipCreateHatchBrush(horizStyle, pColorBlue, pColorTurquoise, pBrush)
   hStatus = GdipFillRectangle(pGraphics, pBrush, 20, 20, 100, 50)

   ' // Get the current hatch style of the brush.
   hStatus = GdipGetHatchStyle(pBrush, currentStyle)

   ' // Draw the rectangle again using the current hatch style.
   hStatus = GdipCreateHatchBrush(currentStyle, pColorBlue, pColorTurquoise, pBrush2)
   hStatus = GdipFillRectangle(pGraphics, pBrush, 130, 20, 100, 50)

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

END SUB