# Function Reference

# _GDIPlus_PenCreate2

Creates a Pen object that uses the attributes of a brush

#include <GDIPlus.au3>
_GDIPlus_PenCreate2 ( $hBrush [, $nWidth = 1 [, $iUnit = 2]] )

## Parameters

$hBrush | Pointer to a brush object to base this pen on
$nWidth | [optional] The width of the pen measured in the units specified in the $iUnit parameter
$iUnit | [optional] Unit of measurement for the pen size: 0 - World coordinates, a nonphysical unit 1 - Display units 2 - A unit is 1 pixel 3 - A unit is 1 point or 1/72 inch 4 - A unit is 1 inch 5 - A unit is 1/300 inch 6 - A unit is 1 millimeter

## Return Value

Success: | a pointer to a new Pen object.
Failure: | 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GDIP_ERR* see GPIPlusConstants.au3).

## Remarks

After you are done with the object, call _GDIPlus_PenDispose() to release the object resources.

## Related

_GDIPlus_PenDispose

## See Also

Search GdipCreatePen2 in MSDN Library.

## Example

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>

    Example()

    Func Example()
        Local $hGUI = GUICreate("GDI+", 800, 400)
        GUISetState(@SW_SHOW)

        _GDIPlus_Startup()
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        Local $hBmp_Buffer = _GDIPlus_BitmapCreateFromGraphics(800, 400, $hGraphics)
        Local $hGfx_Buffer = _GDIPlus_ImageGetGraphicsContext($hBmp_Buffer)
        _GDIPlus_GraphicsSetSmoothingMode($hGfx_Buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
        _GDIPlus_GraphicsClear($hGfx_Buffer, 0xFF000000)

        Local $hPath = _GDIPlus_PathCreate()
        Local $hFormat = _GDIPlus_StringFormatCreate()
        _GDIPlus_StringFormatSetAlign($hFormat, 1)
        Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        Local $tLayout = _GDIPlus_RectFCreate(0, 0, 800, 400)
        _GDIPlus_PathAddString($hPath, "AutoIt rulez!", $tLayout, $hFamily, 0, 140, $hFormat)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_FontFamilyDispose($hFamily)

        Local $aPoints[5][2] = [[4]]
        $aPoints[1][0] = 0
        $aPoints[1][1] = 0
        $aPoints[2][0] = 20
        $aPoints[2][1] = 0
        $aPoints[3][0] = 20
        $aPoints[3][1] = 20
        $aPoints[4][0] = 0
        $aPoints[4][1] = 20

        Local $aColors[4] = [3]
        $aColors[1] = 0xFFFF0000
        $aColors[2] = 0xFF00FF00
        $aColors[3] = 0xFF0000FF

        Local $hMatrix = _GDIPlus_MatrixCreate()
        _GDIPlus_MatrixRotate($hMatrix, 1, True)

        Local $hBrush, $hPen

        Local $hTimer = TimerInit()
        ; Loop until the user exits.
        Do
            If TimerDiff($hTimer) > 40 Then
                _GDIPlus_MatrixTransformPoints($hMatrix, $aPoints)

                $hBrush = _GDIPlus_PathBrushCreate($aPoints, 3)
                _GDIPlus_PathBrushSetCenterColor($hBrush, 0xFFFFFFFF)
                _GDIPlus_PathBrushSetSurroundColorsWithCount($hBrush, $aColors)
                $hPen = _GDIPlus_PenCreate2($hBrush, 6)
                _GDIPlus_PenSetLineJoin($hPen, $GDIP_PENSETLINEJOIN_ROUND)
                _GDIPlus_BrushDispose($hBrush)

                _GDIPlus_GraphicsClear($hGfx_Buffer, 0xFF000000)
                _GDIPlus_GraphicsDrawPath($hGfx_Buffer, $hPath, $hPen)
                _GDIPlus_PenDispose($hPen)

                _GDIPlus_GraphicsDrawImage($hGraphics, $hBmp_Buffer, 0, 0)
                $hTimer = TimerInit()
            EndIf
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Clean up resources
        _GDIPlus_PathDispose($hPath)
        _GDIPlus_MatrixDispose($hMatrix)
        _GDIPlus_GraphicsDispose($hGfx_Buffer)
        _GDIPlus_BitmapDispose($hBmp_Buffer)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
    EndFunc   ;==>Example