The following example sets up three colors:
black,
turquoise, and
current (initialized to black). A rectangle is painted by using turquoise as the background color and black as the foreground color. Then the
GdipGetBackgroundColor function is used to get the current color of the brush (which at the time is turquoise). The address of the current color (initialized to black) is passed as the return point for the call to
GdipGetBackgroundColor. When the rectangle is painted again, note that the background color is again turquoise (not black). This shows that the call to
GdipGetBackgroundColor was successful.
C++
VOID Example_GetBackgroundColor(HDC hdc)
{
Graphics graphics(hdc);
// Set colors.
Color black(255, 0, 0, 0); // foreground
Color turquoise(255, 0, 255, 255); // background
Color current(255, 0, 0, 0); // new background
// Set and then draw the first hatch style.
HatchBrush brush(HatchStyleHorizontal, black, turquoise);
graphics.FillRectangle(&brush, 20, 20, 100, 50);
// Get the background color of the current brush.
brush.GetBackgroundColor(¤t);
// Draw the rectangle again using the current color.
HatchBrush brush2(HatchStyleDiagonalCross, black, current);
graphics.FillRectangle(&brush2, 130, 20, 100, 50);
}
PowerBASIC
SUB GDIP_GetHatchBackgroundColor (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pColorBlack AS DWORD
LOCAL pColorTurquoise AS DWORD
LOCAL pColorCurrent AS DWORD
LOCAL pBrush AS DWORD
LOCAL pBrush2 AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set colors.
pColorBlack = GDIP_ARGB(255, 0, 0, 0) ' 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, pColorBlack, pColorTurquoise, pBrush)
hStatus = GdipFillRectangle(pGraphics, pBrush, 20, 20, 100, 50)
' // Get the background color of the current brush.
hStatus = GdipGetHatchBackgroundColor(pBrush, pColorCurrent)
' // Draw the rectangle again using the current color.
hStatus = GdipCreateHatchBrush(%HatchStyleDiagonalCross, pColorBlack, pColorCurrent, 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
(http://www.jose.it-berater.org/captures/GdipGetHatchBackgroundColor.png)