The following example creates an AdjustableArrowCap, myArrow, and sets the height of the cap. The code then creates a Pen, assigns myArrow as the ending line cap for the 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 myArrow, assigns the new arrow cap as the ending line cap for the Pen, and draws another capped line.
' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapGetHeight.bas
' Contents: GDI+ example
' This version uses the CWindow and CGdiPlus classes, and the GraphCtx graphic control
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers 2.05+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1
' // Header files for imported files
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
#INCLUDE ONCE "CGdiPlus.inc" ' // CGdiPlus class
%IDC_GRCTX = 1001
' ========================================================================================
' The following example creates an AdjustableArrowCap, myArrow, and sets the height of the
' cap. The code then creates a Pen, assigns myArrow as the ending line cap for the 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 myArrow, assigns the new arrow cap as the
' ending line cap for the Pen, and draws another capped line.
' ========================================================================================
SUB Example_GetHeight (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)
' Graphics graphics(hdc);
LOCAL graphics AS IGdipGraphics
graphics = pGdip.Graphics(hdc)
' // Create an AdjustableArrowCap with a height of 10 pixels.
' AdjustableArrowCap myArrow(10, 10, true);
LOCAL myArrow AS IGdipAdjustableArrowCap
myArrow = pGdip.AdjustableArrowCap(10, 10, %TRUE)
' // Create a Pen, and assign myArrow as the end cap.
' Pen arrowPen(Color(255, 0, 0, 0));
' arrowPen.SetCustomEndCap(&myArrow);
LOCAL arrowPen AS IGdipPen
arrowPen = pGdip.Pen(pGdip.Color(255, 0, 0, 0))
arrowPen.SetCustomEndCap(myArrow)
' // Draw a line using arrowPen.
' graphics.DrawLine(&arrowPen, Point(0, 20), Point(100, 20));
graphics.DrawLine(arrowPen, 0, 20, 100, 20)
' // Create a second arrow cap using the height of the first one.
' AdjustableArrowCap otherArrow(myArrow.GetHeight(), 20, true);
LOCAL otherArrow AS IGdipAdjustableArrowCap
otherArrow = pGdip.AdjustableArrowCap(myArrow.GetHeight, 20, %TRUE)
' // Assign the new arrow cap as the end cap for arrowPen.
' arrowPen.SetCustomEndCap(&otherArrow);
arrowPen.SetCustomEndCap(otherArrow)
' // Draw a line using arrowPen.
' graphics.DrawLine(&arrowPen, Point(0, 55), Point(100, 55));
graphics.DrawLine(arrowPen, 0, 55, 100, 55)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
' // Create an instance of the CWindow class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Create the main window
LOCAL hwnd AS DWORD
hwnd = pWindow.CreateWindow(%NULL, "AdjustableArrowCapGetHeight", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
pWindow.SetClientSize 400, 250
' // Center the window
pWindow.CenterWindow
' // Create an instance of the GdiPlus class
LOCAL pGdip AS IGdiPlus
pGdip = NewGdiplus
' // Add a graphic control
LOCAL hCtrl AS DWORD
hCtrl = pWindow.AddGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
GraphCtx_Clear(hCtrl, %WHITE)
' // Get the memory device context of the graphic control
LOCAL hdc AS DWORD
hdc = GraphCtx_GetDc(hCtrl)
' // Draw the graphics
Example_GetHeight(pGdip, hdc)
' // Default message pump (you can replace it with your own)
pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL hCtrl AS DWORD
LOCAL hDC AS DWORD
SELECT CASE uMsg
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hwnd, %WM_CLOSE, 0, 0
END IF
END SELECT
CASE %WM_DESTROY
' // Close the main window
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
Flat API version
' ########################################################################################
' Microsoft Windows
' File: GDIP_AdjustableArrowCapGetHeight.bas
' Contents: GDI+ example
' This version uses the CWindow class, the GraphCtx graphic control and the GDI+ Flat API
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers 2.05+
' Copyright (c) 2011 José Roca. Freeware. Use at your own risk.
' Portions Copyright (c) Microsoft Corporation. All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEGRAPHCTX = 1
' // Header files for imported files
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
#INCLUDE ONCE "GdiPlus.inc" ' // GdiPlus API
%IDC_GRCTX = 1001
' ========================================================================================
' The following example creates an AdjustableArrowCap, myArrow, and sets the height of the
' cap. The code then creates a Pen, assigns myArrow as the ending line cap for the 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 myArrow, assigns the new arrow cap as the
' ending line cap for the Pen, and draws another capped line.
' ========================================================================================
SUB Example_GetHeight (BYVAL hdc AS DWORD)
' Graphics graphics(hdc);
LOCAL graphics AS DWORD
GdipCreateFromHDC(hdc, graphics)
' // Create an AdjustableArrowCap with a height of 10 pixels.
' AdjustableArrowCap myArrow(10, 10, true);
LOCAL myArrow AS DWORD
GdipCreateAdjustableArrowCap(10, 10, %TRUE, myArrow)
' // Create a Pen, and assign myArrow as the end cap.
' Pen arrowPen(Color(255, 0, 0, 0));
' arrowPen.SetCustomEndCap(&myArrow);
LOCAL arrowPen AS DWORD
GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitWorld, arrowPen)
GdipSetPenCustomEndCap(arrowPen, myArrow)
' // Draw a line using arrowPen.
' graphics.DrawLine(&arrowPen, Point(0, 20), Point(100, 20));
GdipDrawLine(graphics, arrowPen, 0, 20, 100, 20)
' // Create a second arrow cap using the height of the first one.
' AdjustableArrowCap otherArrow(myArrow.GetHeight(), 20, true);
LOCAL otherArrow AS DWORD
LOCAL nHeight AS SINGLE
GdipGetAdjustableArrowCapHeight(myArrow, nHeight)
GdipCreateAdjustableArrowCap(nHeight, 20, %TRUE, otherArrow)
' // Assign the new arrow cap as the end cap for arrowPen.
' arrowPen.SetCustomEndCap(&otherArrow);
GdipSetPenCustomEndCap(arrowPen, otherArrow)
' // Draw a line using arrowPen.
' graphics.DrawLine(&arrowPen, Point(0, 55), Point(100, 55));
GdipDrawLine(graphics, arrowPen, 0, 55, 100, 55)
' // Cleanup
GdipDeleteCustomLineCap(otherArrow)
GdipDeleteCustomLineCap(myArrow)
GdipDeletePen(arrowPen)
GdipDeleteGraphics(graphics)
END SUB
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
' // Create an instance of the CWindow class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Create the main window
LOCAL hwnd AS DWORD
hwnd = pWindow.CreateWindow(%NULL, "AdjustableArrowCapGetHeight", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
pWindow.SetClientSize 400, 250
' // Center the window
pWindow.CenterWindow
' // Add a GDI+ aware graphic control
LOCAL hCtrl AS DWORD
hCtrl = pWindow.AddGdipGraphCtx(hwnd, %IDC_GRCTX, "", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight)
GraphCtx_Clear(hCtrl, %WHITE)
' // Get the memory device context of the graphic control
LOCAL hdc AS DWORD
hdc = GraphCtx_GetDc(hCtrl)
' // Draw the graphics
Example_GetHeight(hdc)
' // Default message pump (you can replace it with your own)
pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
LOCAL hCtrl AS DWORD
LOCAL hDC AS DWORD
SELECT CASE uMsg
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hwnd, %WM_CLOSE, 0, 0
END IF
END SELECT
CASE %WM_DESTROY
' // Close the main window
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================