• Welcome to Jose's Read Only Forum 2023.
 

GDI+: AdjustableArrowCap Examples

Started by José Roca, November 03, 2011, 08:48:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The IGdipAdjustableArrowCap interface of the CGdipCustomLineCap class inherits from IGdipCustomLineCap. This interface builds a line cap that looks like an arrow.

José Roca

 
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
' ========================================================================================


José Roca

 
The following example creates an AdjustableArrowCap object, myArrow, with middle inset set to zero (default value). The code then creates a Pen object, assigns myArrow as the ending line cap for this Pen object, and draws a capped line. Next, the code gets the middle inset, increments it, and draws another capped line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapGetMiddleInset.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 object, myArrow, with middle
' inset set to zero (default value). The code then creates a Pen object, assigns
' myArrow as the ending line cap for this Pen object, and draws a capped line. Next,
' the code gets the middle inset, increments it, and draws another capped line.
' ========================================================================================
SUB Example_GetMiddleInset (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap with width and height set to 10.
'   // Middle inset defaults to 0 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, 10), Point(100, 10));
   graphics.DrawLine(arrowPen, 0, 10, 100, 10)

'   // Get the inset of the arrow.
'   REAL inset = myArrow.GetMiddleInset();
   LOCAL inset AS SINGLE
   inset = myArrow.GetMiddleInset

'   // Increase inset by 5 pixels and draw another line.
'   myArrow.SetMiddleInset(inset + 5);
'   arrowPen.SetCustomEndCap(&myArrow);
'   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 40));
   myArrow.SetMiddleInset(inset + 5)
   arrowPen.SetCustomEndCap(myArrow)
   graphics.DrawLine(arrowPen, 0, 40, 100, 40)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapGetMiddleInset", 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_GetMiddleInset(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_AdjustableArrowCapGetMiddleInset.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 object, myArrow, with middle
' inset set to zero (default value). The code then creates a Pen object, assigns
' myArrow as the ending line cap for this Pen object, and draws a capped line. Next,
' the code gets the middle inset, increments it, and draws another capped line.
' ========================================================================================
SUB Example_GetMiddleInset (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap with width and height set to 10.
'   // Middle inset defaults to 0 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, 10), Point(100, 10));
   GdipDrawLineI(graphics, arrowPen, 0, 10, 100, 10)

'   // Get the inset of the arrow.
'   REAL inset = myArrow.GetMiddleInset();
   LOCAL inset AS SINGLE
   GdipSetAdjustableArrowCapMiddleInset(myArrow, inset)

'   // Increase inset by 5 pixels and draw another line.
'   myArrow.SetMiddleInset(inset + 5);
'   arrowPen.SetCustomEndCap(&myArrow);
'   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 40));
   GdipSetAdjustableArrowCapMiddleInset(myArrow, inset + 5)
   GdipSetPenCustomEndCap(arrowPen, myArrow)
   GdipDrawLineI(graphics, arrowPen, 0, 40, 100, 40)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapGetMiddleInset", 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_GetMiddleInset(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
' ========================================================================================


José Roca

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


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapGetWidth.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 object, myArrow, and sets the width
' of the cap to 5 pixels. Next, the code creates a Pen object, assigns myArrow as the
' ending line cap for this Pen object, and draws a capped line. The code obtains the width
' using IGdipAdjustableArrowCap.GetWidth and sets the height equal to the width. The code then
' draws another capped line with the new cap.
' ========================================================================================
SUB Example_GetWidth (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap with a width of 10 pixels.
'   AdjustableArrowCap myArrow(10, 5, true);
   LOCAL myArrow AS IGdipAdjustableArrowCap
   myArrow = pGdip.AdjustableArrowCap(10, 5, %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)

'   // Get the width of the arrow.
'   REAL width = myArrow.GetWidth();
   LOCAL nWidth AS SINGLE
   nWidth = myArrow.GetWidth

'   // Draw a line using arrowPen.
'   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
   graphics.DrawLine(arrowPen, 0, 0, 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));
   myArrow.SetHeight(nWidth)
   arrowPen.SetCustomEndCap(myArrow)
   graphics.DrawLine(arrowPen, 0, 40, 100, 140)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapGetWidth", 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_GetWidth(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_AdjustableArrowCapGetWidth.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 object, myArrow, and sets the width
' of the cap to 5 pixels. Next, the code creates a Pen object, assigns myArrow 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.
' ========================================================================================
SUB Example_GetWidth (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap with a width of 10 pixels.
'   AdjustableArrowCap myArrow(10, 5, true);
   LOCAL myArrow AS DWORD
   GdipCreateAdjustableArrowCap(10, 5, %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)

'   // Get the width of the arrow.
'   REAL width = myArrow.GetWidth();
   LOCAL nWidth AS SINGLE
   GdipGetAdjustableArrowCapWidth(myArrow, nWidth)

'   // Draw a line using arrowPen.
'   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
   GdipDrawLineI(graphics, arrowPen, 0, 0, 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));
   GdipSetAdjustableArrowCapHeight(myArrow, nWidth)
   GdipSetPenCustomEndCap(arrowPen, myArrow)
   GdipDrawLineI(graphics, arrowPen, 0, 40, 100, 140)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapGetWidth", 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_GetWidth(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
' ========================================================================================


José Roca

 
The following example creates an AdjustableArrowCap object, myArrow, and sets the fill mode to TRUE. The code then creates a Pen object and assigns myArrow as the ending line cap for this Pen object. Next, the code tests whether myArrow is filled and, if it is, draws a line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapIsFilled.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 object, myArrow, and sets the fill
' mode to TRUE. The code then creates a Pen object and assigns myArrow as the ending line
' cap for this Pen object. Next, the code tests whether myArrow is filled and, if it is,
' draws a line.
' ========================================================================================
SUB Example_IsFilled (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap that is filled.
'   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)

'   // If the cap is filled, draw a line using arrowPen.
'   if (myArrow.IsFilled())
'   {
'       graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
'   }

   IF myArrow.IsFilled THEN
      graphics.DrawLine(arrowPen, 0, 0, 100, 100)
   END IF

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapIsFilled", 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_IsFilled(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_AdjustableArrowCapIsFilled.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 object, myArrow, and sets the fill
' mode to TRUE. The code then creates a Pen object and assigns myArrow as the ending line
' cap for this Pen object. Next, the code tests whether myArrow is filled and, if it is,
' draws a line.
' ========================================================================================
SUB Example_IsFilled (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap that is filled.
'   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)

'   // If the cap is filled, draw a line using arrowPen.
'   if (myArrow.IsFilled())
'   {
'       graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
'   }

   LOCAL isFilled AS LONG
   GdipGetAdjustableArrowCapFillState(myArrow, isFilled)
   IF isFilled THEN GdipDrawLine(graphics, arrowPen, 0, 0, 100, 100)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapIsFilled", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   pWindow.SetClientSize 400, 250
   ' // Center the window
   pWindow.CenterWindow

   ' // Add a GDI+ awarr 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_IsFilled(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
' ========================================================================================


José Roca

 
The following example creates an AdjustableArrowCap object, myArrow, and sets the fill mode to FALSE. The code then creates a Pen object and assigns myArrow as the ending line cap for this Pen object. Next, the code draws a line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapSetFillState.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 object, myArrow, and sets the fill
' mode to FALSE. The code then creates a Pen object and assigns myArrow as the ending
' line cap for this Pen object. Next, the code draws a line.
' ========================================================================================
SUB Example_SetFillState (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap. Fill state defaults to TRUE when
'   // arrow cap is constructed.
'   AdjustableArrowCap myArrow(10, 10);
   LOCAL myArrow AS IGdipAdjustableArrowCap
   myArrow = pGdip.AdjustableArrowCap(10, 10, %TRUE)

'   // Set fill state to FALSE.
'   myArrow.SetFillState(false);
   myArrow.SetFillState(%FALSE)

'   // 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, 0), Point(100, 100));
   graphics.DrawLine(arrowPen, 0, 0, 100, 100)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapSetFillState", 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_SetFillState(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_AdjustableArrowCapSetFillState.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 object, myArrow, and sets the fill
' mode to FALSE. The code then creates a Pen object and assigns myArrow as the ending
' line cap for this Pen object. Next, the code draws a line.
' ========================================================================================
SUB Example_SetFillState (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap. Fill state defaults to TRUE when
'   // arrow cap is constructed.
'   AdjustableArrowCap myArrow(10, 10);
   LOCAL myArrow AS DWORD
   GdipCreateAdjustableArrowCap(10, 10, %TRUE, myArrow)

'   // Set fill state to FALSE.
'   myArrow.SetFillState(false);
   GdipSetAdjustableArrowCapFillState(myArrow, %FALSE)

'   // 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, 0), Point(100, 100));
   GdipDrawLine(graphics, arrowPen, 0, 0, 100, 100)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapSetFillState", 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_SetFillState(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
' ========================================================================================


José Roca

 
The following example creates an AdjustableArrowCap, pMyArrowCap, and sets the height of the cap to 15 pixels. The code then creates a Pen and assigns pMyArrowCap as the ending line cap for this Pen. Next, the code draws a capped line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapSetHeight.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, pMyArrowCap, and sets the height of the
' cap to 15 pixels. The code then creates a Pen and assigns pMyArrowCap as the ending line cap
' for this Pen. Next, the code draws a capped line.
' ========================================================================================
SUB Example_SetHeight (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap with a width of 10 pixels.
'   AdjustableArrowCap myArrow(10, 5, true);
   LOCAL myArrow AS IGdipAdjustableArrowCap
   myArrow = pGdip.AdjustableArrowCap(10, 5, %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)

'   // Get the width of the arrow.
'   REAL width = myArrow.GetWidth();
   LOCAL nWidth AS SINGLE
   nWidth = myArrow.GetWidth

'   // Draw a line using arrowPen.
'   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
   graphics.DrawLine(arrowPen, 0, 0, 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));
   myArrow.SetHeight(nWidth)
   arrowPen.SetCustomEndCap(myArrow)
   graphics.DrawLine(arrowPen, 0, 40, 100, 140)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "GdipAdjustableArrowCapSetHeight", 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_SetHeight(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_AdjustableArrowCapSetHeight.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, pMyArrowCap, and sets the height of the
' cap to 15 pixels. The code then creates a Pen and assigns pMyArrowCap as the ending line cap
' for this Pen. Next, the code draws a capped line.
' ========================================================================================
SUB Example_SetHeight (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap with a width of 10 pixels.
'   AdjustableArrowCap myArrow(10, 5, true);
   LOCAL myArrow AS DWORD
   GdipCreateAdjustableArrowCap(10, 5, %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)

'   // Get the width of the arrow.
'   REAL width = myArrow.GetWidth();
   LOCAL nWidth AS SINGLE
   GdipGetAdjustableArrowCapWidth(myArrow, nWidth)

'   // Draw a line using arrowPen.
'   graphics.DrawLine(&arrowPen, Point(0, 0), Point(100, 100));
   GdipDrawLine(graphics, arrowPen, 0, 0, 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));
   GdipSetAdjustableArrowCapHeight(myArrow, nWidth)
   GdipSetPenCustomEndCap(arrowPen, myArrow)
   GdipDrawLine(graphics, arrowPen, 0, 40, 100, 140)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "GdipAdjustableArrowCapSetHeight", 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_SetHeight(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
' ========================================================================================



José Roca

 
The following example creates an AdjustableArrowCap object, myArrow, and sets the middle inset of the cap to 5 pixels. The code then creates a Pen object and assigns myArrow as the ending line cap for this Pen object. Next, the code draws a capped line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapSetMiddleInset.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 object, myArrow, and sets the middle
' inset of the cap to 5 pixels. The code then creates a Pen object and assigns myArrow as
' the ending line cap for this Pen object. Next, the code draws a capped line.
' ========================================================================================
SUB Example_SetMiddleInset (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap, and set the middle inset to 5.
'   AdjustableArrowCap myArrow(10, 10, true);
'   myArrow.SetMiddleInset(5.0f);
   LOCAL myArrow AS IGdipAdjustableArrowCap
   myArrow = pGdip.AdjustableArrowCap(10, 10, %TRUE)
   myArrow.SetMiddleInset(5)

'   // 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, 0), Point(100, 100));
   graphics.DrawLine(arrowPen, 0, 0, 100, 100)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapSetMiddleInset", 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_SetMiddleInset(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_AdjustableArrowCapSetMiddleInset.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 object, myArrow, and sets the middle
' inset of the cap to 5 pixels. The code then creates a Pen object and assigns myArrow as
' the ending line cap for this Pen object. Next, the code draws a capped line.
' ========================================================================================
SUB Example_SetMiddleInset (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap, and set the middle inset to 5.
'   AdjustableArrowCap myArrow(10, 10, true);
'   myArrow.SetMiddleInset(5.0f);
   LOCAL myArrow AS DWORD
   GdipCreateAdjustableArrowCap(10, 10, %TRUE, myArrow)
   GdipSetAdjustableArrowCapMiddleInset(myArrow, 5)

'   // 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, 0), Point(100, 100));
   GdipDrawLine(graphics, arrowPen, 0, 0, 100, 100)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "AdjustableArrowCapSetMiddleInset", 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_SetMiddleInset(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
' ========================================================================================


José Roca

 
The following example creates an AdjustableArrowCap, myArrow, and sets the width of the cap to 10 pixels. The code then creates a Pen, assigns myArrow as the ending line cap for this Pen, and draws a capped line. Next, the code sets the width to 15 pixels, reassigns the arrow cap to the pen, and draws a new capped line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_AdjustableArrowCapSetWidth.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 width of
' the cap to 10 pixels. The code then creates a Pen, assigns myArrow as the ending
' line cap for this Pen, and draws a capped line. Next, the code sets the width to 15
' pixels, reassigns the arrow cap to the pen, and draws a new capped line.
' ========================================================================================
SUB Example_SetWidth (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

'   // Create an AdjustableArrowCap, and set the middle inset to 5.
'   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, 0), Point(100, 100));
   graphics.DrawLine(arrowPen, 0, 0, 100, 100)

'   // Set the cap to the new width, and reassign the arrow cap
'   // to the pen object.
'   myArrow.SetWidth(15.7f);
'   arrowPen.SetCustomEndCap(&myArrow);
   myArrow.SetWidth(15.7!)
   arrowPen.SetCustomEndCap(myArrow)

'   // Draw a line with new cap.
'   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 140));
   graphics.DrawLine(arrowPen, 0, 40, 100, 140)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "GdipSetAdjustableArrowCapWidth", 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_SetWidth(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_AdjustableArrowCapSetWidth.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 width of
' the cap to 10 pixels. The code then creates a Pen, assigns myArrow as the ending
' line cap for this Pen, and draws a capped line. Next, the code sets the width to 15
' pixels, reassigns the arrow cap to the pen, and draws a new capped line.
' ========================================================================================
SUB Example_SetWidth (BYVAL hdc AS DWORD)

'   Graphics graphics(hdc);
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

'   // Create an AdjustableArrowCap, and set the middle inset to 5.
'   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, 0), Point(100, 100));
   GdipDrawLine(graphics, arrowPen, 0, 0, 100, 100)

'   // Set the cap to the new width, and reassign the arrow cap
'   // to the pen object.
'   myArrow.SetWidth(15.7f);
'   arrowPen.SetCustomEndCap(&myArrow);
   GdipSetAdjustableArrowCapWidth(myArrow, 15.7!)
   GdipSetPenCustomEndCap(arrowPen, myArrow)

'   // Draw a line with new cap.
'   graphics.DrawLine(&arrowPen, Point(0, 40), Point(100, 140));
   GdipDrawLine(graphics, arrowPen, 0, 40, 100, 140)

   ' // Cleanup
   GdipDeleteCustomLineCap(myArrow)
   GdipDeletePen(arrowPen)
   GdipDeleteGraphics(graphics)

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ 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, "GdipSetAdjustableArrowCapWidth", 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_SetWidth(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
' ========================================================================================


José Roca

 
The following example creates two AdjustableArrowCap objects, arrowCapStart and arrowCapEnd, and sets the fill mode to TRUE. The code then creates a Pen object and assigns arrowCapStart as the starting line cap for this Pen object and arrowCapEnd as the ending line cap. Next, draws a line.


' ########################################################################################
' Microsoft Windows
' File: CGDIP_CreateAdjustableArrowCap.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 two AdjustableArrowCap objects, arrowCapStart and
' arrowCapEnd, and sets the fill mode to TRUE. The code then creates a Pen object and
' assigns arrowCapStart as the starting line cap for this Pen object and arrowCapEnd as
' the ending line cap. Next, draws a line.
' ========================================================================================
SUB Example_CreateAdjustableArrowCap (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)

   ' // Create a Graphics object
   LOCAL graphics AS IGdipGraphics
   graphics = pGdip.Graphics(hdc)

   ' // Create an AdjustableArrowCap that is filled
   LOCAL arrowCapStart AS IGdipAdjustableArrowCap
   arrowCapStart = pGdip.AdjustableArrowCap(10, 10, %TRUE)

   ' // Create an AdjustableArrowCap that is not filled
   LOCAL arrowCapEnd AS IGdipAdjustableArrowCap
   arrowCapEnd = pGdip.AdjustableArrowCap(15, 15, %FALSE)

   ' // Create a Pen
   LOCAL arrowPen AS IGdipPen
   arrowPen = pGdip.Pen(pGdip.Color(255, 0, 0, 0), 1)

   ' // Assign arrowStart as the start cap.
   arrowPen.SetCustomStartCap(arrowCapStart)

   ' // Assign arrowEnd as the end cap.
   arrowPen.SetCustomEndCap(arrowCapEnd)

   ' // Draw a line using arrowPen
   graphics.DrawLine(arrowPen, 0, 0, 100, 100)

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, "GdipCreateAdjustableArrowCap", 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_CreateAdjustableArrowCap(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_CreateAdjustableArrowCap.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.03+
' 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"    ' // GdipPlus API

%IDC_GRCTX = 1001

' ========================================================================================
' The following example creates two AdjustableArrowCap objects, arrowCapStart and
' arrowCapEnd, and sets the fill mode to TRUE. The code then creates a Pen object and
' assigns arrowCapStart as the starting line cap for this Pen object and arrowCapEnd as
' the ending line cap. Next, draws a line.
' ========================================================================================
SUB Example_CreateAdjustableArrowCap (BYVAL hdc AS DWORD)

   ' // Create a Graphics object
   LOCAL graphics AS DWORD
   GdipCreateFromHDC(hdc, graphics)

   ' // Create an AdjustableArrowCap that is filled
   LOCAL arrowCapStart AS DWORD
   GdipCreateAdjustableArrowCap(10, 10, %TRUE, arrowCapStart)

   ' // Create an AdjustableArrowCap that is not filled
   LOCAL arrowCapEnd AS DWORD
   GdipCreateAdjustableArrowCap(15, 15, %FALSE, arrowCapEnd)

   ' // Create a Pen
   LOCAL arrowPen AS DWORD
   GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1.0!, %UnitWorld, arrowPen)

   ' // Assign arrowStart as the start cap.
   GdipSetPenCustomStartCap(arrowPen, arrowCapStart)

   ' // Assign arrowEnd as the end cap.
   GdipSetPenCustomEndCap(arrowPen, arrowCapEnd)

   ' // Draw a line using arrowPen
   GdipDrawLine(graphics, arrowPen, 0, 0, 100, 100)

   ' // Cleanup
   GdipDeleteCustomLineCap(arrowCapStart)
   GdipDeleteCustomLineCap(arrowCapEnd)
   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, "GdipCreateAdjustableArrowCap", 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_CreateAdjustableArrowCap(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
' ========================================================================================