• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetPenCustomStartCap

Started by José Roca, July 02, 2008, 03:55:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and adds a rectangle to it. The code then creates a Pen object, sets the custom start cap based on the GraphicsPath object, and draws a line.

C++


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

   // Create a GraphicsPath object, and add a rectangle to it.
   GraphicsPath strokePath;
   strokePath.AddRectangle(Rect(-10, -5, 20, 10));

   // Create a pen, and set the custom start cap based on the GraphicsPath object.
   Pen pen(Color(255, 0, 0, 255));
   CustomLineCap custCap(NULL, &strokePath);
   pen.SetCustomStartCap(&custCap);

   // Draw a line with the custom start cap.
   graphics.DrawLine(&pen, 20, 20, 200, 100);
}


PowerBASIC


SUB GDIP_SetPenCustomStartCap (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pStrokePath AS DWORD
   LOCAL pCustCap AS DWORD
   LOCAL pPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a GraphicsPath object, and add a rectangle to it.
   hStatus = GdipCreatePath(%FillModeAlternate, pStrokePath)
   hStatus = GdipAddPathRectangleI(pStrokePath, -10, -5, 20, 10)

   ' // Create a pen, and set the custom start cap based on the GraphicsPath object.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pPen)
   hStatus = GdipCreateCustomLineCap(%NULL, pStrokePath, %LineCapFlat, 0, pCustCap)
   hStatus = GdipSetPenCustomStartCap(pPen, pCustCap)

   ' // Draw a line with the custom end cap.
   hStatus = GdipDrawLineI(pGraphics, pPen, 20, 20, 200, 100)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pCustCap THEN GdipDeleteCustomLineCap(pCustCap)
   IF pStrokePath THEN GdipDeletePath(pStrokePath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB