# Gdip [v1.38]

Author: tic Last Modified: 20100828

AutoHotkey does not provide native support for GDI+. With these functions it is possible to work with the GDI+. With that we have the ability to draw shapes or manipulate images.
From Wikipedia, the free encyclopedia:
(http://en.wikipedia.org/wiki/GdiPlus)
"The Graphics Device Interface (GDI) is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers."

Gdip_AddPathEllipse(Path, x, y, w, h)
Gdip_AddPathPolygon(Path, Points)
Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
Gdip_BitmapFromHWND(hwnd)
Gdip_BitmapFromScreen(Screen=0, Raster="")
Gdip_BlurBitmap(pBitmap, Blur)
Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
Gdip_BrushCreateSolid(ARGB=0xff000000)
Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
Gdip_CloneBrush(pBrush)
Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
Gdip_CreateBitmap(Width, Height, Format=0x26200A)
Gdip_CreateBitmapFromClipboard()
Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
Gdip_CreateBitmapFromHICON(hIcon)
Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
Gdip_CreateHICONFromBitmap(pBitmap)
Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
Gdip_CreateMatrix()
Gdip_CreatePath(BrushMode=0)
Gdip_CreatePen(ARGB, w)
Gdip_CreatePenFromBrush(pBrush, w)
Gdip_CreateRegion()
Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
Gdip_DeleteBrush(pBrushClear)
Gdip_DeleteFont(hFont)
Gdip_DeleteFontFamily(hFamily)
Gdip_DeleteGraphics(G)
Gdip_DeleteMatrix(Matrix)
Gdip_DeletePath(Path)
Gdip_DeletePen(pPen)
Gdip_DeleteRegion(Region)
Gdip_DeleteStringFormat(hFormat)
Gdip_DisposeImage(pBitmap1)
Gdip_DisposeImageAttributes(ImageAttr)
Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
Gdip_DrawLines(pGraphics, pPen, Points)
Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
Gdip_FillPath(pGraphics, pBrush, Path)
Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
Gdip_FillRegion(pGraphics, pBrush, Region)
Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
Gdip_FontCreate(hFamily, Size, Style=0)
Gdip_FontFamilyCreate(Font)
Gdip_GetClipRegion(pGraphics)
Gdip_GetDC(pGraphics)
Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
Gdip_GetDpiX(pGraphics)
Gdip_GetDpiY(pGraphics)
Gdip_GetImageHeight(pBitmap)
Gdip_GetImageHorizontalResolution(pBitmap)
Gdip_GetImagePixelFormat(pBitmap)
Gdip_GetImageVerticalResolution(pBitmap)
Gdip_GetImageWidth(pBitmap)
Gdip_GetPixel(pBitmap, x, y)
Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
Gdip_GraphicsFromHDC(hdc)
Gdip_GraphicsFromImage(pBitmap)
Gdip_LibraryVersion()
Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
Gdip_ReleaseDC(pGraphics, hdc)
Gdip_ResetClip(pGraphics)
Gdip_ResetWorldTransform(pGraphics)
Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
Gdip_SetImageAttributesColorMatrix(Matrix)
Gdip_SetInterpolationMode(G1, 7)
Gdip_SetPixel(pBitmap, x, y, ARGB)
Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
Gdip_SetStringFormatAlign(hFormat, Align)
Gdip_SetTextRenderingHint(pGraphics, Rendering)
Gdip_Shutdown(pToken)
Gdip_Startup()
Gdip_StringFormatCreate(Format=0, Lang=0)
Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)

For more details of the functions's parameters and return value, please see it's source code.

#### Remarks

It is not strictly stdlib conform, because some public functions have a name without a prefix.
If your OS is not >= XP then you will need gdiplus.dll.
You will need to place it in the same directory as the script
Minimum OS is Windows 2000

For update's details and remarks related to the functions, please see the AutoHotkey Forum: http://www.autohotkey.com/forum/viewtopic.php?t=32238

#### License

The functions is an open source item under the free license. For details, please see tic_gdip-license.txt

#### Example

    ; gdi+ ahk tutorial 1 written by tic (Tariq Porter)
    ; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
    ;
    ; Tutorial to draw a single ellipse and rectangle to the screen

    #SingleInstance, Force
    #NoEnv
    SetBatchLines, -1

    ; Uncomment if Gdip.ahk is not in your standard library
    ;#Include, Gdip.ahk

    ; Start gdi+
    If !pToken := Gdip_Startup()
    {
    	MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    	ExitApp
    }
    OnExit, Exit

    ; Set the width and height we want as our drawing area, to draw everything in. This will be the dimensions of our bitmap
    Width := 600, Height := 400

    ; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
    Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop

    ; Show the window
    Gui, 1: Show, NA

    ; Get a handle to this window we have created in order to update it later
    hwnd1 := WinExist()

    ; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
    hbm := CreateDIBSection(Width, Height)

    ; Get a device context compatible with the screen
    hdc := CreateCompatibleDC()

    ; Select the bitmap into the device context
    obm := SelectObject(hdc, hbm)

    ; Get a pointer to the graphics of the bitmap, for use with drawing functions
    G := Gdip_GraphicsFromHDC(hdc)

    ; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
    Gdip_SetSmoothingMode(G, 4)

    ; Create a fully opaque red brush (ARGB = Transparency, red, green, blue) to draw a circle
    pBrush := Gdip_BrushCreateSolid(0xffff0000)

    ; Fill the graphics of the bitmap with an ellipse using the brush created
    ; Filling from coordinates (100,50) an ellipse of 200x300
    Gdip_FillEllipse(G, pBrush, 100, 50, 200, 300)

    ; Delete the brush as it is no longer needed and wastes memory
    Gdip_DeleteBrush(pBrush)

    ; Create a slightly transparent (66) blue brush (ARGB = Transparency, red, green, blue) to draw a rectangle
    pBrush := Gdip_BrushCreateSolid(0x660000ff)

    ; Fill the graphics of the bitmap with a rectangle using the brush created
    ; Filling from coordinates (250,80) a rectangle of 300x200
    Gdip_FillRectangle(G, pBrush, 250, 80, 300, 200)

    ; Delete the brush as it is no longer needed and wastes memory
    Gdip_DeleteBrush(pBrush)

    ; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
    ; So this will position our gui at (0,0) with the Width and Height specified earlier
    UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)

    ; Select the object back into the hdc
    SelectObject(hdc, obm)

    ; Now the bitmap may be deleted
    DeleteObject(hbm)

    ; Also the device context related to the bitmap may be deleted
    DeleteDC(hdc)

    ; The graphics may now be deleted
    Gdip_DeleteGraphics(G)
    Return

    ;#######################################################################

    Exit:
    ; gdi+ may now be shutdown on exiting the program
    Gdip_Shutdown(pToken)
    ExitApp
    Return