Function Reference


_GDIPlus_PenCreate

Create a pen object

#include <GDIPlus.au3>
_GDIPlus_PenCreate ( [$iARGB = 0xFF000000 [, $nWidth = 1 [, $iUnit = 2]]] )

Parameters

$iARGB [optional] Alpha, Red, Green and Blue components of pen color
$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 handle to a pen object.
Failure: 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).

Remarks

When you are done with the pen, call _GDIPlus_PenDispose() to release the resources.

Related

_GDIPlus_PenDispose

See Also

Search GdipCreatePen1 in MSDN Library.

Example

Example 1

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

Example()

Func Example()
    Local $hGUI, $hGraphic, $hPen

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState(@SW_SHOW)

    ; Draw line
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hPen = _GDIPlus_PenCreate()
    _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example

Example 2

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

Global $g_hGUI, $g_hGraphics, $g_hBitmap, $g_hGfxCtxt, $g_hPen

Example()

Func Example()
    AutoItSetOption("GUIOnEventMode", 1)

    _GDIPlus_Startup() ;initialize GDI+
    Local $iW = 600, $iH = 600
    Local Const $iBgColor = 0x303030 ;$iBGColor format RRGGBB

    $g_hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iW, $iH) ;create a test GUI
    GUISetBkColor($iBgColor, $g_hGUI) ;set GUI background color
    GUISetState(@SW_SHOW)

    ;create buffered graphics frame set for smoother gfx object movements
    $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $g_hGraphics)
    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
    $g_hPen = _GDIPlus_PenCreate(0xFF8080FF, 2)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    Local Const $fDeg = ACos(-1) / 180, $iRadius = 300, $iWidth = $iW / 2, $iHeight = $iH / 2
    Local $fAngle = 0

    Do
        _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ;clear bitmap for repaint
        _GDIPlus_GraphicsDrawEllipse($g_hGfxCtxt, $iWidth - $iRadius / 2 + $iRadius / 18, $iHeight - $iRadius / 2 + $iRadius / 18, $iRadius - $iRadius / 9, $iRadius - $iRadius / 9, $g_hPen) ;draw ellipse
        _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, $iWidth + Cos($fAngle * $fDeg) * $iRadius, $iHeight + Sin($fAngle * $fDeg) * $iRadius, _ ;draw line
                $iWidth + Cos($fAngle * $fDeg + 180) * $iRadius, $iHeight + Sin($fAngle * $fDeg + 180) * $iRadius, $g_hPen)

        _GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iW, $iH) ;copy drawn bitmap to graphics handle (GUI)
        $fAngle += 0.5
    Until Not Sleep(20) ;sleep 20 ms to avoid high cpu usage
EndFunc   ;==>Example

Func _Exit()
    ;cleanup GDI+ resources
    _GDIPlus_PenDispose($g_hPen)
    _GDIPlus_GraphicsDispose($g_hGfxCtxt)
    _GDIPlus_GraphicsDispose($g_hGraphics)
    _GDIPlus_BitmapDispose($g_hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($g_hGUI)
    Exit
EndFunc   ;==>_Exit