Author Topic: GDI+: GdipGetPenCustomEndCap  (Read 2522 times)

0 Members and 1 Guest are viewing this topic.

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
GDI+: GdipGetPenCustomEndCap
« on: July 02, 2008, 02:59:09 PM »

The following example creates a GraphicsPath object and adds a rectangle to it. The code then creates a Pen object, sets the custom end cap using the GraphicsPath object, and draws a line. Finally, the code gets the custom end cap of the pen and creates another Pen object using the same custom end cap. It then draws a second line.

C++

Code: [Select]
VOID Example_GetCustomEndCap(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 with a custom end cap.
   Pen pen(Color(255, 0, 0, 255));
   CustomLineCap custCap(NULL, &strokePath);
   pen.SetCustomEndCap(&custCap);

   // Draw a line with a custom end cap.
   graphics.DrawLine(&pen, 0, 0, 200, 100);

   // Obtain the custom end cap for the pen.
   CustomLineCap customLineCap(NULL, NULL);
   pen.GetCustomEndCap(&customLineCap);

   // Create another pen, and use the same custom end cap.
   Pen pen2(Color(255, 0, 255, 0), 3);
   pen2.SetCustomEndCap(&customLineCap);

   // Draw a line using the second pen.
   graphics.DrawLine(&pen2, 0, 100, 200, 150);
}

PowerBASIC

Code: [Select]
SUB GDIP_GetPenCustomEndCap (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pStrokePath AS DWORD
   LOCAL pCustCap AS DWORD
   LOCAL pCustomLineCap AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pPen2 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 end 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 = GdipSetPenCustomEndCap(pPen, pCustCap)

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

   ' // Obtain the custom end cap for the pen.
   hStatus = GdipCreateCustomLineCap(%NULL, %NULL, %LineCapFlat, 0, pCustomLineCap)
   hStatus = GdipGetPenCustomEndCap(pPen, pCustomLineCap)

   ' // Create another pen, and use the same custom end cap.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 3, %UnitWorld, pPen2)
   hStatus = GdipSetPenCustomEndCap(pPen2, pCustomLineCap)

   ' // Draw a line using the second pen.
   hStatus = GdipDrawLineI(pGraphics, pPen2, 0, 100, 200, 150)

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

END SUB


« Last Edit: August 07, 2011, 09:16:47 PM by José Roca »