The following example creates an
AdjustableArrowCap,
pMyArrowCap, and sets the height of the cap. The code then creates a
Pen, assigns
pMyArrowCap as the ending line cap for this
Pen, and draws a capped line. Next, the code gets the height of the arrow cap, creates a new arrow cap with height equal to the height of
pMyArrowCap, assigns the new arrow cap as the ending line cap for the Pen, and draws another capped line.
C++
VOID Example_GetHeight(HDC hdc)
{
Graphics graphics(hdc);
// Create an AdjustableArrowCap with a height of 10 pixels.
AdjustableArrowCap myArrow(10, 10, true);
// Create a Pen, and assign myArrow as the end cap.
Pen arrowPen(Color(255, 0, 0, 0));
arrowPen.SetCustomEndCap(&myArrow);
// Draw a line using arrowPen.
graphics.DrawLine(&arrowPen, Point(0, 20), Point(100, 20));
// Create a second arrow cap using the height of the first one.
AdjustableArrowCap otherArrow(myArrow.GetHeight(), 20, true);
// Assign the new arrow cap as the end cap for arrowPen.
arrowPen.SetCustomEndCap(&otherArrow);
// Draw a line using arrowPen.
graphics.DrawLine(&arrowPen, Point(0, 55), Point(100, 55));
}
PowerBASIC
SUB GDIP_GetHeight(BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pArrowPen AS DWORD
LOCAL pMyArrowCap AS DWORD
LOCAL pOtherArrowCap AS DWORD
LOCAL nHeight AS SINGLE
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create an AdjustableArrowCap with a height of 10 pixels.
hStatus = GdipCreateAdjustableArrowCap(10, 10, %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)
' // Draw a line using pArrowPen.
hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 20, 100, 20)
' // Get the height of the arrow cap.
hStatus = GdipGetAdjustableArrowCapHeight(pMyArrowCap, nHeight)
' // Create a second arrow cap using the height of the first one.
hStatus = GdipCreateAdjustableArrowCap(nHeight, 20, %TRUE, pOtherArrowCap)
' // Assign the new arrow cap as the end cap for pArrowPen.
hStatus = GdipSetPenCustomEndCap(pArrowPen, pOtherArrowCap)
' // Draw a line using pArrowPen.
hStatus = GdipDrawLineI(pGraphics, pArrowPen, 0, 55, 100, 55)
' // Cleanup
IF pOtherArrowCap THEN GdipDeleteCustomLineCap(pOtherArrowCap)
IF pMyArrowCap THEN GdipDeleteCustomLineCap(pMyArrowCap)
IF pArrowPen THEN GdipDeletePen(pArrowPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipGetAdjustableArrowCapHeight.png)