• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPenCustomStartCap

Started by José Roca, July 02, 2008, 04:04:42 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 using the GraphicsPath object, and draws a line. Finally, the code gets the custom start cap of the pen and creates another Pen object using the same custom end cap. It then draws a second line.

C++


VOID Example_GetCustomStartCap(HDC hdc)
{
   Graphics graphics(hdc);
   GraphicsPath strokePath;
   strokePath.AddRectangle(Rect(-10, -5, 20, 10));

  // Create a pen with a custom start cap.
   Pen pen(Color(255, 0, 0, 255));
   CustomLineCap custCap(NULL, &strokePath);
   pen.SetCustomStartCap(&custCap);

   graphics.DrawLine(&pen, 50, 50, 200, 100);

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

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

   graphics.DrawLine(&pen2, 50, 100, 200, 150);
}


PowerBASIC


SUB GDIP_GetPenCustomStartCap (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 = GdipSetPenCustomStartCap(pPen, pCustCap)

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

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

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

   ' // Draw a line using the second pen.
   hStatus = GdipDrawLineI(pGraphics, pPen2, 50, 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