Advertisement
pastamaker

hellbents_gdip with a little bit of my stuff

Jun 6th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Shit that I (Hellbent) added
  2. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  3. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  4. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  5.  
  6. Layered_Window_SetUp(Smoothing,Window_X,Window_Y,Window_W,Window_H,Window_Name:=1,Window_Options:="")
  7.     {
  8.         Layered:={}
  9.         Layered.W:=Window_W
  10.         Layered.H:=Window_H
  11.         Layered.X:=Window_X
  12.         Layered.Y:=Window_Y
  13.         Layered.Name:=Window_Name
  14.         Layered.Options:=Window_Options
  15.         Layered.Token:=Gdip_Startup()
  16.         Create_Layered_GUI(Layered)
  17.         Layered.hwnd:=winExist()
  18.         Layered.hbm := CreateDIBSection(Window_W,Window_H)
  19.         Layered.hdc := CreateCompatibleDC()
  20.         Layered.obm := SelectObject(Layered.hdc,Layered.hbm)
  21.         Layered.G := Gdip_GraphicsFromHDC(Layered.hdc)
  22.         Gdip_SetSmoothingMode(Layered.G,Smoothing)
  23.         return Layered
  24.     }
  25.  
  26. Create_Layered_GUI(Layered)
  27.     {
  28.         Gui,% Layered.Name ": +E0x80000 +LastFound " Layered.Options
  29.         Gui,% Layered.Name ":Show",% "x" Layered.X " y" Layered.Y " w" Layered.W " h" Layered.H " NA"
  30.     }
  31.    
  32. Layered_Window_ShutDown(This)
  33.     {
  34.         SelectObject(This.hdc,This.obm)
  35.         DeleteObject(This.hbm)
  36.         DeleteDC(This.hdc)
  37.         gdip_deleteGraphics(This.g)
  38.         Gdip_Shutdown(This.Token)
  39.     }
  40.  
  41. Gdip_RotateBitmap(pBitmap, Angle, Dispose=1) { ; returns rotated bitmap. By Learning one.
  42. Gdip_GetImageDimensions(pBitmap, Width, Height)
  43. Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
  44. Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
  45.  
  46. pBitmap2 := Gdip_CreateBitmap(RWidth, RHeight)
  47. G2 := Gdip_GraphicsFromImage(pBitmap2), Gdip_SetSmoothingMode(G2, 4), Gdip_SetInterpolationMode(G2, 7)
  48. Gdip_TranslateWorldTransform(G2, xTranslation, yTranslation)
  49. Gdip_RotateWorldTransform(G2, Angle)
  50. Gdip_DrawImage(G2, pBitmap, 0, 0, Width, Height)
  51.  
  52. Gdip_ResetWorldTransform(G2)
  53. Gdip_DeleteGraphics(G2)
  54. if Dispose
  55. Gdip_DisposeImage(pBitmap)
  56. return pBitmap2
  57. }
  58.  
  59. New_Brush(colour:="000000",Alpha:="FF")
  60.     {
  61.         static Hellbent_Brush:=[]
  62.         new_colour := "0x" Alpha colour
  63.         Hellbent_Brush[Hellbent_Brush.Length()+1]:=Gdip_BrushCreateSolid(new_colour)
  64.         return Hellbent_Brush[Hellbent_Brush.Length()]
  65.     }
  66.    
  67.    
  68. New_Pen(colour:="000000",Alpha:="FF",Width:= 5)
  69.     {
  70.         static Hellbent_Pen:=[]
  71.         new_colour := "0x" Alpha colour
  72.         Hellbent_Pen[Hellbent_Pen.Length()+1]:=Gdip_CreatePen(New_Colour,Width)
  73.         return Hellbent_Pen[Hellbent_Pen.Length()]
  74.     }  
  75.    
  76. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  77.     {
  78.         ;~ Gdip_FillRectangle(G, Brush, x, y, w, h)
  79.         Ptr := A_PtrSize ? "UPtr" : "UInt"
  80.    
  81.         return DllCall("gdiplus\GdipFillRectangle"
  82.                     , Ptr, pGraphics
  83.                     , Ptr, pBrush
  84.                     , "float", x
  85.                     , "float", y
  86.                     , "float", w
  87.                     , "float", h)
  88.     }
  89. Fill_Boxx(pGraphics,colour,x,y,w,h){
  90.     pBrush:=new_brush(colour)
  91. Fill_Box(pGraphics,pBrush,x,y,w,h) 
  92. }
  93. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  94. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  95. ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  96.  
  97. turn_bitmap(byref xbitmap,xturn){
  98. xWidth := Gdip_GetImageWidth(xbitmap)
  99. xHeight := Gdip_GetImageHeight(xbitmap)
  100.  
  101.  
  102. Gdip_GetRotatedDimensions(xWidth, xHeight, xturn, xRWidth, xRHeight)
  103. ;~ MsgBox,% "Rwidth: " RWidth "`nrheight: " rheight
  104.  
  105. ; xTranslation and yTranslation now contain the distance to shift the image by
  106. Gdip_GetRotatedTranslation(xWidth, xHeight, xturn, xxTranslation, xyTranslation)
  107. ;~ MsgBox,% "xTranslation: " xTranslation "`nyTranslation: " yTranslation
  108. xpBitmap := Gdip_CreateBitmap(xRWidth, xRHeight)                       ; Create a new bitmap
  109. xg := Gdip_GraphicsFromImage(xpBitmap)                                ; Get a pointer to the graphics of the bitmap
  110. Gdip_SetSmoothingMode(xg, 4)
  111.  
  112. Gdip_SetInterpolationMode(xg, 7)
  113. Gdip_TranslateWorldTransform(xg, xxTranslation, xyTranslation)
  114. Gdip_RotateWorldTransform(xg, xturn)
  115.  
  116.  
  117. Gdip_DrawImage(xg, xbitmap, 0,0, xWidth, xHeight)  
  118. Gdip_ResetWorldTransform(xg)
  119.  
  120. xbitmap:=xpbitmap
  121. }
  122.  
  123. turn_in_graphics(byref xg,xx,xy,xturn,xbitmap){
  124.    
  125.     turn_bitmap(xbitmap,xturn)
  126.     xWidth := Gdip_GetImageWidth(xbitmap)
  127. xHeight := Gdip_GetImageHeight(xbitmap)
  128.     Gdip_DrawImage(xG, xBitmap, xx-xWidth/2, xy-xheight/2, xWidth, xHeight)
  129.    
  130. }
  131.  
  132.  
  133. sinG(x){
  134. return sin(x*3.14159265359/180)
  135. }
  136. cosG(x){
  137. return cos(x*3.14159265359/180)
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
  151. ; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
  152. ; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
  153. ;
  154. ; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
  155. ; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
  156. ;
  157. ;#####################################################################################
  158. ;#####################################################################################
  159. ; STATUS ENUMERATION
  160. ; Return values for functions specified to have status enumerated return type
  161. ;#####################################################################################
  162. ;
  163. ; Ok =                      = 0
  164. ; GenericError              = 1
  165. ; InvalidParameter          = 2
  166. ; OutOfMemory               = 3
  167. ; ObjectBusy                = 4
  168. ; InsufficientBuffer        = 5
  169. ; NotImplemented            = 6
  170. ; Win32Error                = 7
  171. ; WrongState                = 8
  172. ; Aborted                   = 9
  173. ; FileNotFound              = 10
  174. ; ValueOverflow             = 11
  175. ; AccessDenied              = 12
  176. ; UnknownImageFormat        = 13
  177. ; FontFamilyNotFound        = 14
  178. ; FontStyleNotFound         = 15
  179. ; NotTrueTypeFont           = 16
  180. ; UnsupportedGdiplusVersion = 17
  181. ; GdiplusNotInitialized     = 18
  182. ; PropertyNotFound          = 19
  183. ; PropertyNotSupported      = 20
  184. ; ProfileNotFound           = 21
  185. ;
  186. ;#####################################################################################
  187. ;#####################################################################################
  188. ; FUNCTIONS
  189. ;#####################################################################################
  190. ;
  191. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  192. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  193. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  194. ; SetImage(hwnd, hBitmap)
  195. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  196. ; CreateRectF(ByRef RectF, x, y, w, h)
  197. ; CreateSizeF(ByRef SizeF, w, h)
  198. ; CreateDIBSection
  199. ;
  200. ;#####################################################################################
  201.  
  202. ; Function:                 UpdateLayeredWindow
  203. ; Description:              Updates a layered window with the handle to the DC of a gdi bitmap
  204. ;
  205. ; hwnd                      Handle of the layered window to update
  206. ; hdc                       Handle to the DC of the GDI bitmap to update the window with
  207. ; Layeredx                  x position to place the window
  208. ; Layeredy                  y position to place the window
  209. ; Layeredw                  Width of the window
  210. ; Layeredh                  Height of the window
  211. ; Alpha                     Default = 255 : The transparency (0-255) to set the window transparency
  212. ;
  213. ; return                    If the function succeeds, the return value is nonzero
  214. ;
  215. ; notes                     If x or y omitted, then layered window will use its current coordinates
  216. ;                           If w or h omitted then current width and height will be used
  217.  
  218. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  219. {
  220.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  221.    
  222.     if ((x != "") && (y != ""))
  223.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  224.  
  225.     if (w = "") ||(h = "")
  226.         WinGetPos,,, w, h, ahk_id %hwnd%
  227.    
  228.     return DllCall("UpdateLayeredWindow"
  229.                     , Ptr, hwnd
  230.                     , Ptr, 0
  231.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  232.                     , "int64*", w|h<<32
  233.                     , Ptr, hdc
  234.                     , "int64*", 0
  235.                     , "uint", 0
  236.                     , "UInt*", Alpha<<16|1<<24
  237.                     , "uint", 2)
  238. }
  239.  
  240. ;#####################################################################################
  241.  
  242. ; Function              BitBlt
  243. ; Description           The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  244. ;                       of pixels from the specified source device context into a destination device context.
  245. ;
  246. ; dDC                   handle to destination DC
  247. ; dx                    x-coord of destination upper-left corner
  248. ; dy                    y-coord of destination upper-left corner
  249. ; dw                    width of the area to copy
  250. ; dh                    height of the area to copy
  251. ; sDC                   handle to source DC
  252. ; sx                    x-coordinate of source upper-left corner
  253. ; sy                    y-coordinate of source upper-left corner
  254. ; Raster                raster operation code
  255. ;
  256. ; return                If the function succeeds, the return value is nonzero
  257. ;
  258. ; notes                 If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  259. ;
  260. ; BLACKNESS             = 0x00000042
  261. ; NOTSRCERASE           = 0x001100A6
  262. ; NOTSRCCOPY            = 0x00330008
  263. ; SRCERASE              = 0x00440328
  264. ; DSTINVERT             = 0x00550009
  265. ; PATINVERT             = 0x005A0049
  266. ; SRCINVERT             = 0x00660046
  267. ; SRCAND                = 0x008800C6
  268. ; MERGEPAINT            = 0x00BB0226
  269. ; MERGECOPY             = 0x00C000CA
  270. ; SRCCOPY               = 0x00CC0020
  271. ; SRCPAINT              = 0x00EE0086
  272. ; PATCOPY               = 0x00F00021
  273. ; PATPAINT              = 0x00FB0A09
  274. ; WHITENESS             = 0x00FF0062
  275. ; CAPTUREBLT            = 0x40000000
  276. ; NOMIRRORBITMAP        = 0x80000000
  277.  
  278. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  279. {
  280.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  281.    
  282.     return DllCall("gdi32\BitBlt"
  283.                     , Ptr, dDC
  284.                     , "int", dx
  285.                     , "int", dy
  286.                     , "int", dw
  287.                     , "int", dh
  288.                     , Ptr, sDC
  289.                     , "int", sx
  290.                     , "int", sy
  291.                     , "uint", Raster ? Raster : 0x00CC0020)
  292. }
  293.  
  294. ;#####################################################################################
  295.  
  296. ; Function              StretchBlt
  297. ; Description           The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  298. ;                       stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  299. ;                       The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  300. ;
  301. ; ddc                   handle to destination DC
  302. ; dx                    x-coord of destination upper-left corner
  303. ; dy                    y-coord of destination upper-left corner
  304. ; dw                    width of destination rectangle
  305. ; dh                    height of destination rectangle
  306. ; sdc                   handle to source DC
  307. ; sx                    x-coordinate of source upper-left corner
  308. ; sy                    y-coordinate of source upper-left corner
  309. ; sw                    width of source rectangle
  310. ; sh                    height of source rectangle
  311. ; Raster                raster operation code
  312. ;
  313. ; return                If the function succeeds, the return value is nonzero
  314. ;
  315. ; notes                 If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt    
  316.  
  317. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  318. {
  319.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  320.    
  321.     return DllCall("gdi32\StretchBlt"
  322.                     , Ptr, ddc
  323.                     , "int", dx
  324.                     , "int", dy
  325.                     , "int", dw
  326.                     , "int", dh
  327.                     , Ptr, sdc
  328.                     , "int", sx
  329.                     , "int", sy
  330.                     , "int", sw
  331.                     , "int", sh
  332.                     , "uint", Raster ? Raster : 0x00CC0020)
  333. }
  334.  
  335. ;#####################################################################################
  336.  
  337. ; Function              SetStretchBltMode
  338. ; Description           The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  339. ;
  340. ; hdc                   handle to the DC
  341. ; iStretchMode          The stretching mode, describing how the target will be stretched
  342. ;
  343. ; return                If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  344. ;
  345. ; STRETCH_ANDSCANS      = 0x01
  346. ; STRETCH_ORSCANS       = 0x02
  347. ; STRETCH_DELETESCANS   = 0x03
  348. ; STRETCH_HALFTONE      = 0x04
  349.  
  350. SetStretchBltMode(hdc, iStretchMode=4)
  351. {
  352.     return DllCall("gdi32\SetStretchBltMode"
  353.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  354.                     , "int", iStretchMode)
  355. }
  356.  
  357. ;#####################################################################################
  358.  
  359. ; Function              SetImage
  360. ; Description           Associates a new image with a static control
  361. ;
  362. ; hwnd                  handle of the control to update
  363. ; hBitmap               a gdi bitmap to associate the static control with
  364. ;
  365. ; return                If the function succeeds, the return value is nonzero
  366.  
  367. SetImage(hwnd, hBitmap)
  368. {
  369.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  370.     E := ErrorLevel
  371.     DeleteObject(E)
  372.     return E
  373. }
  374.  
  375. ;#####################################################################################
  376.  
  377. ; Function              SetSysColorToControl
  378. ; Description           Sets a solid colour to a control
  379. ;
  380. ; hwnd                  handle of the control to update
  381. ; SysColor              A system colour to set to the control
  382. ;
  383. ; return                If the function succeeds, the return value is zero
  384. ;
  385. ; notes                 A control must have the 0xE style set to it so it is recognised as a bitmap
  386. ;                       By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  387. ;
  388. ; COLOR_3DDKSHADOW              = 21
  389. ; COLOR_3DFACE                  = 15
  390. ; COLOR_3DHIGHLIGHT             = 20
  391. ; COLOR_3DHILIGHT               = 20
  392. ; COLOR_3DLIGHT                 = 22
  393. ; COLOR_3DSHADOW                = 16
  394. ; COLOR_ACTIVEBORDER            = 10
  395. ; COLOR_ACTIVECAPTION           = 2
  396. ; COLOR_APPWORKSPACE            = 12
  397. ; COLOR_BACKGROUND              = 1
  398. ; COLOR_BTNFACE                 = 15
  399. ; COLOR_BTNHIGHLIGHT            = 20
  400. ; COLOR_BTNHILIGHT              = 20
  401. ; COLOR_BTNSHADOW               = 16
  402. ; COLOR_BTNTEXT                 = 18
  403. ; COLOR_CAPTIONTEXT             = 9
  404. ; COLOR_DESKTOP                 = 1
  405. ; COLOR_GRADIENTACTIVECAPTION   = 27
  406. ; COLOR_GRADIENTINACTIVECAPTION = 28
  407. ; COLOR_GRAYTEXT                = 17
  408. ; COLOR_HIGHLIGHT               = 13
  409. ; COLOR_HIGHLIGHTTEXT           = 14
  410. ; COLOR_HOTLIGHT                = 26
  411. ; COLOR_INACTIVEBORDER          = 11
  412. ; COLOR_INACTIVECAPTION         = 3
  413. ; COLOR_INACTIVECAPTIONTEXT     = 19
  414. ; COLOR_INFOBK                  = 24
  415. ; COLOR_INFOTEXT                = 23
  416. ; COLOR_MENU                    = 4
  417. ; COLOR_MENUHILIGHT             = 29
  418. ; COLOR_MENUBAR                 = 30
  419. ; COLOR_MENUTEXT                = 7
  420. ; COLOR_SCROLLBAR               = 0
  421. ; COLOR_WINDOW                  = 5
  422. ; COLOR_WINDOWFRAME             = 6
  423. ; COLOR_WINDOWTEXT              = 8
  424.  
  425. SetSysColorToControl(hwnd, SysColor=15)
  426. {
  427.    WinGetPos,,, w, h, ahk_id %hwnd%
  428.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  429.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  430.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  431.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  432.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  433.    SetImage(hwnd, hBitmap)
  434.    Gdip_DeleteBrush(pBrushClear)
  435.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  436.    return 0
  437. }
  438.  
  439. ;#####################################################################################
  440.  
  441. ; Function              Gdip_BitmapFromScreen
  442. ; Description           Gets a gdi+ bitmap from the screen
  443. ;
  444. ; Screen                0 = All screens
  445. ;                       Any numerical value = Just that screen
  446. ;                       x|y|w|h = Take specific coordinates with a width and height
  447. ; Raster                raster operation code
  448. ;
  449. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  450. ;                       -1:     one or more of x,y,w,h not passed properly
  451. ;
  452. ; notes                 If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  453.  
  454. Gdip_BitmapFromScreen(Screen=0, Raster="")
  455. {
  456.     if (Screen = 0)
  457.     {
  458.         Sysget, x, 76
  459.         Sysget, y, 77  
  460.         Sysget, w, 78
  461.         Sysget, h, 79
  462.     }
  463.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  464.     {
  465.         Screen := SubStr(Screen, 6)
  466.         if !WinExist( "ahk_id " Screen)
  467.             return -2
  468.         WinGetPos,,, w, h, ahk_id %Screen%
  469.         x := y := 0
  470.         hhdc := GetDCEx(Screen, 3)
  471.     }
  472.     else if (Screen&1 != "")
  473.     {
  474.         Sysget, M, Monitor, %Screen%
  475.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  476.     }
  477.     else
  478.     {
  479.         StringSplit, S, Screen, |
  480.         x := S1, y := S2, w := S3, h := S4
  481.     }
  482.  
  483.     if (x = "") || (y = "") || (w = "") || (h = "")
  484.         return -1
  485.  
  486.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  487.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  488.     ReleaseDC(hhdc)
  489.    
  490.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  491.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  492.     return pBitmap
  493. }
  494.  
  495. ;#####################################################################################
  496.  
  497. ; Function              Gdip_BitmapFromHWND
  498. ; Description           Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  499. ;
  500. ; hwnd                  handle to the window to get a bitmap from
  501. ;
  502. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  503. ;
  504. ; notes                 Window must not be not minimised in order to get a handle to it's client area
  505.  
  506. Gdip_BitmapFromHWND(hwnd)
  507. {
  508.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  509.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  510.     PrintWindow(hwnd, hdc)
  511.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  512.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  513.     return pBitmap
  514. }
  515.  
  516. ;#####################################################################################
  517.  
  518. ; Function              CreateRectF
  519. ; Description           Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  520. ;
  521. ; RectF                 Name to call the RectF object
  522. ; x                     x-coordinate of the upper left corner of the rectangle
  523. ; y                     y-coordinate of the upper left corner of the rectangle
  524. ; w                     Width of the rectangle
  525. ; h                     Height of the rectangle
  526. ;
  527. ; return                No return value
  528.  
  529. CreateRectF(ByRef RectF, x, y, w, h)
  530. {
  531.    VarSetCapacity(RectF, 16)
  532.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  533. }
  534.  
  535. ;#####################################################################################
  536.  
  537. ; Function              CreateRect
  538. ; Description           Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  539. ;
  540. ; RectF                 Name to call the RectF object
  541. ; x                     x-coordinate of the upper left corner of the rectangle
  542. ; y                     y-coordinate of the upper left corner of the rectangle
  543. ; w                     Width of the rectangle
  544. ; h                     Height of the rectangle
  545. ;
  546. ; return                No return value
  547.  
  548. CreateRect(ByRef Rect, x, y, w, h)
  549. {
  550.     VarSetCapacity(Rect, 16)
  551.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  552. }
  553. ;#####################################################################################
  554.  
  555. ; Function              CreateSizeF
  556. ; Description           Creates a SizeF object, containing an 2 values
  557. ;
  558. ; SizeF                 Name to call the SizeF object
  559. ; w                     w-value for the SizeF object
  560. ; h                     h-value for the SizeF object
  561. ;
  562. ; return                No Return value
  563.  
  564. CreateSizeF(ByRef SizeF, w, h)
  565. {
  566.    VarSetCapacity(SizeF, 8)
  567.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  568. }
  569. ;#####################################################################################
  570.  
  571. ; Function              CreatePointF
  572. ; Description           Creates a SizeF object, containing an 2 values
  573. ;
  574. ; SizeF                 Name to call the SizeF object
  575. ; w                     w-value for the SizeF object
  576. ; h                     h-value for the SizeF object
  577. ;
  578. ; return                No Return value
  579.  
  580. CreatePointF(ByRef PointF, x, y)
  581. {
  582.    VarSetCapacity(PointF, 8)
  583.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  584. }
  585. ;#####################################################################################
  586.  
  587. ; Function              CreateDIBSection
  588. ; Description           The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  589. ;
  590. ; w                     width of the bitmap to create
  591. ; h                     height of the bitmap to create
  592. ; hdc                   a handle to the device context to use the palette from
  593. ; bpp                   bits per pixel (32 = ARGB)
  594. ; ppvBits               A pointer to a variable that receives a pointer to the location of the DIB bit values
  595. ;
  596. ; return                returns a DIB. A gdi bitmap
  597. ;
  598. ; notes                 ppvBits will receive the location of the pixels in the DIB
  599.  
  600. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  601. {
  602.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  603.    
  604.     hdc2 := hdc ? hdc : GetDC()
  605.     VarSetCapacity(bi, 40, 0)
  606.    
  607.     NumPut(w, bi, 4, "uint")
  608.     , NumPut(h, bi, 8, "uint")
  609.     , NumPut(40, bi, 0, "uint")
  610.     , NumPut(1, bi, 12, "ushort")
  611.     , NumPut(0, bi, 16, "uInt")
  612.     , NumPut(bpp, bi, 14, "ushort")
  613.    
  614.     hbm := DllCall("CreateDIBSection"
  615.                     , Ptr, hdc2
  616.                     , Ptr, &bi
  617.                     , "uint", 0
  618.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  619.                     , Ptr, 0
  620.                     , "uint", 0, Ptr)
  621.  
  622.     if !hdc
  623.         ReleaseDC(hdc2)
  624.     return hbm
  625. }
  626.  
  627. ;#####################################################################################
  628.  
  629. ; Function              PrintWindow
  630. ; Description           The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  631. ;
  632. ; hwnd                  A handle to the window that will be copied
  633. ; hdc                   A handle to the device context
  634. ; Flags                 Drawing options
  635. ;
  636. ; return                If the function succeeds, it returns a nonzero value
  637. ;
  638. ; PW_CLIENTONLY         = 1
  639.  
  640. PrintWindow(hwnd, hdc, Flags=0)
  641. {
  642.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  643.    
  644.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  645. }
  646.  
  647. ;#####################################################################################
  648.  
  649. ; Function              DestroyIcon
  650. ; Description           Destroys an icon and frees any memory the icon occupied
  651. ;
  652. ; hIcon                 Handle to the icon to be destroyed. The icon must not be in use
  653. ;
  654. ; return                If the function succeeds, the return value is nonzero
  655.  
  656. DestroyIcon(hIcon)
  657. {
  658.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  659. }
  660.  
  661. ;#####################################################################################
  662.  
  663. PaintDesktop(hdc)
  664. {
  665.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  666. }
  667.  
  668. ;#####################################################################################
  669.  
  670. CreateCompatibleBitmap(hdc, w, h)
  671. {
  672.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  673. }
  674.  
  675. ;#####################################################################################
  676.  
  677. ; Function              CreateCompatibleDC
  678. ; Description           This function creates a memory device context (DC) compatible with the specified device
  679. ;
  680. ; hdc                   Handle to an existing device context                   
  681. ;
  682. ; return                returns the handle to a device context or 0 on failure
  683. ;
  684. ; notes                 If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  685.  
  686. CreateCompatibleDC(hdc=0)
  687. {
  688.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  689. }
  690.  
  691. ;#####################################################################################
  692.  
  693. ; Function              SelectObject
  694. ; Description           The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  695. ;
  696. ; hdc                   Handle to a DC
  697. ; hgdiobj               A handle to the object to be selected into the DC
  698. ;
  699. ; return                If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  700. ;
  701. ; notes                 The specified object must have been created by using one of the following functions
  702. ;                       Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  703. ;                       Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  704. ;                       Font - CreateFont, CreateFontIndirect
  705. ;                       Pen - CreatePen, CreatePenIndirect
  706. ;                       Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  707. ;
  708. ; notes                 If the selected object is a region and the function succeeds, the return value is one of the following value
  709. ;
  710. ; SIMPLEREGION          = 2 Region consists of a single rectangle
  711. ; COMPLEXREGION         = 3 Region consists of more than one rectangle
  712. ; NULLREGION            = 1 Region is empty
  713.  
  714. SelectObject(hdc, hgdiobj)
  715. {
  716.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  717.    
  718.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  719. }
  720.  
  721. ;#####################################################################################
  722.  
  723. ; Function              DeleteObject
  724. ; Description           This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  725. ;                       After the object is deleted, the specified handle is no longer valid
  726. ;
  727. ; hObject               Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  728. ;
  729. ; return                Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  730.  
  731. DeleteObject(hObject)
  732. {
  733.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  734. }
  735.  
  736. ;#####################################################################################
  737.  
  738. ; Function              GetDC
  739. ; Description           This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  740. ;                       The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  741. ;
  742. ; hwnd                  Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen                  
  743. ;
  744. ; return                The handle the device context for the specified window's client area indicates success. NULL indicates failure
  745.  
  746. GetDC(hwnd=0)
  747. {
  748.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  749. }
  750.  
  751. ;#####################################################################################
  752.  
  753. ; DCX_CACHE = 0x2
  754. ; DCX_CLIPCHILDREN = 0x8
  755. ; DCX_CLIPSIBLINGS = 0x10
  756. ; DCX_EXCLUDERGN = 0x40
  757. ; DCX_EXCLUDEUPDATE = 0x100
  758. ; DCX_INTERSECTRGN = 0x80
  759. ; DCX_INTERSECTUPDATE = 0x200
  760. ; DCX_LOCKWINDOWUPDATE = 0x400
  761. ; DCX_NORECOMPUTE = 0x100000
  762. ; DCX_NORESETATTRS = 0x4
  763. ; DCX_PARENTCLIP = 0x20
  764. ; DCX_VALIDATE = 0x200000
  765. ; DCX_WINDOW = 0x1
  766.  
  767. GetDCEx(hwnd, flags=0, hrgnClip=0)
  768. {
  769.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  770.    
  771.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  772. }
  773.  
  774. ;#####################################################################################
  775.  
  776. ; Function              ReleaseDC
  777. ; Description           This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context
  778. ;
  779. ; hdc                   Handle to the device context to be released
  780. ; hwnd                  Handle to the window whose device context is to be released
  781. ;
  782. ; return                1 = released
  783. ;                       0 = not released
  784. ;
  785. ; notes                 The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context
  786. ;                       An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function.
  787.  
  788. ReleaseDC(hdc, hwnd=0)
  789. {
  790.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  791.    
  792.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  793. }
  794.  
  795. ;#####################################################################################
  796.  
  797. ; Function              DeleteDC
  798. ; Description           The DeleteDC function deletes the specified device context (DC)
  799. ;
  800. ; hdc                   A handle to the device context
  801. ;
  802. ; return                If the function succeeds, the return value is nonzero
  803. ;
  804. ; notes                 An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC
  805.  
  806. DeleteDC(hdc)
  807. {
  808.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  809. }
  810. ;#####################################################################################
  811.  
  812. ; Function              Gdip_LibraryVersion
  813. ; Description           Get the current library version
  814. ;
  815. ; return                the library version
  816. ;
  817. ; notes                 This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  818.  
  819. Gdip_LibraryVersion()
  820. {
  821.     return 1.45
  822. }
  823.  
  824. ;#####################################################################################
  825.  
  826. ; Function              Gdip_LibrarySubVersion
  827. ; Description           Get the current library sub version
  828. ;
  829. ; return                the library sub version
  830. ;
  831. ; notes                 This is the sub-version currently maintained by Rseding91
  832. Gdip_LibrarySubVersion()
  833. {
  834.     return 1.47
  835. }
  836.  
  837. ;#####################################################################################
  838.  
  839. ; Function:             Gdip_BitmapFromBRA
  840. ; Description:          Gets a pointer to a gdi+ bitmap from a BRA file
  841. ;
  842. ; BRAFromMemIn          The variable for a BRA file read to memory
  843. ; File                  The name of the file, or its number that you would like (This depends on alternate parameter)
  844. ; Alternate             Changes whether the File parameter is the file name or its number
  845. ;
  846. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  847. ;                       -1 = The BRA variable is empty
  848. ;                       -2 = The BRA has an incorrect header
  849. ;                       -3 = The BRA has information missing
  850. ;                       -4 = Could not find file inside the BRA
  851.  
  852. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  853. {
  854.     Static FName = "ObjRelease"
  855.    
  856.     if !BRAFromMemIn
  857.         return -1
  858.     Loop, Parse, BRAFromMemIn, `n
  859.     {
  860.         if (A_Index = 1)
  861.         {
  862.             StringSplit, Header, A_LoopField, |
  863.             if (Header0 != 4 || Header2 != "BRA!")
  864.                 return -2
  865.         }
  866.         else if (A_Index = 2)
  867.         {
  868.             StringSplit, Info, A_LoopField, |
  869.             if (Info0 != 3)
  870.                 return -3
  871.         }
  872.         else
  873.             break
  874.     }
  875.     if !Alternate
  876.         StringReplace, File, File, \, \\, All
  877.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  878.     if !FileInfo
  879.         return -4
  880.    
  881.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  882.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  883.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  884.     DllCall("GlobalUnlock", Ptr, hData)
  885.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  886.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  887.     If (A_PtrSize)
  888.         %FName%(pStream)
  889.     Else
  890.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  891.     return pBitmap
  892. }
  893.  
  894. ;#####################################################################################
  895.  
  896. ; Function              Gdip_DrawRectangle
  897. ; Description           This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  898. ;
  899. ; pGraphics             Pointer to the Graphics of a bitmap
  900. ; pPen                  Pointer to a pen
  901. ; x                     x-coordinate of the top left of the rectangle
  902. ; y                     y-coordinate of the top left of the rectangle
  903. ; w                     width of the rectanlge
  904. ; h                     height of the rectangle
  905. ;
  906. ; return                status enumeration. 0 = success
  907. ;
  908. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  909.  
  910. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  911. {
  912.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  913.    
  914.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  915. }
  916.  
  917. ;#####################################################################################
  918.  
  919. ; Function              Gdip_DrawRoundedRectangle
  920. ; Description           This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  921. ;
  922. ; pGraphics             Pointer to the Graphics of a bitmap
  923. ; pPen                  Pointer to a pen
  924. ; x                     x-coordinate of the top left of the rounded rectangle
  925. ; y                     y-coordinate of the top left of the rounded rectangle
  926. ; w                     width of the rectanlge
  927. ; h                     height of the rectangle
  928. ; r                     radius of the rounded corners
  929. ;
  930. ; return                status enumeration. 0 = success
  931. ;
  932. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  933.  
  934. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  935. {
  936.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  937.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  938.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  939.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  940.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  941.     Gdip_ResetClip(pGraphics)
  942.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  943.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  944.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  945.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  946.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  947.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  948.     Gdip_ResetClip(pGraphics)
  949.     return E
  950. }
  951.  
  952. ;#####################################################################################
  953.  
  954. ; Function              Gdip_DrawEllipse
  955. ; Description           This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  956. ;
  957. ; pGraphics             Pointer to the Graphics of a bitmap
  958. ; pPen                  Pointer to a pen
  959. ; x                     x-coordinate of the top left of the rectangle the ellipse will be drawn into
  960. ; y                     y-coordinate of the top left of the rectangle the ellipse will be drawn into
  961. ; w                     width of the ellipse
  962. ; h                     height of the ellipse
  963. ;
  964. ; return                status enumeration. 0 = success
  965. ;
  966. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  967.  
  968. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  969. {
  970.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  971.    
  972.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  973. }
  974.  
  975. ;#####################################################################################
  976.  
  977. ; Function              Gdip_DrawBezier
  978. ; Description           This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  979. ;
  980. ; pGraphics             Pointer to the Graphics of a bitmap
  981. ; pPen                  Pointer to a pen
  982. ; x1                    x-coordinate of the start of the bezier
  983. ; y1                    y-coordinate of the start of the bezier
  984. ; x2                    x-coordinate of the first arc of the bezier
  985. ; y2                    y-coordinate of the first arc of the bezier
  986. ; x3                    x-coordinate of the second arc of the bezier
  987. ; y3                    y-coordinate of the second arc of the bezier
  988. ; x4                    x-coordinate of the end of the bezier
  989. ; y4                    y-coordinate of the end of the bezier
  990. ;
  991. ; return                status enumeration. 0 = success
  992. ;
  993. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  994.  
  995. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  996. {
  997.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  998.    
  999.     return DllCall("gdiplus\GdipDrawBezier"
  1000.                     , Ptr, pgraphics
  1001.                     , Ptr, pPen
  1002.                     , "float", x1
  1003.                     , "float", y1
  1004.                     , "float", x2
  1005.                     , "float", y2
  1006.                     , "float", x3
  1007.                     , "float", y3
  1008.                     , "float", x4
  1009.                     , "float", y4)
  1010. }
  1011.  
  1012. ;#####################################################################################
  1013.  
  1014. ; Function              Gdip_DrawArc
  1015. ; Description           This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1016. ;
  1017. ; pGraphics             Pointer to the Graphics of a bitmap
  1018. ; pPen                  Pointer to a pen
  1019. ; x                     x-coordinate of the start of the arc
  1020. ; y                     y-coordinate of the start of the arc
  1021. ; w                     width of the arc
  1022. ; h                     height of the arc
  1023. ; StartAngle            specifies the angle between the x-axis and the starting point of the arc
  1024. ; SweepAngle            specifies the angle between the starting and ending points of the arc
  1025. ;
  1026. ; return                status enumeration. 0 = success
  1027. ;
  1028. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1029.  
  1030. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1031. {
  1032.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1033.    
  1034.     return DllCall("gdiplus\GdipDrawArc"
  1035.                     , Ptr, pGraphics
  1036.                     , Ptr, pPen
  1037.                     , "float", x
  1038.                     , "float", y
  1039.                     , "float", w
  1040.                     , "float", h
  1041.                     , "float", StartAngle
  1042.                     , "float", SweepAngle)
  1043. }
  1044.  
  1045. ;#####################################################################################
  1046.  
  1047. ; Function              Gdip_DrawPie
  1048. ; Description           This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1049. ;
  1050. ; pGraphics             Pointer to the Graphics of a bitmap
  1051. ; pPen                  Pointer to a pen
  1052. ; x                     x-coordinate of the start of the pie
  1053. ; y                     y-coordinate of the start of the pie
  1054. ; w                     width of the pie
  1055. ; h                     height of the pie
  1056. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1057. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1058. ;
  1059. ; return                status enumeration. 0 = success
  1060. ;
  1061. ; notes                 as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  1062.  
  1063. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1064. {
  1065.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1066.    
  1067.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1068. }
  1069.  
  1070. ;#####################################################################################
  1071.  
  1072. ; Function              Gdip_DrawLine
  1073. ; Description           This function uses a pen to draw a line into the Graphics of a bitmap
  1074. ;
  1075. ; pGraphics             Pointer to the Graphics of a bitmap
  1076. ; pPen                  Pointer to a pen
  1077. ; x1                    x-coordinate of the start of the line
  1078. ; y1                    y-coordinate of the start of the line
  1079. ; x2                    x-coordinate of the end of the line
  1080. ; y2                    y-coordinate of the end of the line
  1081. ;
  1082. ; return                status enumeration. 0 = success    
  1083.  
  1084. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1085. {
  1086.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1087.    
  1088.     return DllCall("gdiplus\GdipDrawLine"
  1089.                     , Ptr, pGraphics
  1090.                     , Ptr, pPen
  1091.                     , "float", x1
  1092.                     , "float", y1
  1093.                     , "float", x2
  1094.                     , "float", y2)
  1095. }
  1096.  
  1097. ;#####################################################################################
  1098.  
  1099. ; Function              Gdip_DrawLines
  1100. ; Description           This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1101. ;
  1102. ; pGraphics             Pointer to the Graphics of a bitmap
  1103. ; pPen                  Pointer to a pen
  1104. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1105. ;
  1106. ; return                status enumeration. 0 = success            
  1107.  
  1108. Gdip_DrawLines(pGraphics, pPen, Points)
  1109. {
  1110.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1111.     StringSplit, Points, Points, |
  1112.     VarSetCapacity(PointF, 8*Points0)  
  1113.     Loop, %Points0%
  1114.     {
  1115.         StringSplit, Coord, Points%A_Index%, `,
  1116.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1117.     }
  1118.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  1119. }
  1120.  
  1121. ;#####################################################################################
  1122.  
  1123. ; Function              Gdip_FillRectangle
  1124. ; Description           This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1125. ;
  1126. ; pGraphics             Pointer to the Graphics of a bitmap
  1127. ; pBrush                Pointer to a brush
  1128. ; x                     x-coordinate of the top left of the rectangle
  1129. ; y                     y-coordinate of the top left of the rectangle
  1130. ; w                     width of the rectanlge
  1131. ; h                     height of the rectangle
  1132. ;
  1133. ; return                status enumeration. 0 = success
  1134.  
  1135. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1136. {
  1137.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1138.    
  1139.     return DllCall("gdiplus\GdipFillRectangle"
  1140.                     , Ptr, pGraphics
  1141.                     , Ptr, pBrush
  1142.                     , "float", x
  1143.                     , "float", y
  1144.                     , "float", w
  1145.                     , "float", h)
  1146. }
  1147.  
  1148. ;#####################################################################################
  1149.  
  1150. ; Function              Gdip_FillRoundedRectangle
  1151. ; Description           This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1152. ;
  1153. ; pGraphics             Pointer to the Graphics of a bitmap
  1154. ; pBrush                Pointer to a brush
  1155. ; x                     x-coordinate of the top left of the rounded rectangle
  1156. ; y                     y-coordinate of the top left of the rounded rectangle
  1157. ; w                     width of the rectanlge
  1158. ; h                     height of the rectangle
  1159. ; r                     radius of the rounded corners
  1160. ;
  1161. ; return                status enumeration. 0 = success
  1162.  
  1163. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1164. {
  1165.     Region := Gdip_GetClipRegion(pGraphics)
  1166.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1167.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1168.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1169.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1170.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1171.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1172.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1173.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1174.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1175.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1176.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1177.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1178.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1179.     Gdip_DeleteRegion(Region)
  1180.     return E
  1181. }
  1182.  
  1183. ;#####################################################################################
  1184.  
  1185. ; Function              Gdip_FillPolygon
  1186. ; Description           This function uses a brush to fill a polygon in the Graphics of a bitmap
  1187. ;
  1188. ; pGraphics             Pointer to the Graphics of a bitmap
  1189. ; pBrush                Pointer to a brush
  1190. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1191. ;
  1192. ; return                status enumeration. 0 = success
  1193. ;
  1194. ; notes                 Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1195. ; Alternate             = 0
  1196. ; Winding               = 1
  1197.  
  1198. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1199. {
  1200.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1201.    
  1202.     StringSplit, Points, Points, |
  1203.     VarSetCapacity(PointF, 8*Points0)  
  1204.     Loop, %Points0%
  1205.     {
  1206.         StringSplit, Coord, Points%A_Index%, `,
  1207.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1208.     }  
  1209.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  1210. }
  1211.  
  1212. ;#####################################################################################
  1213.  
  1214. ; Function              Gdip_FillPie
  1215. ; Description           This function uses a brush to fill a pie in the Graphics of a bitmap
  1216. ;
  1217. ; pGraphics             Pointer to the Graphics of a bitmap
  1218. ; pBrush                Pointer to a brush
  1219. ; x                     x-coordinate of the top left of the pie
  1220. ; y                     y-coordinate of the top left of the pie
  1221. ; w                     width of the pie
  1222. ; h                     height of the pie
  1223. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1224. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1225. ;
  1226. ; return                status enumeration. 0 = success
  1227.  
  1228. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1229. {
  1230.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1231.    
  1232.     return DllCall("gdiplus\GdipFillPie"
  1233.                     , Ptr, pGraphics
  1234.                     , Ptr, pBrush
  1235.                     , "float", x
  1236.                     , "float", y
  1237.                     , "float", w
  1238.                     , "float", h
  1239.                     , "float", StartAngle
  1240.                     , "float", SweepAngle)
  1241. }
  1242.  
  1243. ;#####################################################################################
  1244.  
  1245. ; Function              Gdip_FillEllipse
  1246. ; Description           This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1247. ;
  1248. ; pGraphics             Pointer to the Graphics of a bitmap
  1249. ; pBrush                Pointer to a brush
  1250. ; x                     x-coordinate of the top left of the ellipse
  1251. ; y                     y-coordinate of the top left of the ellipse
  1252. ; w                     width of the ellipse
  1253. ; h                     height of the ellipse
  1254. ;
  1255. ; return                status enumeration. 0 = success
  1256.  
  1257. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1258. {
  1259.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1260.    
  1261.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  1262. }
  1263.  
  1264. ;#####################################################################################
  1265.  
  1266. ; Function              Gdip_FillRegion
  1267. ; Description           This function uses a brush to fill a region in the Graphics of a bitmap
  1268. ;
  1269. ; pGraphics             Pointer to the Graphics of a bitmap
  1270. ; pBrush                Pointer to a brush
  1271. ; Region                Pointer to a Region
  1272. ;
  1273. ; return                status enumeration. 0 = success
  1274. ;
  1275. ; notes                 You can create a region Gdip_CreateRegion() and then add to this
  1276.  
  1277. Gdip_FillRegion(pGraphics, pBrush, Region)
  1278. {
  1279.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1280.    
  1281.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  1282. }
  1283.  
  1284. ;#####################################################################################
  1285.  
  1286. ; Function              Gdip_FillPath
  1287. ; Description           This function uses a brush to fill a path in the Graphics of a bitmap
  1288. ;
  1289. ; pGraphics             Pointer to the Graphics of a bitmap
  1290. ; pBrush                Pointer to a brush
  1291. ; Region                Pointer to a Path
  1292. ;
  1293. ; return                status enumeration. 0 = success
  1294.  
  1295. Gdip_FillPath(pGraphics, pBrush, Path)
  1296. {
  1297.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1298.    
  1299.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  1300. }
  1301.  
  1302. ;#####################################################################################
  1303.  
  1304. ; Function              Gdip_DrawImagePointsRect
  1305. ; Description           This function draws a bitmap into the Graphics of another bitmap and skews it
  1306. ;
  1307. ; pGraphics             Pointer to the Graphics of a bitmap
  1308. ; pBitmap               Pointer to a bitmap to be drawn
  1309. ; Points                Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1310. ; sx                    x-coordinate of source upper-left corner
  1311. ; sy                    y-coordinate of source upper-left corner
  1312. ; sw                    width of source rectangle
  1313. ; sh                    height of source rectangle
  1314. ; Matrix                a matrix used to alter image attributes when drawing
  1315. ;
  1316. ; return                status enumeration. 0 = success
  1317. ;
  1318. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1319. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1320. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1321. ;                       Matrix can be passed as a matrix with any delimiter
  1322.  
  1323. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1324. {
  1325.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1326.    
  1327.     StringSplit, Points, Points, |
  1328.     VarSetCapacity(PointF, 8*Points0)  
  1329.     Loop, %Points0%
  1330.     {
  1331.         StringSplit, Coord, Points%A_Index%, `,
  1332.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1333.     }
  1334.  
  1335.     if (Matrix&1 = "")
  1336.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1337.     else if (Matrix != 1)
  1338.         ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1339.        
  1340.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1341.     {
  1342.         sx := 0, sy := 0
  1343.         sw := Gdip_GetImageWidth(pBitmap)
  1344.         sh := Gdip_GetImageHeight(pBitmap)
  1345.     }
  1346.  
  1347.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1348.                 , Ptr, pGraphics
  1349.                 , Ptr, pBitmap
  1350.                 , Ptr, &PointF
  1351.                 , "int", Points0
  1352.                 , "float", sx
  1353.                 , "float", sy
  1354.                 , "float", sw
  1355.                 , "float", sh
  1356.                 , "int", 2
  1357.                 , Ptr, ImageAttr
  1358.                 , Ptr, 0
  1359.                 , Ptr, 0)
  1360.     if ImageAttr
  1361.         Gdip_DisposeImageAttributes(ImageAttr)
  1362.     return E
  1363. }
  1364.  
  1365. ;#####################################################################################
  1366.  
  1367. ; Function              Gdip_DrawImage
  1368. ; Description           This function draws a bitmap into the Graphics of another bitmap
  1369. ;
  1370. ; pGraphics             Pointer to the Graphics of a bitmap
  1371. ; pBitmap               Pointer to a bitmap to be drawn
  1372. ; dx                    x-coord of destination upper-left corner
  1373. ; dy                    y-coord of destination upper-left corner
  1374. ; dw                    width of destination image
  1375. ; dh                    height of destination image
  1376. ; sx                    x-coordinate of source upper-left corner
  1377. ; sy                    y-coordinate of source upper-left corner
  1378. ; sw                    width of source image
  1379. ; sh                    height of source image
  1380. ; Matrix                a matrix used to alter image attributes when drawing
  1381. ;
  1382. ; return                status enumeration. 0 = success
  1383. ;
  1384. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1385. ;                       Gdip_DrawImage performs faster
  1386. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1387. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1388. ;                       Matrix can be passed as a matrix with any delimiter. For example:
  1389. ;                       MatrixBright=
  1390. ;                       (
  1391. ;                       1.5     |0      |0      |0      |0
  1392. ;                       0       |1.5    |0      |0      |0
  1393. ;                       0       |0      |1.5    |0      |0
  1394. ;                       0       |0      |0      |1      |0
  1395. ;                       0.05    |0.05   |0.05   |0      |1
  1396. ;                       )
  1397. ;
  1398. ; notes                 MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1399. ;                       MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1400. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1401.  
  1402. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1403. {
  1404.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1405.    
  1406.     if (Matrix&1 = "")
  1407.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1408.     else if (Matrix != 1)
  1409.         ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
  1410.  
  1411.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1412.     {
  1413.         if (dx = "" && dy = "" && dw = "" && dh = "")
  1414.         {
  1415.             sx := dx := 0, sy := dy := 0
  1416.             sw := dw := Gdip_GetImageWidth(pBitmap)
  1417.             sh := dh := Gdip_GetImageHeight(pBitmap)
  1418.         }
  1419.         else
  1420.         {
  1421.             sx := sy := 0
  1422.             sw := Gdip_GetImageWidth(pBitmap)
  1423.             sh := Gdip_GetImageHeight(pBitmap)
  1424.         }
  1425.     }
  1426.  
  1427.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  1428.                 , Ptr, pGraphics
  1429.                 , Ptr, pBitmap
  1430.                 , "float", dx
  1431.                 , "float", dy
  1432.                 , "float", dw
  1433.                 , "float", dh
  1434.                 , "float", sx
  1435.                 , "float", sy
  1436.                 , "float", sw
  1437.                 , "float", sh
  1438.                 , "int", 2
  1439.                 , Ptr, ImageAttr
  1440.                 , Ptr, 0
  1441.                 , Ptr, 0)
  1442.     if ImageAttr
  1443.         Gdip_DisposeImageAttributes(ImageAttr)
  1444.     return E
  1445. }
  1446.  
  1447. ;#####################################################################################
  1448.  
  1449. ; Function              Gdip_SetImageAttributesColorMatrix
  1450. ; Description           This function creates an image matrix ready for drawing
  1451. ;
  1452. ; Matrix                a matrix used to alter image attributes when drawing
  1453. ;                       passed with any delimeter
  1454. ;
  1455. ; return                returns an image matrix on sucess or 0 if it fails
  1456. ;
  1457. ; notes                 MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
  1458. ;                       MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
  1459. ;                       MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
  1460.  
  1461. Gdip_SetImageAttributesColorMatrix(Matrix)
  1462. {
  1463.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1464.    
  1465.     VarSetCapacity(ColourMatrix, 100, 0)
  1466.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1467.     StringSplit, Matrix, Matrix, |
  1468.     Loop, 25
  1469.     {
  1470.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1471.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1472.     }
  1473.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  1474.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  1475.     return ImageAttr
  1476. }
  1477.  
  1478. ;#####################################################################################
  1479.  
  1480. ; Function              Gdip_GraphicsFromImage
  1481. ; Description           This function gets the graphics for a bitmap used for drawing functions
  1482. ;
  1483. ; pBitmap               Pointer to a bitmap to get the pointer to its graphics
  1484. ;
  1485. ; return                returns a pointer to the graphics of a bitmap
  1486. ;
  1487. ; notes                 a bitmap can be drawn into the graphics of another bitmap
  1488.  
  1489. Gdip_GraphicsFromImage(pBitmap)
  1490. {
  1491.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1492.     return pGraphics
  1493. }
  1494.  
  1495. ;#####################################################################################
  1496.  
  1497. ; Function              Gdip_GraphicsFromHDC
  1498. ; Description           This function gets the graphics from the handle to a device context
  1499. ;
  1500. ; hdc                   This is the handle to the device context
  1501. ;
  1502. ; return                returns a pointer to the graphics of a bitmap
  1503. ;
  1504. ; notes                 You can draw a bitmap into the graphics of another bitmap
  1505.  
  1506. Gdip_GraphicsFromHDC(hdc)
  1507. {
  1508.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1509.     return pGraphics
  1510. }
  1511.  
  1512. ;#####################################################################################
  1513.  
  1514. ; Function              Gdip_GetDC
  1515. ; Description           This function gets the device context of the passed Graphics
  1516. ;
  1517. ; hdc                   This is the handle to the device context
  1518. ;
  1519. ; return                returns the device context for the graphics of a bitmap
  1520.  
  1521. Gdip_GetDC(pGraphics)
  1522. {
  1523.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  1524.     return hdc
  1525. }
  1526.  
  1527. ;#####################################################################################
  1528.  
  1529. ; Function              Gdip_ReleaseDC
  1530. ; Description           This function releases a device context from use for further use
  1531. ;
  1532. ; pGraphics             Pointer to the graphics of a bitmap
  1533. ; hdc                   This is the handle to the device context
  1534. ;
  1535. ; return                status enumeration. 0 = success
  1536.  
  1537. Gdip_ReleaseDC(pGraphics, hdc)
  1538. {
  1539.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1540.    
  1541.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  1542. }
  1543.  
  1544. ;#####################################################################################
  1545.  
  1546. ; Function              Gdip_GraphicsClear
  1547. ; Description           Clears the graphics of a bitmap ready for further drawing
  1548. ;
  1549. ; pGraphics             Pointer to the graphics of a bitmap
  1550. ; ARGB                  The colour to clear the graphics to
  1551. ;
  1552. ; return                status enumeration. 0 = success
  1553. ;
  1554. ; notes                 By default this will make the background invisible
  1555. ;                       Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1556.  
  1557. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1558. {
  1559.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  1560. }
  1561.  
  1562. ;#####################################################################################
  1563.  
  1564. ; Function              Gdip_BlurBitmap
  1565. ; Description           Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1566. ;
  1567. ; pBitmap               Pointer to a bitmap to be blurred
  1568. ; Blur                  The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1569. ;
  1570. ; return                If the function succeeds, the return value is a pointer to the new blurred bitmap
  1571. ;                       -1 = The blur parameter is outside the range 1-100
  1572. ;
  1573. ; notes                 This function will not dispose of the original bitmap
  1574.  
  1575. Gdip_BlurBitmap(pBitmap, Blur)
  1576. {
  1577.     if (Blur > 100) || (Blur < 1)
  1578.         return -1  
  1579.    
  1580.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1581.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1582.  
  1583.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1584.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  1585.     Gdip_SetInterpolationMode(G1, 7)
  1586.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1587.  
  1588.     Gdip_DeleteGraphics(G1)
  1589.  
  1590.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1591.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  1592.     Gdip_SetInterpolationMode(G2, 7)
  1593.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1594.  
  1595.     Gdip_DeleteGraphics(G2)
  1596.     Gdip_DisposeImage(pBitmap1)
  1597.     return pBitmap2
  1598. }
  1599.  
  1600. ;#####################################################################################
  1601.  
  1602. ; Function:             Gdip_SaveBitmapToFile
  1603. ; Description:          Saves a bitmap to a file in any supported format onto disk
  1604. ;  
  1605. ; pBitmap               Pointer to a bitmap
  1606. ; sOutput               The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
  1607. ; Quality               If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1608. ;
  1609. ; return                If the function succeeds, the return value is zero, otherwise:
  1610. ;                       -1 = Extension supplied is not a supported file format
  1611. ;                       -2 = Could not get a list of encoders on system
  1612. ;                       -3 = Could not find matching encoder for specified file format
  1613. ;                       -4 = Could not get WideChar name of output file
  1614. ;                       -5 = Could not save file to disk
  1615. ;
  1616. ; notes                 This function will use the extension supplied from the sOutput parameter to determine the output format
  1617.  
  1618. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1619. {
  1620.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1621.    
  1622.     SplitPath, sOutput,,, Extension
  1623.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1624.         return -1
  1625.     Extension := "." Extension
  1626.  
  1627.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1628.     VarSetCapacity(ci, nSize)
  1629.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  1630.     if !(nCount && nSize)
  1631.         return -2
  1632.    
  1633.     If (A_IsUnicode){
  1634.         StrGet_Name := "StrGet"
  1635.         Loop, %nCount%
  1636.         {
  1637.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  1638.             if !InStr(sString, "*" Extension)
  1639.                 continue
  1640.            
  1641.             pCodec := &ci+idx
  1642.             break
  1643.         }
  1644.     } else {
  1645.         Loop, %nCount%
  1646.         {
  1647.             Location := NumGet(ci, 76*(A_Index-1)+44)
  1648.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1649.             VarSetCapacity(sString, nSize)
  1650.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1651.             if !InStr(sString, "*" Extension)
  1652.                 continue
  1653.            
  1654.             pCodec := &ci+76*(A_Index-1)
  1655.             break
  1656.         }
  1657.     }
  1658.    
  1659.     if !pCodec
  1660.         return -3
  1661.  
  1662.     if (Quality != 75)
  1663.     {
  1664.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1665.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  1666.         {
  1667.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  1668.             VarSetCapacity(EncoderParameters, nSize, 0)
  1669.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  1670.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  1671.             {
  1672.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  1673.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  1674.                 {
  1675.                     p := elem+&EncoderParameters-pad-4
  1676.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  1677.                     break
  1678.                 }
  1679.             }      
  1680.         }
  1681.     }
  1682.  
  1683.     if (!A_IsUnicode)
  1684.     {
  1685.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  1686.         VarSetCapacity(wOutput, nSize*2)
  1687.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  1688.         VarSetCapacity(wOutput, -1)
  1689.         if !VarSetCapacity(wOutput)
  1690.             return -4
  1691.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  1692.     }
  1693.     else
  1694.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  1695.     return E ? -5 : 0
  1696. }
  1697.  
  1698. ;#####################################################################################
  1699.  
  1700. ; Function              Gdip_GetPixel
  1701. ; Description           Gets the ARGB of a pixel in a bitmap
  1702. ;
  1703. ; pBitmap               Pointer to a bitmap
  1704. ; x                     x-coordinate of the pixel
  1705. ; y                     y-coordinate of the pixel
  1706. ;
  1707. ; return                Returns the ARGB value of the pixel
  1708.  
  1709. Gdip_GetPixel(pBitmap, x, y)
  1710. {
  1711.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1712.     return ARGB
  1713. }
  1714.  
  1715. ;#####################################################################################
  1716.  
  1717. ; Function              Gdip_SetPixel
  1718. ; Description           Sets the ARGB of a pixel in a bitmap
  1719. ;
  1720. ; pBitmap               Pointer to a bitmap
  1721. ; x                     x-coordinate of the pixel
  1722. ; y                     y-coordinate of the pixel
  1723. ;
  1724. ; return                status enumeration. 0 = success
  1725.  
  1726. Gdip_SetPixel(pBitmap, x, y, ARGB)
  1727. {
  1728.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  1729. }
  1730.  
  1731. ;#####################################################################################
  1732.  
  1733. ; Function              Gdip_GetImageWidth
  1734. ; Description           Gives the width of a bitmap
  1735. ;
  1736. ; pBitmap               Pointer to a bitmap
  1737. ;
  1738. ; return                Returns the width in pixels of the supplied bitmap
  1739.  
  1740. Gdip_GetImageWidth(pBitmap)
  1741. {
  1742.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  1743.    return Width
  1744. }
  1745.  
  1746. ;#####################################################################################
  1747.  
  1748. ; Function              Gdip_GetImageHeight
  1749. ; Description           Gives the height of a bitmap
  1750. ;
  1751. ; pBitmap               Pointer to a bitmap
  1752. ;
  1753. ; return                Returns the height in pixels of the supplied bitmap
  1754.  
  1755. Gdip_GetImageHeight(pBitmap)
  1756. {
  1757.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  1758.    return Height
  1759. }
  1760.  
  1761. ;#####################################################################################
  1762.  
  1763. ; Function              Gdip_GetDimensions
  1764. ; Description           Gives the width and height of a bitmap
  1765. ;
  1766. ; pBitmap               Pointer to a bitmap
  1767. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  1768. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  1769. ;
  1770. ; return                No return value
  1771. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1772.  
  1773. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  1774. {
  1775.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1776.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  1777.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  1778. }
  1779.  
  1780. ;#####################################################################################
  1781.  
  1782. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  1783. {
  1784.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  1785. }
  1786.  
  1787. ;#####################################################################################
  1788.  
  1789. Gdip_GetImagePixelFormat(pBitmap)
  1790. {
  1791.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  1792.     return Format
  1793. }
  1794.  
  1795. ;#####################################################################################
  1796.  
  1797. ; Function              Gdip_GetDpiX
  1798. ; Description           Gives the horizontal dots per inch of the graphics of a bitmap
  1799. ;
  1800. ; pBitmap               Pointer to a bitmap
  1801. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  1802. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  1803. ;
  1804. ; return                No return value
  1805. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1806.  
  1807. Gdip_GetDpiX(pGraphics)
  1808. {
  1809.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  1810.     return Round(dpix)
  1811. }
  1812.  
  1813. ;#####################################################################################
  1814.  
  1815. Gdip_GetDpiY(pGraphics)
  1816. {
  1817.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  1818.     return Round(dpiy)
  1819. }
  1820.  
  1821. ;#####################################################################################
  1822.  
  1823. Gdip_GetImageHorizontalResolution(pBitmap)
  1824. {
  1825.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  1826.     return Round(dpix)
  1827. }
  1828.  
  1829. ;#####################################################################################
  1830.  
  1831. Gdip_GetImageVerticalResolution(pBitmap)
  1832. {
  1833.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  1834.     return Round(dpiy)
  1835. }
  1836.  
  1837. ;#####################################################################################
  1838.  
  1839. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  1840. {
  1841.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  1842. }
  1843.  
  1844. ;#####################################################################################
  1845.  
  1846. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  1847. {
  1848.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1849.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  1850.    
  1851.     SplitPath, sFile,,, ext
  1852.     if ext in exe,dll
  1853.     {
  1854.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  1855.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  1856.        
  1857.         VarSetCapacity(buf, BufSize, 0)
  1858.         Loop, Parse, Sizes, |
  1859.         {
  1860.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  1861.            
  1862.             if !hIcon
  1863.                 continue
  1864.  
  1865.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  1866.             {
  1867.                 DestroyIcon(hIcon)
  1868.                 continue
  1869.             }
  1870.            
  1871.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  1872.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  1873.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  1874.             {
  1875.                 DestroyIcon(hIcon)
  1876.                 continue
  1877.             }
  1878.             break
  1879.         }
  1880.         if !hIcon
  1881.             return -1
  1882.  
  1883.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  1884.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  1885.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  1886.         {
  1887.             DestroyIcon(hIcon)
  1888.             return -2
  1889.         }
  1890.        
  1891.         VarSetCapacity(dib, 104)
  1892.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  1893.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  1894.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  1895.         pBitmap := Gdip_CreateBitmap(Width, Height)
  1896.         G := Gdip_GraphicsFromImage(pBitmap)
  1897.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  1898.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  1899.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  1900.         DestroyIcon(hIcon)
  1901.     }
  1902.     else
  1903.     {
  1904.         if (!A_IsUnicode)
  1905.         {
  1906.             VarSetCapacity(wFile, 1024)
  1907.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  1908.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  1909.         }
  1910.         else
  1911.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  1912.     }
  1913.    
  1914.     return pBitmap
  1915. }
  1916.  
  1917. ;#####################################################################################
  1918.  
  1919. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  1920. {
  1921.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1922.    
  1923.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1924.     return pBitmap
  1925. }
  1926.  
  1927. ;#####################################################################################
  1928.  
  1929. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  1930. {
  1931.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  1932.     return hbm
  1933. }
  1934.  
  1935. ;#####################################################################################
  1936.  
  1937. Gdip_CreateBitmapFromHICON(hIcon)
  1938. {
  1939.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1940.     return pBitmap
  1941. }
  1942.  
  1943. ;#####################################################################################
  1944.  
  1945. Gdip_CreateHICONFromBitmap(pBitmap)
  1946. {
  1947.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  1948.     return hIcon
  1949. }
  1950.  
  1951. ;#####################################################################################
  1952.  
  1953. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  1954. {
  1955.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1956.     Return pBitmap
  1957. }
  1958.  
  1959. ;#####################################################################################
  1960.  
  1961. Gdip_CreateBitmapFromClipboard()
  1962. {
  1963.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1964.    
  1965.     if !DllCall("OpenClipboard", Ptr, 0)
  1966.         return -1
  1967.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  1968.         return -2
  1969.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  1970.         return -3
  1971.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  1972.         return -4
  1973.     if !DllCall("CloseClipboard")
  1974.         return -5
  1975.     DeleteObject(hBitmap)
  1976.     return pBitmap
  1977. }
  1978.  
  1979. ;#####################################################################################
  1980.  
  1981. Gdip_SetBitmapToClipboard(pBitmap)
  1982. {
  1983.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1984.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  1985.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  1986.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  1987.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  1988.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  1989.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  1990.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  1991.     DllCall("GlobalUnlock", Ptr, hdib)
  1992.     DllCall("DeleteObject", Ptr, hBitmap)
  1993.     DllCall("OpenClipboard", Ptr, 0)
  1994.     DllCall("EmptyClipboard")
  1995.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  1996.     DllCall("CloseClipboard")
  1997. }
  1998.  
  1999. ;#####################################################################################
  2000.  
  2001. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  2002. {
  2003.     DllCall("gdiplus\GdipCloneBitmapArea"
  2004.                     , "float", x
  2005.                     , "float", y
  2006.                     , "float", w
  2007.                     , "float", h
  2008.                     , "int", Format
  2009.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  2010.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  2011.     return pBitmapDest
  2012. }
  2013.  
  2014. ;#####################################################################################
  2015. ; Create resources
  2016. ;#####################################################################################
  2017.  
  2018. Gdip_CreatePen(ARGB, w)
  2019. {
  2020.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2021.    return pPen
  2022. }
  2023.  
  2024. ;#####################################################################################
  2025.  
  2026. Gdip_CreatePenFromBrush(pBrush, w)
  2027. {
  2028.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2029.     return pPen
  2030. }
  2031.  
  2032. ;#####################################################################################
  2033.  
  2034. Gdip_BrushCreateSolid(ARGB=0xff000000)
  2035. {
  2036.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2037.     return pBrush
  2038. }
  2039.  
  2040. ;#####################################################################################
  2041.  
  2042. ; HatchStyleHorizontal = 0
  2043. ; HatchStyleVertical = 1
  2044. ; HatchStyleForwardDiagonal = 2
  2045. ; HatchStyleBackwardDiagonal = 3
  2046. ; HatchStyleCross = 4
  2047. ; HatchStyleDiagonalCross = 5
  2048. ; HatchStyle05Percent = 6
  2049. ; HatchStyle10Percent = 7
  2050. ; HatchStyle20Percent = 8
  2051. ; HatchStyle25Percent = 9
  2052. ; HatchStyle30Percent = 10
  2053. ; HatchStyle40Percent = 11
  2054. ; HatchStyle50Percent = 12
  2055. ; HatchStyle60Percent = 13
  2056. ; HatchStyle70Percent = 14
  2057. ; HatchStyle75Percent = 15
  2058. ; HatchStyle80Percent = 16
  2059. ; HatchStyle90Percent = 17
  2060. ; HatchStyleLightDownwardDiagonal = 18
  2061. ; HatchStyleLightUpwardDiagonal = 19
  2062. ; HatchStyleDarkDownwardDiagonal = 20
  2063. ; HatchStyleDarkUpwardDiagonal = 21
  2064. ; HatchStyleWideDownwardDiagonal = 22
  2065. ; HatchStyleWideUpwardDiagonal = 23
  2066. ; HatchStyleLightVertical = 24
  2067. ; HatchStyleLightHorizontal = 25
  2068. ; HatchStyleNarrowVertical = 26
  2069. ; HatchStyleNarrowHorizontal = 27
  2070. ; HatchStyleDarkVertical = 28
  2071. ; HatchStyleDarkHorizontal = 29
  2072. ; HatchStyleDashedDownwardDiagonal = 30
  2073. ; HatchStyleDashedUpwardDiagonal = 31
  2074. ; HatchStyleDashedHorizontal = 32
  2075. ; HatchStyleDashedVertical = 33
  2076. ; HatchStyleSmallConfetti = 34
  2077. ; HatchStyleLargeConfetti = 35
  2078. ; HatchStyleZigZag = 36
  2079. ; HatchStyleWave = 37
  2080. ; HatchStyleDiagonalBrick = 38
  2081. ; HatchStyleHorizontalBrick = 39
  2082. ; HatchStyleWeave = 40
  2083. ; HatchStylePlaid = 41
  2084. ; HatchStyleDivot = 42
  2085. ; HatchStyleDottedGrid = 43
  2086. ; HatchStyleDottedDiamond = 44
  2087. ; HatchStyleShingle = 45
  2088. ; HatchStyleTrellis = 46
  2089. ; HatchStyleSphere = 47
  2090. ; HatchStyleSmallGrid = 48
  2091. ; HatchStyleSmallCheckerBoard = 49
  2092. ; HatchStyleLargeCheckerBoard = 50
  2093. ; HatchStyleOutlinedDiamond = 51
  2094. ; HatchStyleSolidDiamond = 52
  2095. ; HatchStyleTotal = 53
  2096. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  2097. {
  2098.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2099.     return pBrush
  2100. }
  2101.  
  2102. ;#####################################################################################
  2103.  
  2104. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  2105. {
  2106.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2107.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2108.    
  2109.     if !(w && h)
  2110.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  2111.     else
  2112.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  2113.     return pBrush
  2114. }
  2115.  
  2116. ;#####################################################################################
  2117.  
  2118. ; WrapModeTile = 0
  2119. ; WrapModeTileFlipX = 1
  2120. ; WrapModeTileFlipY = 2
  2121. ; WrapModeTileFlipXY = 3
  2122. ; WrapModeClamp = 4
  2123. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2124. {
  2125.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2126.    
  2127.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  2128.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2129.     return LGpBrush
  2130. }
  2131.  
  2132. ;#####################################################################################
  2133.  
  2134. ; LinearGradientModeHorizontal = 0
  2135. ; LinearGradientModeVertical = 1
  2136. ; LinearGradientModeForwardDiagonal = 2
  2137. ; LinearGradientModeBackwardDiagonal = 3
  2138. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2139. {
  2140.     CreateRectF(RectF, x, y, w, h)
  2141.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2142.     return LGpBrush
  2143. }
  2144.  
  2145. ;#####################################################################################
  2146.  
  2147. Gdip_CloneBrush(pBrush)
  2148. {
  2149.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  2150.     return pBrushClone
  2151. }
  2152.  
  2153. ;#####################################################################################
  2154. ; Delete resources
  2155. ;#####################################################################################
  2156.  
  2157. Gdip_DeletePen(pPen)
  2158. {
  2159.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  2160. }
  2161.  
  2162. ;#####################################################################################
  2163.  
  2164. Gdip_DeleteBrush(pBrush)
  2165. {
  2166.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  2167. }
  2168.  
  2169. ;#####################################################################################
  2170.  
  2171. Gdip_DisposeImage(pBitmap)
  2172. {
  2173.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  2174. }
  2175.  
  2176. ;#####################################################################################
  2177.  
  2178. Gdip_DeleteGraphics(pGraphics)
  2179. {
  2180.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2181. }
  2182.  
  2183. ;#####################################################################################
  2184.  
  2185. Gdip_DisposeImageAttributes(ImageAttr)
  2186. {
  2187.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  2188. }
  2189.  
  2190. ;#####################################################################################
  2191.  
  2192. Gdip_DeleteFont(hFont)
  2193. {
  2194.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  2195. }
  2196.  
  2197. ;#####################################################################################
  2198.  
  2199. Gdip_DeleteStringFormat(hFormat)
  2200. {
  2201.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  2202. }
  2203.  
  2204. ;#####################################################################################
  2205.  
  2206. Gdip_DeleteFontFamily(hFamily)
  2207. {
  2208.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  2209. }
  2210.  
  2211. ;#####################################################################################
  2212.  
  2213. Gdip_DeleteMatrix(Matrix)
  2214. {
  2215.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  2216. }
  2217.  
  2218. ;#####################################################################################
  2219. ; Text functions
  2220. ;#####################################################################################
  2221.  
  2222. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2223. {
  2224.     IWidth := Width, IHeight:= Height
  2225.    
  2226.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2227.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2228.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2229.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2230.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2231.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2232.     RegExMatch(Options, "i)NoWrap", NoWrap)
  2233.     RegExMatch(Options, "i)R(\d)", Rendering)
  2234.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2235.  
  2236.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2237.         PassBrush := 1, pBrush := Colour2
  2238.    
  2239.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2240.         return -1
  2241.  
  2242.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2243.     Loop, Parse, Styles, |
  2244.     {
  2245.         if RegExMatch(Options, "\b" A_loopField)
  2246.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2247.     }
  2248.  
  2249.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2250.     Loop, Parse, Alignments, |
  2251.     {
  2252.         if RegExMatch(Options, "\b" A_loopField)
  2253.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  2254.     }
  2255.  
  2256.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2257.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2258.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2259.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2260.     if !PassBrush
  2261.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2262.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2263.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2264.  
  2265.     hFamily := Gdip_FontFamilyCreate(Font)
  2266.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  2267.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  2268.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  2269.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2270.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2271.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2272.    
  2273.     CreateRectF(RC, xpos, ypos, Width, Height)
  2274.     Gdip_SetStringFormatAlign(hFormat, Align)
  2275.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2276.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2277.  
  2278.     if vPos
  2279.     {
  2280.         StringSplit, ReturnRC, ReturnRC, |
  2281.        
  2282.         if (vPos = "vCentre") || (vPos = "vCenter")
  2283.             ypos += (Height-ReturnRC4)//2
  2284.         else if (vPos = "Top") || (vPos = "Up")
  2285.             ypos := 0
  2286.         else if (vPos = "Bottom") || (vPos = "Down")
  2287.             ypos := Height-ReturnRC4
  2288.        
  2289.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2290.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2291.     }
  2292.  
  2293.     if !Measure
  2294.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2295.  
  2296.     if !PassBrush
  2297.         Gdip_DeleteBrush(pBrush)
  2298.     Gdip_DeleteStringFormat(hFormat)  
  2299.     Gdip_DeleteFont(hFont)
  2300.     Gdip_DeleteFontFamily(hFamily)
  2301.     return E ? E : ReturnRC
  2302. }
  2303.  
  2304. ;#####################################################################################
  2305.  
  2306. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2307. {
  2308.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2309.    
  2310.     if (!A_IsUnicode)
  2311.     {
  2312.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  2313.         VarSetCapacity(wString, nSize*2)
  2314.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2315.     }
  2316.    
  2317.     return DllCall("gdiplus\GdipDrawString"
  2318.                     , Ptr, pGraphics
  2319.                     , Ptr, A_IsUnicode ? &sString : &wString
  2320.                     , "int", -1
  2321.                     , Ptr, hFont
  2322.                     , Ptr, &RectF
  2323.                     , Ptr, hFormat
  2324.                     , Ptr, pBrush)
  2325. }
  2326.  
  2327. ;#####################################################################################
  2328.  
  2329. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2330. {
  2331.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2332.    
  2333.     VarSetCapacity(RC, 16)
  2334.     if !A_IsUnicode
  2335.     {
  2336.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  2337.         VarSetCapacity(wString, nSize*2)  
  2338.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2339.     }
  2340.    
  2341.     DllCall("gdiplus\GdipMeasureString"
  2342.                     , Ptr, pGraphics
  2343.                     , Ptr, A_IsUnicode ? &sString : &wString
  2344.                     , "int", -1
  2345.                     , Ptr, hFont
  2346.                     , Ptr, &RectF
  2347.                     , Ptr, hFormat
  2348.                     , Ptr, &RC
  2349.                     , "uint*", Chars
  2350.                     , "uint*", Lines)
  2351.    
  2352.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2353. }
  2354.  
  2355. ; Near = 0
  2356. ; Center = 1
  2357. ; Far = 2
  2358. Gdip_SetStringFormatAlign(hFormat, Align)
  2359. {
  2360.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  2361. }
  2362.  
  2363. ; StringFormatFlagsDirectionRightToLeft    = 0x00000001
  2364. ; StringFormatFlagsDirectionVertical       = 0x00000002
  2365. ; StringFormatFlagsNoFitBlackBox           = 0x00000004
  2366. ; StringFormatFlagsDisplayFormatControl    = 0x00000020
  2367. ; StringFormatFlagsNoFontFallback          = 0x00000400
  2368. ; StringFormatFlagsMeasureTrailingSpaces   = 0x00000800
  2369. ; StringFormatFlagsNoWrap                  = 0x00001000
  2370. ; StringFormatFlagsLineLimit               = 0x00002000
  2371. ; StringFormatFlagsNoClip                  = 0x00004000
  2372. Gdip_StringFormatCreate(Format=0, Lang=0)
  2373. {
  2374.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  2375.    return hFormat
  2376. }
  2377.  
  2378. ; Regular = 0
  2379. ; Bold = 1
  2380. ; Italic = 2
  2381. ; BoldItalic = 3
  2382. ; Underline = 4
  2383. ; Strikeout = 8
  2384. Gdip_FontCreate(hFamily, Size, Style=0)
  2385. {
  2386.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  2387.    return hFont
  2388. }
  2389.  
  2390. Gdip_FontFamilyCreate(Font)
  2391. {
  2392.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2393.    
  2394.     if (!A_IsUnicode)
  2395.     {
  2396.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  2397.         VarSetCapacity(wFont, nSize*2)
  2398.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  2399.     }
  2400.    
  2401.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  2402.                     , Ptr, A_IsUnicode ? &Font : &wFont
  2403.                     , "uint", 0
  2404.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  2405.    
  2406.     return hFamily
  2407. }
  2408.  
  2409. ;#####################################################################################
  2410. ; Matrix functions
  2411. ;#####################################################################################
  2412.  
  2413. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2414. {
  2415.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2416.    return Matrix
  2417. }
  2418.  
  2419. Gdip_CreateMatrix()
  2420. {
  2421.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2422.    return Matrix
  2423. }
  2424.  
  2425. ;#####################################################################################
  2426. ; GraphicsPath functions
  2427. ;#####################################################################################
  2428.  
  2429. ; Alternate = 0
  2430. ; Winding = 1
  2431. Gdip_CreatePath(BrushMode=0)
  2432. {
  2433.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  2434.     return Path
  2435. }
  2436.  
  2437. Gdip_AddPathEllipse(Path, x, y, w, h)
  2438. {
  2439.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  2440. }
  2441.  
  2442. Gdip_AddPathPolygon(Path, Points)
  2443. {
  2444.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2445.    
  2446.     StringSplit, Points, Points, |
  2447.     VarSetCapacity(PointF, 8*Points0)  
  2448.     Loop, %Points0%
  2449.     {
  2450.         StringSplit, Coord, Points%A_Index%, `,
  2451.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2452.     }  
  2453.  
  2454.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  2455. }
  2456.  
  2457. Gdip_DeletePath(Path)
  2458. {
  2459.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  2460. }
  2461.  
  2462. ;#####################################################################################
  2463. ; Quality functions
  2464. ;#####################################################################################
  2465.  
  2466. ; SystemDefault = 0
  2467. ; SingleBitPerPixelGridFit = 1
  2468. ; SingleBitPerPixel = 2
  2469. ; AntiAliasGridFit = 3
  2470. ; AntiAlias = 4
  2471. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2472. {
  2473.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  2474. }
  2475.  
  2476. ; Default = 0
  2477. ; LowQuality = 1
  2478. ; HighQuality = 2
  2479. ; Bilinear = 3
  2480. ; Bicubic = 4
  2481. ; NearestNeighbor = 5
  2482. ; HighQualityBilinear = 6
  2483. ; HighQualityBicubic = 7
  2484. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2485. {
  2486.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  2487. }
  2488.  
  2489. ; Default = 0
  2490. ; HighSpeed = 1
  2491. ; HighQuality = 2
  2492. ; None = 3
  2493. ; AntiAlias = 4
  2494. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2495. {
  2496.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  2497. }
  2498.  
  2499. ; CompositingModeSourceOver = 0 (blended)
  2500. ; CompositingModeSourceCopy = 1 (overwrite)
  2501. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2502. {
  2503.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  2504. }
  2505.  
  2506. ;#####################################################################################
  2507. ; Extra functions
  2508. ;#####################################################################################
  2509.  
  2510. Gdip_Startup()
  2511. {
  2512.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2513.    
  2514.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2515.         DllCall("LoadLibrary", "str", "gdiplus")
  2516.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  2517.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  2518.     return pToken
  2519. }
  2520.  
  2521. Gdip_Shutdown(pToken)
  2522. {
  2523.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2524.    
  2525.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  2526.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2527.         DllCall("FreeLibrary", Ptr, hModule)
  2528.     return 0
  2529. }
  2530.  
  2531. ; Prepend = 0; The new operation is applied before the old operation.
  2532. ; Append = 1; The new operation is applied after the old operation.
  2533. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2534. {
  2535.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  2536. }
  2537.  
  2538. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2539. {
  2540.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2541. }
  2542.  
  2543. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2544. {
  2545.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2546. }
  2547.  
  2548. Gdip_ResetWorldTransform(pGraphics)
  2549. {
  2550.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2551. }
  2552.  
  2553. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2554. {
  2555.     pi := 3.14159, TAngle := Angle*(pi/180)
  2556.  
  2557.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2558.     if ((Bound >= 0) && (Bound <= 90))
  2559.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  2560.     else if ((Bound > 90) && (Bound <= 180))
  2561.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2562.     else if ((Bound > 180) && (Bound <= 270))
  2563.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2564.     else if ((Bound > 270) && (Bound <= 360))
  2565.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2566. }
  2567.  
  2568. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2569. {
  2570.     pi := 3.14159, TAngle := Angle*(pi/180)
  2571.     if !(Width && Height)
  2572.         return -1
  2573.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2574.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2575. }
  2576.  
  2577. ; RotateNoneFlipNone   = 0
  2578. ; Rotate90FlipNone     = 1
  2579. ; Rotate180FlipNone    = 2
  2580. ; Rotate270FlipNone    = 3
  2581. ; RotateNoneFlipX      = 4
  2582. ; Rotate90FlipX        = 5
  2583. ; Rotate180FlipX       = 6
  2584. ; Rotate270FlipX       = 7
  2585. ; RotateNoneFlipY      = Rotate180FlipX
  2586. ; Rotate90FlipY        = Rotate270FlipX
  2587. ; Rotate180FlipY       = RotateNoneFlipX
  2588. ; Rotate270FlipY       = Rotate90FlipX
  2589. ; RotateNoneFlipXY     = Rotate180FlipNone
  2590. ; Rotate90FlipXY       = Rotate270FlipNone
  2591. ; Rotate180FlipXY      = RotateNoneFlipNone
  2592. ; Rotate270FlipXY      = Rotate90FlipNone
  2593.  
  2594. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  2595. {
  2596.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  2597. }
  2598.  
  2599. ; Replace = 0
  2600. ; Intersect = 1
  2601. ; Union = 2
  2602. ; Xor = 3
  2603. ; Exclude = 4
  2604. ; Complement = 5
  2605. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2606. {
  2607.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2608. }
  2609.  
  2610. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2611. {
  2612.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2613.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  2614. }
  2615.  
  2616. Gdip_ResetClip(pGraphics)
  2617. {
  2618.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2619. }
  2620.  
  2621. Gdip_GetClipRegion(pGraphics)
  2622. {
  2623.     Region := Gdip_CreateRegion()
  2624.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  2625.     return Region
  2626. }
  2627.  
  2628. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  2629. {
  2630.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2631.    
  2632.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  2633. }
  2634.  
  2635. Gdip_CreateRegion()
  2636. {
  2637.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  2638.     return Region
  2639. }
  2640.  
  2641. Gdip_DeleteRegion(Region)
  2642. {
  2643.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  2644. }
  2645.  
  2646. ;#####################################################################################
  2647. ; BitmapLockBits
  2648. ;#####################################################################################
  2649.  
  2650. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  2651. {
  2652.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2653.    
  2654.     CreateRect(Rect, x, y, w, h)
  2655.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  2656.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  2657.     Stride := NumGet(BitmapData, 8, "Int")
  2658.     Scan0 := NumGet(BitmapData, 16, Ptr)
  2659.     return E
  2660. }
  2661.  
  2662. ;#####################################################################################
  2663.  
  2664. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  2665. {
  2666.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2667.    
  2668.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  2669. }
  2670.  
  2671. ;#####################################################################################
  2672.  
  2673. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  2674. {
  2675.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  2676. }
  2677.  
  2678. ;#####################################################################################
  2679.  
  2680. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  2681. {
  2682.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  2683. }
  2684.  
  2685. ;#####################################################################################
  2686.  
  2687. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  2688. {
  2689.     static PixelateBitmap
  2690.    
  2691.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2692.    
  2693.     if (!PixelateBitmap)
  2694.     {
  2695.         if A_PtrSize != 8 ; x86 machine code
  2696.         MCode_PixelateBitmap =
  2697.         (LTrim Join
  2698.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  2699.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  2700.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  2701.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  2702.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  2703.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  2704.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  2705.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  2706.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  2707.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  2708.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  2709.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  2710.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  2711.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  2712.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  2713.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  2714.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  2715.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  2716.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  2717.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  2718.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  2719.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  2720.         )
  2721.         else ; x64 machine code
  2722.         MCode_PixelateBitmap =
  2723.         (LTrim Join
  2724.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  2725.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  2726.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  2727.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  2728.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  2729.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  2730.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  2731.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  2732.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  2733.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  2734.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  2735.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  2736.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  2737.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  2738.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  2739.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  2740.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  2741.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  2742.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  2743.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  2744.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  2745.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  2746.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  2747.         )
  2748.        
  2749.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  2750.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  2751.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  2752.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  2753.     }
  2754.  
  2755.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  2756.    
  2757.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  2758.         return -1
  2759.     if (BlockSize > Width || BlockSize > Height)
  2760.         return -2
  2761.  
  2762.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  2763.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  2764.     if (E1 || E2)
  2765.         return -3
  2766.  
  2767.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  2768.    
  2769.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  2770.     return 0
  2771. }
  2772.  
  2773. ;#####################################################################################
  2774.  
  2775. Gdip_ToARGB(A, R, G, B)
  2776. {
  2777.     return (A << 24) | (R << 16) | (G << 8) | B
  2778. }
  2779.  
  2780. ;#####################################################################################
  2781.  
  2782. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  2783. {
  2784.     A := (0xff000000 & ARGB) >> 24
  2785.     R := (0x00ff0000 & ARGB) >> 16
  2786.     G := (0x0000ff00 & ARGB) >> 8
  2787.     B := 0x000000ff & ARGB
  2788. }
  2789.  
  2790. ;#####################################################################################
  2791.  
  2792. Gdip_AFromARGB(ARGB)
  2793. {
  2794.     return (0xff000000 & ARGB) >> 24
  2795. }
  2796.  
  2797. ;#####################################################################################
  2798.  
  2799. Gdip_RFromARGB(ARGB)
  2800. {
  2801.     return (0x00ff0000 & ARGB) >> 16
  2802. }
  2803.  
  2804. ;#####################################################################################
  2805.  
  2806. Gdip_GFromARGB(ARGB)
  2807. {
  2808.     return (0x0000ff00 & ARGB) >> 8
  2809. }
  2810.  
  2811. ;#####################################################################################
  2812.  
  2813. Gdip_BFromARGB(ARGB)
  2814. {
  2815.     return 0x000000ff & ARGB
  2816. }
  2817.  
  2818. ;#####################################################################################
  2819.  
  2820. StrGetB(Address, Length=-1, Encoding=0)
  2821. {
  2822.     ; Flexible parameter handling:
  2823.     if Length is not integer
  2824.     Encoding := Length,  Length := -1
  2825.  
  2826.     ; Check for obvious errors.
  2827.     if (Address+0 < 1024)
  2828.         return
  2829.  
  2830.     ; Ensure 'Encoding' contains a numeric identifier.
  2831.     if Encoding = UTF-16
  2832.         Encoding = 1200
  2833.     else if Encoding = UTF-8
  2834.         Encoding = 65001
  2835.     else if SubStr(Encoding,1,2)="CP"
  2836.         Encoding := SubStr(Encoding,3)
  2837.  
  2838.     if !Encoding ; "" or 0
  2839.     {
  2840.         ; No conversion necessary, but we might not want the whole string.
  2841.         if (Length == -1)
  2842.             Length := DllCall("lstrlen", "uint", Address)
  2843.         VarSetCapacity(String, Length)
  2844.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  2845.     }
  2846.     else if Encoding = 1200 ; UTF-16
  2847.     {
  2848.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  2849.         VarSetCapacity(String, char_count)
  2850.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  2851.     }
  2852.     else if Encoding is integer
  2853.     {
  2854.         ; Convert from target encoding to UTF-16 then to the active code page.
  2855.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  2856.         VarSetCapacity(String, char_count * 2)
  2857.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  2858.         String := StrGetB(&String, char_count, 1200)
  2859.     }
  2860.    
  2861.     return String
  2862. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement