The following example creates a CustomLineCap object with a stroke join. It then gets the stroke join and assigns it as the line join of a Pen object that it then uses to draw a line.
' ########################################################################################
' Microsoft Windows
' File: CGDIP_CustomLineCapSetStrokeJoin.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.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 "CGdiPlus.inc" ' // CWindow class
%IDC_GRCTX = 1001
' ========================================================================================
' The following example creates a CustomLineCap object with a stroke join. It then gets the
' stroke join and assigns it as the line join of a Pen object that it then uses to draw a line.
' ========================================================================================
SUB Example_SetStrokeJoin (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)
' Graphics graphics(hdc);
LOCAL graphics AS IGdipGraphics
graphics = pGdip.Graphics(hdc)
' // Create a Path, and add two lines to it.
' Point points[3] = {Point(-15, -15), Point(0, 0), Point(15, -15)};
' GraphicsPath capPath;
' capPath.AddLines(points, 3);
DIM pts(2) AS POINTF
pts(0) = pGdip.PointF(-15, -15)
pts(1) = pGdip.PointF(0, 0)
pts(2) = pGdip.PointF(15, -15)
LOCAL capPath AS IGdipGraphicsPath
capPath = pGdip.GraphicsPath(%FillModeAlternate)
capPath.AddLines(pts(0), 3)
' // Create a CustomLineCap object.
' CustomLineCap custCap(NULL, &capPath);
LOCAL custCap AS IGdipCustomLineCap
custCap = pGdip.CustomLineCap(NOTHING, capPath)
' // Set the stroke join for custCap.
' custCap.SetStrokeJoin(LineJoinBevel);
custCap.SetStrokeJoin(%LineJoinBevel)
' // Create a Pen object, assign custCap to a Pen object, and draw a line.
' Pen strokeJoinPen(Color(255, 200, 150, 0), 5.0f);
' strokeJoinPen.SetCustomEndCap(&custCap);
' graphics.DrawLine(&strokeJoinPen, Point(0, 0), Point(200, 200));
LOCAL strokeJoinPen AS IGdipPen
strokeJoinPen = pGdip.Pen(pGdip.Color(255, 255, 0, 0), 15.1!)
strokeJoinPen.SetCustomEndCap(custCap)
graphics.DrawLine(strokeJoinPen, 0, 0, 200, 200)
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, "CustomLineCapSetStrokeJoin", 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_SetStrokeJoin(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
' ========================================================================================
The following example creates a CustomLineCap object with a stroke join. It then gets the stroke join and assigns it as the line join of a Pen object that it then uses to draw a line.
' ########################################################################################
' Microsoft Windows
' File: CGDIP_CustomLineCapSetStrokeJoin2.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.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 "CGdiPlus.inc" ' // CWindow class
%IDC_GRCTX = 1001
' ========================================================================================
' The following example creates a CustomLineCap object with a stroke join. It then gets the
' stroke join and assigns it as the line join of a Pen object that it then uses to draw a line.
' ========================================================================================
SUB Example_SetStrokeJoin (BYVAL pGdip AS IGdiPlus, BYVAL hdc AS DWORD)
' Graphics graphics(hdc);
LOCAL graphics AS IGdipGraphics
graphics = pGdip.Graphics(hdc)
' // Create a Path, and add two lines to it.
' Point points[3] = {Point(-15, -15), Point(0, 0), Point(15, -15)};
' GraphicsPath capPath;
' capPath.AddLines(points, 3);
DIM pts(2) AS POINTF
pts(0) = pGdip.PointF(-15, -15)
pts(1) = pGdip.PointF(0, 0)
pts(2) = pGdip.PointF(15, -15)
LOCAL capPath AS IGdipGraphicsPath
capPath = pGdip.GraphicsPath(%FillModeAlternate)
capPath.AddLines(pts(0), 3)
' // Create a CustomLineCap object.
LOCAL custCap AS IGdipCustomLineCap
custCap = pGdip.CustomLineCap(NOTHING, capPath, %LineCapFlat)
' // Set the stroke join for custCap.
custCap.SetStrokeJoin(%LineJoinBevel)
' // Create a Pen object, assign custCap to a Pen object, and draw a line.
LOCAL strokeJoinPen AS IGdipPen
strokeJoinPen = pGdip.Pen(pGdip.Color(255, 200, 150, 0), 5.0!)
strokeJoinPen.SetCustomEndCap(custCap)
graphics.DrawLine(strokeJoinPen, 0, 0, 200, 200)
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, "CustomLineCapSetStrokeJoin", 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.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_SetStrokeJoin(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
' ========================================================================================