Function Reference


_GDIPlus_GraphicsDrawRect

Draw a rectangle

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

Parameters

$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 ($GPIP_ERR* see GPIPlusConstants.au3).

See Also

Search GdipDrawRectangle in MSDN Library.

Example

Example 1

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

Example()

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

        ; Initialize GDI+ library
        _GDIPlus_Startup()

        ; 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
        _GDIPlus_ImageDispose($hImage1)
        _GDIPlus_ImageDispose($hImage2)
        _WinAPI_DeleteObject($hBitmap1)
        _WinAPI_DeleteObject($hBitmap2)

        ; Shut down GDI+ library
        _GDIPlus_Shutdown()

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

Example 2

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

Example()

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
        GUISetState(@SW_SHOW)

        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)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ;cleanup GDI+ resources
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
EndFunc   ;==>Example