• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPenEndCap

Started by José Roca, July 03, 2008, 04:09:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Pen object, sets the dash style, and draws a dashed line. The code then gets the dash style, creates a second pen with the dash style of the first pen, and draws a second dashed line.

C++


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

   // Create a dashed pen, and use it to draw a dashed line.
   Pen pen(Color(255, 255, 0, 0), 9);
   pen.SetDashStyle(DashStyleDashDot);
   graphics.DrawLine(&pen, 20, 20, 200, 100);

   // Obtain the dash style for the pen.
   DashStyle dashStyle;
   dashStyle = pen.GetDashStyle();

   // Create another pen, and use the same dash style.
   Pen pen2(Color(255, 0, 255, 0), 9);
   pen2.SetDashStyle(dashStyle);

   // Draw a second dashed line.
   graphics.DrawLine(&pen2, 20, 60, 200, 140);
}


PowerBASIC


SUB GDIP_GetPenDashStyle (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pPen2 AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a dashed pen, and use it to draw a dashed line.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 9, %UnitWorld, pPen)
   hStatus = GdipSetPenDashStyle(pPen, %DashStyleDashDot)
   hStatus = GdipDrawLineI(pGraphics, pPen, 20, 20, 200, 100)

   ' // Obtain the dash style for the pen.
   LOCAL dashStyle AS LONG
   hStatus = GdipGetPenDashStyle(pPen, dashStyle)

   ' // Create another pen, and use the same dash style.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 9, %UnitWorld, pPen2)
   hStatus = GdipSetPenDashStyle(pPen2, dashStyle)

   ' // Draw a second dashed line.
   hStatus = GdipDrawLineI(pGraphics, pPen2, 20, 60, 200, 140)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pPen2 THEN GdipDeletePen(pPen2)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB