• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetAdjustableArrowCapWidth

Started by José Roca, June 22, 2008, 11:38:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates an AdjustableArrowCap object, pMyArrowCap, and sets the width of the cap to 5 pixels. Next, the code creates a Pen object, assigns pMyArrowCap as the ending line cap for this Pen object, and draws a capped line. The code obtains the width using GdipGetAdjustableArrowCapWidth and sets the height equal to the width. The code then draws another capped line with the new cap.

C++


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

   // Create an AdjustableArrowCap with a width of 10 pixels.
   AdjustableArrowCap myArrow(10, 5, true);

   // Create a Pen, and assign myArrow as the end cap.
   Pen arrowPen(Color(255, 0, 0, 0));
   arrowPen.SetCustomEndCap(&myArrow);

   // Get the width of the arrow.
   REAL width = myArrow.GetWidth();
   
   // Draw a line using arrowPen.
   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));

   // Set height equal to width and draw another line.
   myArrow.SetHeight(width);
   arrowPen.SetCustomEndCap(&myArrow);
   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 140));
}


PowerBASIC


SUB GDIP_GetWidth (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pArrowPen AS DWORD
   LOCAL pMyArrowCap AS DWORD
   LOCAL nWidth AS SINGLE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create an AdjustableArrowCap with a width of 10 pixels.
   hStatus = GdipCreateAdjustableArrowCap(10, 5, %TRUE, pMyArrowCap)

   ' // Create a Pen, and assign pMyArrowCap as the end cap.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0!, %UnitWorld, pArrowPen)
   hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)

   ' // Get the width of the arrow.
   hStatus = GdipGetAdjustableArrowCapWidth(pMyArrowCap, nWidth)

   ' // Draw a line using pArrowPen.
   hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 0, 100, 100)

   ' // Set height equal to width and draw another line.
   hStatus = GdipSetAdjustableArrowCapHeight(pMyArrowCap, nWidth)
   hStatus = GdipSetPenCustomEndCap(pArrowPen, pMyArrowCap)

   ' // Draw a line with new cap.
   hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 40, 100, 140)

   ' // Cleanup
   IF pMyArrowCap THEN GdipDeleteCustomLineCap(pMyArrowCap)
   IF pArrowPen THEN GdipDeletePen(pArrowPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB