diff --git a/Gdip_All.ahk b/Gdip_All.ahk index 69ac2da..5d2baac 100644 --- a/Gdip_All.ahk +++ b/Gdip_All.ahk @@ -81,18 +81,18 @@ UpdateLayeredWindow(hwnd, hdc, x:="", y:="", w:="", h:="", Alpha:=255) { Ptr := A_PtrSize ? "UPtr" : "UInt" - + if ((x != "") && (y != "")) VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt") - + if (w = "") || (h = "") - { + { CreateRect( winRect, 0, 0, 0, 0 ) ;is 16 on both 32 and 64 DllCall( "GetWindowRect", Ptr, hwnd, Ptr, &winRect ) w := NumGet(winRect, 8, "UInt") - NumGet(winRect, 0, "UInt") h := NumGet(winRect, 12, "UInt") - NumGet(winRect, 4, "UInt") } - + return DllCall("UpdateLayeredWindow" , Ptr, hwnd , Ptr, 0 @@ -325,6 +325,7 @@ SetSysColorToControl(hwnd, SysColor:=15) Gdip_BitmapFromScreen(Screen:=0, Raster:="") { + hhdc := 0 Ptr := A_PtrSize ? "UPtr" : "UInt" if (Screen = 0) { @@ -355,14 +356,14 @@ Gdip_BitmapFromScreen(Screen:=0, Raster:="") S := StrSplit(Screen, "|") _x := S[1], _y := S[2], _w := S[3], _h := S[4] } - + if (_x = "") || (_y = "") || (_w = "") || (_h = "") return -1 - + chdc := CreateCompatibleDC(), hbm := CreateDIBSection(_w, _h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC() BitBlt(chdc, 0, 0, _w, _h, hhdc, _x, _y, Raster) ReleaseDC(hhdc) - + pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc) return pBitmap @@ -731,6 +732,8 @@ Gdip_LibrarySubVersion() ; -4 = Could not find file inside the BRA Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate := 0) { + pBitmap := "" + If !(BRAFromMemIn) Return -1 Headers := StrSplit(StrGet(&BRAFromMemIn, 256, "CP0"), "`n") @@ -1489,28 +1492,31 @@ Gdip_BlurBitmap(pBitmap, Blur) Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75) { Ptr := A_PtrSize ? "UPtr" : "UInt" - + nCount := 0 + nSize := 0 + _p := 0 + SplitPath sOutput,,, Extension if !RegExMatch(Extension, "^(?i:BMP|DIB|RLE|JPG|JPEG|JPE|JFIF|GIF|TIF|TIFF|PNG)$") return -1 Extension := "." Extension - + DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize) VarSetCapacity(ci, nSize) DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci) if !(nCount && nSize) return -2 - + If (A_IsUnicode){ StrGet_Name := "StrGet" - + N := (A_AhkVersion < 2) ? nCount : "nCount" Loop %N% { sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16") if !InStr(sString, "*" Extension) continue - + pCodec := &ci+idx break } @@ -1524,15 +1530,15 @@ Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75) DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0) if !InStr(sString, "*" Extension) continue - + pCodec := &ci+76*(A_Index-1) break } } - + if !pCodec return -3 - + if (Quality != 75) { Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality @@ -1555,7 +1561,7 @@ Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75) } } } - + if (!A_IsUnicode) { nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0) @@ -1584,6 +1590,8 @@ Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality:=75) Gdip_GetPixel(pBitmap, x, y) { + ARGB := 0 + DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB) return ARGB } @@ -1798,6 +1806,7 @@ Gdip_CreateBitmapFromFile(sFile, IconNumber:=1, IconSize:="") Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette:=0) { Ptr := A_PtrSize ? "UPtr" : "UInt" + pBitmap := "" DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap) return pBitmap @@ -1815,6 +1824,8 @@ Gdip_CreateHBITMAPFromBitmap(pBitmap, Background:=0xffffffff) Gdip_CreateBitmapFromHICON(hIcon) { + pBitmap := "" + DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap) return pBitmap } @@ -1823,6 +1834,9 @@ Gdip_CreateBitmapFromHICON(hIcon) Gdip_CreateHICONFromBitmap(pBitmap) { + pBitmap := "" + hIcon := 0 + DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon) return hIcon } @@ -1831,6 +1845,8 @@ Gdip_CreateHICONFromBitmap(pBitmap) Gdip_CreateBitmap(Width, Height, Format:=0x26200A) { + pBitmap := "" + DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap) Return pBitmap } @@ -1904,6 +1920,8 @@ Gdip_CreatePen(ARGB, w) Gdip_CreatePenFromBrush(pBrush, w) { + pPen := "" + DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen) return pPen } @@ -1912,6 +1930,8 @@ Gdip_CreatePenFromBrush(pBrush, w) Gdip_BrushCreateSolid(ARGB:=0xff000000) { + pBrush := "" + DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush) return pBrush } @@ -1974,6 +1994,8 @@ Gdip_BrushCreateSolid(ARGB:=0xff000000) ; HatchStyleTotal = 53 Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle:=0) { + pBrush := "" + DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush) return pBrush } @@ -2101,7 +2123,7 @@ Gdip_DeleteMatrix(Matrix) Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:="", Measure:=0) { IWidth := Width, IHeight:= Height - + pattern_opts := (A_AhkVersion < "2") ? "iO)" : "i)" RegExMatch(Options, pattern_opts "X([\-\d\.]+)(p*)", xpos) RegExMatch(Options, pattern_opts "Y([\-\d\.]+)(p*)", ypos) @@ -2112,27 +2134,27 @@ Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:= RegExMatch(Options, pattern_opts "NoWrap", NoWrap) RegExMatch(Options, pattern_opts "R(\d)", Rendering) RegExMatch(Options, pattern_opts "S(\d+)(p*)", Size) - + if Colour && !Gdip_DeleteBrush(Gdip_CloneBrush(Colour[2])) PassBrush := 1, pBrush := Colour[2] - + if !(IWidth && IHeight) && ((xpos && xpos[2]) || (ypos && ypos[2]) || (Width && Width[2]) || (Height && Height[2]) || (Size && Size[2])) return -1 - + Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout" For eachStyle, valStyle in StrSplit( Styles, "|" ) { if RegExMatch(Options, "\b" valStyle) Style |= (valStyle != "StrikeOut") ? (A_Index-1) : 8 } - + Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right" For eachAlignment, valAlignment in StrSplit( Alignments, "|" ) { if RegExMatch(Options, "\b" valAlignment) Align |= A_Index//2.1 ; 0|0|1|1|2|2 } - + xpos := (xpos && (xpos[1] != "")) ? xpos[2] ? IWidth*(xpos[1]/100) : xpos[1] : 0 ypos := (ypos && (ypos[1] != "")) ? ypos[2] ? IHeight*(ypos[1]/100) : ypos[1] : 0 Width := (Width && Width[1]) ? Width[2] ? IWidth*(Width[1]/100) : Width[1] : IWidth @@ -2141,7 +2163,7 @@ Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:= Colour := "0x" (Colour && Colour[2] ? Colour[2] : "ff000000") Rendering := (Rendering && (Rendering[1] >= 0) && (Rendering[1] <= 5)) ? Rendering[1] : 4 Size := (Size && (Size[1] > 0)) ? Size[2] ? IHeight*(Size[1]/100) : Size[1] : 12 - + hFamily := Gdip_FontFamilyCreate(Font) hFont := Gdip_FontCreate(hFamily, Size, Style) FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000 @@ -2149,30 +2171,30 @@ Gdip_TextToGraphics(pGraphics, Text, Options, Font:="Arial", Width:="", Height:= pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour) if !(hFamily && hFont && hFormat && pBrush && pGraphics) return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0 - + CreateRectF(RC, xpos, ypos, Width, Height) Gdip_SetStringFormatAlign(hFormat, Align) Gdip_SetTextRenderingHint(pGraphics, Rendering) ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) - + if vPos { ReturnRC := StrSplit(ReturnRC, "|") - + if (vPos[0] = "vCentre") || (vPos[0] = "vCenter") ypos += (Height-ReturnRC[4])//2 else if (vPos[0] = "Top") || (vPos[0] = "Up") ypos := 0 else if (vPos[0] = "Bottom") || (vPos[0] = "Down") ypos := Height-ReturnRC[4] - + CreateRectF(RC, xpos, ypos, Width, ReturnRC[4]) ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) } - + if !Measure _E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC) - + if !PassBrush Gdip_DeleteBrush(pBrush) Gdip_DeleteStringFormat(hFormat)