• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetHatchForegroundColor

Started by José Roca, July 01, 2008, 11:48:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example sets up three colors: blue, turquoise, and current (initialized to black). A rectangle is painted by using turquoise as the background color and blue as the foreground color. Then the GdipGetBackgroundColor function is used to get the current color of the brush (which at the time is blue). The address of the current Color object (initialized to black) is passed as the return point for the call to GdipGetBackgroundColor. When the rectangle is painted again, notice that the foreground color is again blue (not black). This shows that the call to GdipGetForegroundColor was successful.

C++


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

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

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

   // Get the current foreground color of the brush.
   brush.GetForegroundColor(&current);

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


PowerBASIC


SUB GDIP_GetHatchForegroundColor (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pColorBlue AS DWORD
   LOCAL pColorTurquoise AS DWORD
   LOCAL pColorCurrent AS DWORD
   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
   pColorCurrent = GDIP_ARGB(255, 0, 0, 0)         ' new background

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

   ' // Get the background color of the current brush.
   hStatus = GdipGetHatchForegroundColor(pBrush, pColorCurrent)

   ' // Draw the rectangle again using the current color.
   hStatus = GdipCreateHatchBrush(%HatchStyleDiagonalCross, pColorCurrent, pColorTurquoise, pBrush2)
   hStatus = GdipFillRectangle(pGraphics, pBrush2, 130, 20, 100, 50)

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

END SUB