Author Topic: GDI+: GdipSetPenCustomStartCap  (Read 2664 times)

0 Members and 1 Guest are viewing this topic.

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
GDI+: GdipSetPenCustomStartCap
« on: July 02, 2008, 03:55:25 PM »

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++

Code: [Select]
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

Code: [Select]
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


« Last Edit: August 07, 2011, 09:15:34 PM by José Roca »