Function Reference


Draw a rectangle

#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawRect ( $hGraphics, $nX, $nY, $nWidth, $nHeight [, $hPen = 0] )


$hGraphics Handle to a Graphics object
$nX The X coordinate of the upper left corner of the rectangle
$nY The Y coordinate of the upper left corner of the rectangle
$nWidth The width of the rectangle
$nHeight The height of the rectangle
$hPen [optional] Handle to a pen object that is used to draw the rectangle. If 0, a solid black pen with a width of 1 will be used

Return Value

Success: True.
Failure: False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).

See Also

Search GdipDrawRectangle in MSDN Library.


Example 1

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>


Func Example()
    Local $hBitmap1, $hBitmap2, $hImage1, $hImage2, $hGraphics

    ; Initialize GDI+ library

    ; Capture full screen
    $hBitmap1 = _ScreenCapture_Capture("")
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap1)

    ; Capture screen region
    $hBitmap2 = _ScreenCapture_Capture("", 0, 0, 400, 300)
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)

    ; Draw one image in another
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage2, 100, 100)

    ; Draw a frame around the inserted image
    _GDIPlus_GraphicsDrawRect($hGraphics, 100, 100, 400, 300)

    ; Save resultant image
    _GDIPlus_ImageSaveToFile($hImage1, @MyDocumentsDir & "\GDIPlus_Image.jpg")

    ; Clean up resources

    ; Shut down GDI+ library

    ShellExecute(@MyDocumentsDir & "\GDIPlus_Image.jpg")
EndFunc   ;==>Example

Example 2

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


Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBgColor format RRGGBB

    Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
    GUISetBkColor($iBgColor, $hGUI) ;set GUI background color

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
    Local $hPen = _GDIPlus_PenCreate(0xFFFEDCBA, 4) ;color format AARRGGBB (hex)

    _GDIPlus_GraphicsDrawRect($hGraphics, 150.5, 50.1, 280.25, 500.75, $hPen)

    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
EndFunc   ;==>Example