The following example creates a
Pen object and draws a line. The code then gets the color of the pen and creates a
Brush object based on that color. Finally, the code uses the
Brush object to fill a rectangle.
C++
VOID Example_GetColor(HDC hdc
{
Graphics graphics(hdc);
// Create a pen, and use it to draw a line.
Pen pen(Color(255, 200, 150, 100), 5);
graphics.DrawLine(&pen, 0, 0, 200, 100);
// Get the pen's color, and use that color to create a brush.
Color color;
pen.GetColor(&color);
SolidBrush solidBrush(color);
// Use the brush to fill a rectangle.
graphics.FillRectangle(&solidBrush, 0, 100, 200, 100);
}
PowerBASIC
SUB GDIP_GetPenColor (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
LOCAL pSolidBrush AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a pen, and use it to draw a line.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 200, 150, 100), 5, %UnitWorld, pPen)
hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 200, 100)
' // Get the pen's color, and use that color to create a brush.
LOCAL argbColor AS DWORD
hStatus = GdipGetPenColor(pPen, argbColor)
hStatus = GdipCreateSolidFill(argbColor, pSolidBrush)
' // Use the brush to fill a rectangle.
hStatus = GdipFillRectangleI(pGraphics, pSolidBrush, 0, 100, 200, 100)
' // Cleanup
IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipGetPenColor.png)