Advertisement
Guest User

Gdip functions tool

a guest
May 22nd, 2018
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Written By: Hellbent aka CivReborn (https://www.youtube.com/user/CivReborn)
  3.     Date Stared: May 21st, 2018
  4.     Date Of Last Edit: May 21st, 2018
  5.     PasteBin Link:
  6.     Description:
  7.         A simple tool that lists all the current functions for the gdip lib.
  8.         The tool allows you to:
  9.              -Dump the prototype of a function to your clipboard
  10.              -Dump a full function into your clipboard
  11.              -Make a clone of your gdip lib to paste in a new folder
  12.              -Dump the full gdip lib into your clipboard to paste in a new script.
  13. */
  14.  
  15.  
  16. #SingleInstance,Force
  17. ;--------------------------------------------------------------------------------
  18. ;--------------------------------------------------------------------------------
  19.  
  20. Gdip_File_Full_Path:=  "  "  ;Add the full path to a copy of gdip between the quotes
  21.  
  22. ;--------------------------------------------------------------------------------
  23. ;--------------------------------------------------------------------------------
  24. set_Temp()
  25. FileRead,temp2,% A_ScriptFullPath
  26. My_Array:=StrSplit(temp,"î")
  27. My_Array2:=StrSplit(temp2,"•")
  28. My_Array3:=StrSplit(temp2,"¤")
  29.  
  30. My_Array.Remove(1)
  31. loop 2
  32.     My_Array2.Remove(1)
  33. loop 2
  34.     My_Array3.Remove(1)
  35. My_Array3.Remove(2)
  36. Loop,% My_Array.Length()
  37.     {
  38.         (A_Index=1)?(Functions_Prototypes.=My_Array[A_Index] "||"):(Functions_Prototypes.=My_Array[A_Index] "|")
  39.     }
  40. Loop,% My_Array2.Length()
  41.     {
  42.         (A_Index=1)?(Full_Functions.=My_Array2[A_Index] "||"):(Full_Functions.=My_Array2[A_Index] "|")
  43.     }  
  44. Gui,+AlwaysOnTop   
  45. Gui,color,black,   
  46. Gui,Font, q5, ;Gill Sans Ultra Bold   ;Cambria
  47. Gui,Add,ListBox, x10 y10 w350 r10  AltSubmit vSelected_Prototype gProto,% Functions_Prototypes
  48. Gui,Add,Button,x+10 y10 w240 r1 Section -Theme gClip_Prototype,Clip Prototype
  49. Gui,Add,Button,xs w240 r1  gClip_Full_Functions             -Theme,Clip Function
  50. Gui,Add,Checkbox,cWhite xs w55  r1 BackgroundTrans gLock ,Unlock
  51. Gui,Add,Button,x+10 w175 r1 Disabled -Theme vClip_File  gCopy_File,Clip Gdip File
  52. Gui,Add,Button,xs w240 r1  Disabled -Theme vClip_Full_Gdip_Text gClip_all_Gdip ,Clip Gdip Text
  53. Gui,Add,ComboBox, xs w350 r20 Hidden AltSubmit vextra gProto2,% Functions_Prototypes
  54. Gui,Add,edit, x10 w900 r30 -Wrap HScroll Hidden vEdit1,%  My_Array2[1]  
  55. Gui,Show,AutoSize
  56. Gui,Submit,NoHide
  57. return
  58. GuiClose:
  59. GuiEscape:
  60.     ExitApp
  61. GuiContextMenu:
  62.     gosub, Hide_Edit
  63.     return
  64. Lock:
  65.     if(Lock:=!Lock)
  66.         {
  67.             GuiControl,Enable,Clip_File
  68.             GuiControl,Enable,Clip_Full_Gdip_Text
  69.         }
  70.     else
  71.         {
  72.             GuiControl,Disable,Clip_File
  73.             GuiControl,Disable,Clip_Full_Gdip_Text
  74.         }
  75.     return
  76. Proto:
  77.     Gui,Submit,NoHide
  78.     GuiControl,,Edit1,% My_Array2[Selected_Prototype]
  79.     return
  80. Proto2:
  81.     Gui,Submit,NoHide
  82.     GuiControl,Choose,Selected_Prototype,% extra
  83.     gosub,Proto
  84.     return 
  85. Hide_Edit:
  86.     if(Show_Edit:=!Show_Edit){
  87.         GuiControl,Show,Edit1
  88.         GuiControl,Show,extra
  89.         Gui,Show,AutoSize
  90.     }else   {
  91.         GuiControl,Hide,Edit1
  92.         GuiControl,Hide,extra
  93.         Gui,Show,AutoSize
  94.     }
  95.     return
  96. Clip_Prototype:
  97.     Clipboard:=""
  98.     sleep,200
  99.     Clipboard:=My_Array[Selected_Prototype]
  100.     return
  101. Clip_Full_Functions:
  102.     Clipboard:=""
  103.     sleep,200
  104.     Clipboard:=My_Array2[Selected_Prototype]
  105.     return
  106. Clip_all_Gdip:
  107.     Clipboard:=""
  108.     sleep,200
  109.     Clipboard:=My_Array3[1]
  110.     return
  111. Copy_File:
  112.     InvokeVerb(Gdip_File_Full_Path,"copy")
  113.     return
  114. InvokeVerb(path, menu, validate=True)
  115.     {
  116.         objShell := ComObjCreate("Shell.Application")
  117.         if InStr(FileExist(path), "D") || InStr(path, "::{")
  118.             {
  119.                 objFolder := objShell.NameSpace(path)  
  120.                 objFolderItem := objFolder.Self
  121.             }
  122.         else
  123.             {
  124.                 SplitPath, path, name, dir
  125.                 objFolder := objShell.NameSpace(dir)
  126.                 objFolderItem := objFolder.ParseName(name)
  127.             }
  128.         if validate
  129.             {
  130.                 colVerbs := objFolderItem.Verbs  
  131.                 loop % colVerbs.Count
  132.                 {
  133.                     verb := colVerbs.Item(A_Index - 1)
  134.                     retMenu := verb.name
  135.                     StringReplace, retMenu, retMenu, &      
  136.                     if (retMenu = menu)
  137.                         {
  138.                             verb.DoIt
  139.                             Return True
  140.                         }
  141.                 }
  142.             Return False
  143.             }
  144.         else
  145.             objFolderItem.InvokeVerbEx(Menu)
  146.     }
  147.  
  148. ; This is the full Gdip Lib
  149. ;-----------------------------------------------------------------------------------------------
  150. ;-----------------------------------------------------------------------------------------------
  151. ;-----------------------------------------------------------------------------------------------
  152.  
  153.  
  154. ; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11
  155. ; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013
  156. ; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64
  157. ;
  158. ; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86
  159. ; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64
  160. ;
  161. ;#####################################################################################
  162. ;#####################################################################################
  163. ; STATUS ENUMERATION
  164. ; Return values for functions specified to have status enumerated return type
  165. ;#####################################################################################
  166. ;
  167. ; Ok =                      = 0
  168. ; GenericError              = 1
  169. ; InvalidParameter          = 2
  170. ; OutOfMemory               = 3
  171. ; ObjectBusy                = 4
  172. ; InsufficientBuffer        = 5
  173. ; NotImplemented            = 6
  174. ; Win32Error                = 7
  175. ; WrongState                = 8
  176. ; Aborted                   = 9
  177. ; FileNotFound              = 10
  178. ; ValueOverflow             = 11
  179. ; AccessDenied              = 12
  180. ; UnknownImageFormat        = 13
  181. ; FontFamilyNotFound        = 14
  182. ; FontStyleNotFound         = 15
  183. ; NotTrueTypeFont           = 16
  184. ; UnsupportedGdiplusVersion = 17
  185. ; GdiplusNotInitialized     = 18
  186. ; PropertyNotFound          = 19
  187. ; PropertyNotSupported      = 20
  188. ; ProfileNotFound           = 21
  189. ;
  190. ;#####################################################################################
  191. ;#####################################################################################
  192. ; FUNCTIONS
  193. ;#####################################################################################
  194. ;
  195. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  196. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  197. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  198. ; SetImage(hwnd, hBitmap)
  199. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  200. ; CreateRectF(ByRef RectF, x, y, w, h)
  201. ; CreateSizeF(ByRef SizeF, w, h)
  202. ; CreateDIBSection
  203. ;
  204. ;#####################################################################################
  205.  
  206. ; Function:                 UpdateLayeredWindow
  207. ; Description:              Updates a layered window with the handle to the DC of a gdi bitmap
  208. ;
  209. ; hwnd                      Handle of the layered window to update
  210. ; hdc                       Handle to the DC of the GDI bitmap to update the window with
  211. ; Layeredx                  x position to place the window
  212. ; Layeredy                  y position to place the window
  213. ; Layeredw                  Width of the window
  214. ; Layeredh                  Height of the window
  215. ; Alpha                     Default = 255 : The transparency (0-255) to set the window transparency
  216. ;
  217. ; return                    If the function succeeds, the return value is nonzero
  218. ;
  219. ; notes                     If x or y omitted, then layered window will use its current coordinates
  220. ;                           If w or h omitted then current width and height will be used
  221.  
  222. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  223. {
  224.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  225.    
  226.     if ((x != "") && (y != ""))
  227.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  228.  
  229.     if (w = "") ||(h = "")
  230.         WinGetPos,,, w, h, ahk_id %hwnd%
  231.    
  232.     return DllCall("UpdateLayeredWindow"
  233.                     , Ptr, hwnd
  234.                     , Ptr, 0
  235.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  236.                     , "int64*", w|h<<32
  237.                     , Ptr, hdc
  238.                     , "int64*", 0
  239.                     , "uint", 0
  240.                     , "UInt*", Alpha<<16|1<<24
  241.                     , "uint", 2)
  242. }
  243.  
  244. ;#####################################################################################
  245.  
  246. ; Function              BitBlt
  247. ; Description           The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  248. ;                       of pixels from the specified source device context into a destination device context.
  249. ;
  250. ; dDC                   handle to destination DC
  251. ; dx                    x-coord of destination upper-left corner
  252. ; dy                    y-coord of destination upper-left corner
  253. ; dw                    width of the area to copy
  254. ; dh                    height of the area to copy
  255. ; sDC                   handle to source DC
  256. ; sx                    x-coordinate of source upper-left corner
  257. ; sy                    y-coordinate of source upper-left corner
  258. ; Raster                raster operation code
  259. ;
  260. ; return                If the function succeeds, the return value is nonzero
  261. ;
  262. ; notes                 If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  263. ;
  264. ; BLACKNESS             = 0x00000042
  265. ; NOTSRCERASE           = 0x001100A6
  266. ; NOTSRCCOPY            = 0x00330008
  267. ; SRCERASE              = 0x00440328
  268. ; DSTINVERT             = 0x00550009
  269. ; PATINVERT             = 0x005A0049
  270. ; SRCINVERT             = 0x00660046
  271. ; SRCAND                = 0x008800C6
  272. ; MERGEPAINT            = 0x00BB0226
  273. ; MERGECOPY             = 0x00C000CA
  274. ; SRCCOPY               = 0x00CC0020
  275. ; SRCPAINT              = 0x00EE0086
  276. ; PATCOPY               = 0x00F00021
  277. ; PATPAINT              = 0x00FB0A09
  278. ; WHITENESS             = 0x00FF0062
  279. ; CAPTUREBLT            = 0x40000000
  280. ; NOMIRRORBITMAP        = 0x80000000
  281.  
  282. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  283. {
  284.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  285.    
  286.     return DllCall("gdi32\BitBlt"
  287.                     , Ptr, dDC
  288.                     , "int", dx
  289.                     , "int", dy
  290.                     , "int", dw
  291.                     , "int", dh
  292.                     , Ptr, sDC
  293.                     , "int", sx
  294.                     , "int", sy
  295.                     , "uint", Raster ? Raster : 0x00CC0020)
  296. }
  297.  
  298. ;#####################################################################################
  299.  
  300. ; Function              StretchBlt
  301. ; Description           The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  302. ;                       stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  303. ;                       The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  304. ;
  305. ; ddc                   handle to destination DC
  306. ; dx                    x-coord of destination upper-left corner
  307. ; dy                    y-coord of destination upper-left corner
  308. ; dw                    width of destination rectangle
  309. ; dh                    height of destination rectangle
  310. ; sdc                   handle to source DC
  311. ; sx                    x-coordinate of source upper-left corner
  312. ; sy                    y-coordinate of source upper-left corner
  313. ; sw                    width of source rectangle
  314. ; sh                    height of source rectangle
  315. ; Raster                raster operation code
  316. ;
  317. ; return                If the function succeeds, the return value is nonzero
  318. ;
  319. ; notes                 If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt    
  320.  
  321. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  322. {
  323.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  324.    
  325.     return DllCall("gdi32\StretchBlt"
  326.                     , Ptr, ddc
  327.                     , "int", dx
  328.                     , "int", dy
  329.                     , "int", dw
  330.                     , "int", dh
  331.                     , Ptr, sdc
  332.                     , "int", sx
  333.                     , "int", sy
  334.                     , "int", sw
  335.                     , "int", sh
  336.                     , "uint", Raster ? Raster : 0x00CC0020)
  337. }
  338.  
  339. ;#####################################################################################
  340.  
  341. ; Function              SetStretchBltMode
  342. ; Description           The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  343. ;
  344. ; hdc                   handle to the DC
  345. ; iStretchMode          The stretching mode, describing how the target will be stretched
  346. ;
  347. ; return                If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  348. ;
  349. ; STRETCH_ANDSCANS      = 0x01
  350. ; STRETCH_ORSCANS       = 0x02
  351. ; STRETCH_DELETESCANS   = 0x03
  352. ; STRETCH_HALFTONE      = 0x04
  353.  
  354. SetStretchBltMode(hdc, iStretchMode=4)
  355. {
  356.     return DllCall("gdi32\SetStretchBltMode"
  357.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  358.                     , "int", iStretchMode)
  359. }
  360.  
  361. ;#####################################################################################
  362.  
  363. ; Function              SetImage
  364. ; Description           Associates a new image with a static control
  365. ;
  366. ; hwnd                  handle of the control to update
  367. ; hBitmap               a gdi bitmap to associate the static control with
  368. ;
  369. ; return                If the function succeeds, the return value is nonzero
  370.  
  371. SetImage(hwnd, hBitmap)
  372. {
  373.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  374.     E := ErrorLevel
  375.     DeleteObject(E)
  376.     return E
  377. }
  378.  
  379. ;#####################################################################################
  380.  
  381. ; Function              SetSysColorToControl
  382. ; Description           Sets a solid colour to a control
  383. ;
  384. ; hwnd                  handle of the control to update
  385. ; SysColor              A system colour to set to the control
  386. ;
  387. ; return                If the function succeeds, the return value is zero
  388. ;
  389. ; notes                 A control must have the 0xE style set to it so it is recognised as a bitmap
  390. ;                       By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  391. ;
  392. ; COLOR_3DDKSHADOW              = 21
  393. ; COLOR_3DFACE                  = 15
  394. ; COLOR_3DHIGHLIGHT             = 20
  395. ; COLOR_3DHILIGHT               = 20
  396. ; COLOR_3DLIGHT                 = 22
  397. ; COLOR_3DSHADOW                = 16
  398. ; COLOR_ACTIVEBORDER            = 10
  399. ; COLOR_ACTIVECAPTION           = 2
  400. ; COLOR_APPWORKSPACE            = 12
  401. ; COLOR_BACKGROUND              = 1
  402. ; COLOR_BTNFACE                 = 15
  403. ; COLOR_BTNHIGHLIGHT            = 20
  404. ; COLOR_BTNHILIGHT              = 20
  405. ; COLOR_BTNSHADOW               = 16
  406. ; COLOR_BTNTEXT                 = 18
  407. ; COLOR_CAPTIONTEXT             = 9
  408. ; COLOR_DESKTOP                 = 1
  409. ; COLOR_GRADIENTACTIVECAPTION   = 27
  410. ; COLOR_GRADIENTINACTIVECAPTION = 28
  411. ; COLOR_GRAYTEXT                = 17
  412. ; COLOR_HIGHLIGHT               = 13
  413. ; COLOR_HIGHLIGHTTEXT           = 14
  414. ; COLOR_HOTLIGHT                = 26
  415. ; COLOR_INACTIVEBORDER          = 11
  416. ; COLOR_INACTIVECAPTION         = 3
  417. ; COLOR_INACTIVECAPTIONTEXT     = 19
  418. ; COLOR_INFOBK                  = 24
  419. ; COLOR_INFOTEXT                = 23
  420. ; COLOR_MENU                    = 4
  421. ; COLOR_MENUHILIGHT             = 29
  422. ; COLOR_MENUBAR                 = 30
  423. ; COLOR_MENUTEXT                = 7
  424. ; COLOR_SCROLLBAR               = 0
  425. ; COLOR_WINDOW                  = 5
  426. ; COLOR_WINDOWFRAME             = 6
  427. ; COLOR_WINDOWTEXT              = 8
  428.  
  429. SetSysColorToControl(hwnd, SysColor=15)
  430. {
  431.    WinGetPos,,, w, h, ahk_id %hwnd%
  432.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  433.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  434.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  435.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  436.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  437.    SetImage(hwnd, hBitmap)
  438.    Gdip_DeleteBrush(pBrushClear)
  439.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  440.    return 0
  441. }
  442.  
  443. ;#####################################################################################
  444.  
  445. ; Function              Gdip_BitmapFromScreen
  446. ; Description           Gets a gdi+ bitmap from the screen
  447. ;
  448. ; Screen                0 = All screens
  449. ;                       Any numerical value = Just that screen
  450. ;                       x|y|w|h = Take specific coordinates with a width and height
  451. ; Raster                raster operation code
  452. ;
  453. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  454. ;                       -1:     one or more of x,y,w,h not passed properly
  455. ;
  456. ; notes                 If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  457.  
  458. Gdip_BitmapFromScreen(Screen=0, Raster="")
  459. {
  460.     if (Screen = 0)
  461.     {
  462.         Sysget, x, 76
  463.         Sysget, y, 77  
  464.         Sysget, w, 78
  465.         Sysget, h, 79
  466.     }
  467.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  468.     {
  469.         Screen := SubStr(Screen, 6)
  470.         if !WinExist( "ahk_id " Screen)
  471.             return -2
  472.         WinGetPos,,, w, h, ahk_id %Screen%
  473.         x := y := 0
  474.         hhdc := GetDCEx(Screen, 3)
  475.     }
  476.     else if (Screen&1 != "")
  477.     {
  478.         Sysget, M, Monitor, %Screen%
  479.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  480.     }
  481.     else
  482.     {
  483.         StringSplit, S, Screen, |
  484.         x := S1, y := S2, w := S3, h := S4
  485.     }
  486.  
  487.     if (x = "") || (y = "") || (w = "") || (h = "")
  488.         return -1
  489.  
  490.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  491.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  492.     ReleaseDC(hhdc)
  493.    
  494.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  495.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  496.     return pBitmap
  497. }
  498.  
  499. ;#####################################################################################
  500.  
  501. ; Function              Gdip_BitmapFromHWND
  502. ; Description           Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  503. ;
  504. ; hwnd                  handle to the window to get a bitmap from
  505. ;
  506. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  507. ;
  508. ; notes                 Window must not be not minimised in order to get a handle to it's client area
  509.  
  510. Gdip_BitmapFromHWND(hwnd)
  511. {
  512.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  513.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  514.     PrintWindow(hwnd, hdc)
  515.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  516.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  517.     return pBitmap
  518. }
  519.  
  520. ;#####################################################################################
  521.  
  522. ; Function              CreateRectF
  523. ; Description           Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  524. ;
  525. ; RectF                 Name to call the RectF object
  526. ; x                     x-coordinate of the upper left corner of the rectangle
  527. ; y                     y-coordinate of the upper left corner of the rectangle
  528. ; w                     Width of the rectangle
  529. ; h                     Height of the rectangle
  530. ;
  531. ; return                No return value
  532.  
  533. CreateRectF(ByRef RectF, x, y, w, h)
  534. {
  535.    VarSetCapacity(RectF, 16)
  536.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  537. }
  538.  
  539. ;#####################################################################################
  540.  
  541. ; Function              CreateRect
  542. ; Description           Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  543. ;
  544. ; RectF                 Name to call the RectF object
  545. ; x                     x-coordinate of the upper left corner of the rectangle
  546. ; y                     y-coordinate of the upper left corner of the rectangle
  547. ; w                     Width of the rectangle
  548. ; h                     Height of the rectangle
  549. ;
  550. ; return                No return value
  551.  
  552. CreateRect(ByRef Rect, x, y, w, h)
  553. {
  554.     VarSetCapacity(Rect, 16)
  555.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  556. }
  557. ;#####################################################################################
  558.  
  559. ; Function              CreateSizeF
  560. ; Description           Creates a SizeF object, containing an 2 values
  561. ;
  562. ; SizeF                 Name to call the SizeF object
  563. ; w                     w-value for the SizeF object
  564. ; h                     h-value for the SizeF object
  565. ;
  566. ; return                No Return value
  567.  
  568. CreateSizeF(ByRef SizeF, w, h)
  569. {
  570.    VarSetCapacity(SizeF, 8)
  571.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  572. }
  573. ;#####################################################################################
  574.  
  575. ; Function              CreatePointF
  576. ; Description           Creates a SizeF object, containing an 2 values
  577. ;
  578. ; SizeF                 Name to call the SizeF object
  579. ; w                     w-value for the SizeF object
  580. ; h                     h-value for the SizeF object
  581. ;
  582. ; return                No Return value
  583.  
  584. CreatePointF(ByRef PointF, x, y)
  585. {
  586.    VarSetCapacity(PointF, 8)
  587.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  588. }
  589. ;#####################################################################################
  590.  
  591. ; Function              CreateDIBSection
  592. ; Description           The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  593. ;
  594. ; w                     width of the bitmap to create
  595. ; h                     height of the bitmap to create
  596. ; hdc                   a handle to the device context to use the palette from
  597. ; bpp                   bits per pixel (32 = ARGB)
  598. ; ppvBits               A pointer to a variable that receives a pointer to the location of the DIB bit values
  599. ;
  600. ; return                returns a DIB. A gdi bitmap
  601. ;
  602. ; notes                 ppvBits will receive the location of the pixels in the DIB
  603.  
  604. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  605. {
  606.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  607.    
  608.     hdc2 := hdc ? hdc : GetDC()
  609.     VarSetCapacity(bi, 40, 0)
  610.    
  611.     NumPut(w, bi, 4, "uint")
  612.     , NumPut(h, bi, 8, "uint")
  613.     , NumPut(40, bi, 0, "uint")
  614.     , NumPut(1, bi, 12, "ushort")
  615.     , NumPut(0, bi, 16, "uInt")
  616.     , NumPut(bpp, bi, 14, "ushort")
  617.    
  618.     hbm := DllCall("CreateDIBSection"
  619.                     , Ptr, hdc2
  620.                     , Ptr, &bi
  621.                     , "uint", 0
  622.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  623.                     , Ptr, 0
  624.                     , "uint", 0, Ptr)
  625.  
  626.     if !hdc
  627.         ReleaseDC(hdc2)
  628.     return hbm
  629. }
  630.  
  631. ;#####################################################################################
  632.  
  633. ; Function              PrintWindow
  634. ; Description           The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  635. ;
  636. ; hwnd                  A handle to the window that will be copied
  637. ; hdc                   A handle to the device context
  638. ; Flags                 Drawing options
  639. ;
  640. ; return                If the function succeeds, it returns a nonzero value
  641. ;
  642. ; PW_CLIENTONLY         = 1
  643.  
  644. PrintWindow(hwnd, hdc, Flags=0)
  645. {
  646.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  647.    
  648.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  649. }
  650.  
  651. ;#####################################################################################
  652.  
  653. ; Function              DestroyIcon
  654. ; Description           Destroys an icon and frees any memory the icon occupied
  655. ;
  656. ; hIcon                 Handle to the icon to be destroyed. The icon must not be in use
  657. ;
  658. ; return                If the function succeeds, the return value is nonzero
  659.  
  660. DestroyIcon(hIcon)
  661. {
  662.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  663. }
  664.  
  665. ;#####################################################################################
  666.  
  667. PaintDesktop(hdc)
  668. {
  669.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  670. }
  671.  
  672. ;#####################################################################################
  673.  
  674. CreateCompatibleBitmap(hdc, w, h)
  675. {
  676.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  677. }
  678.  
  679. ;#####################################################################################
  680.  
  681. ; Function              CreateCompatibleDC
  682. ; Description           This function creates a memory device context (DC) compatible with the specified device
  683. ;
  684. ; hdc                   Handle to an existing device context                   
  685. ;
  686. ; return                returns the handle to a device context or 0 on failure
  687. ;
  688. ; notes                 If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  689.  
  690. CreateCompatibleDC(hdc=0)
  691. {
  692.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  693. }
  694.  
  695. ;#####################################################################################
  696.  
  697. ; Function              SelectObject
  698. ; Description           The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  699. ;
  700. ; hdc                   Handle to a DC
  701. ; hgdiobj               A handle to the object to be selected into the DC
  702. ;
  703. ; return                If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  704. ;
  705. ; notes                 The specified object must have been created by using one of the following functions
  706. ;                       Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  707. ;                       Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  708. ;                       Font - CreateFont, CreateFontIndirect
  709. ;                       Pen - CreatePen, CreatePenIndirect
  710. ;                       Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  711. ;
  712. ; notes                 If the selected object is a region and the function succeeds, the return value is one of the following value
  713. ;
  714. ; SIMPLEREGION          = 2 Region consists of a single rectangle
  715. ; COMPLEXREGION         = 3 Region consists of more than one rectangle
  716. ; NULLREGION            = 1 Region is empty
  717.  
  718. SelectObject(hdc, hgdiobj)
  719. {
  720.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  721.    
  722.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  723. }
  724.  
  725. ;#####################################################################################
  726.  
  727. ; Function              DeleteObject
  728. ; Description           This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  729. ;                       After the object is deleted, the specified handle is no longer valid
  730. ;
  731. ; hObject               Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  732. ;
  733. ; return                Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  734.  
  735. DeleteObject(hObject)
  736. {
  737.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  738. }
  739.  
  740. ;#####################################################################################
  741.  
  742. ; Function              GetDC
  743. ; Description           This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  744. ;                       The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  745. ;
  746. ; 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                  
  747. ;
  748. ; return                The handle the device context for the specified window's client area indicates success. NULL indicates failure
  749.  
  750. GetDC(hwnd=0)
  751. {
  752.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  753. }
  754.  
  755. ;#####################################################################################
  756.  
  757. ; DCX_CACHE = 0x2
  758. ; DCX_CLIPCHILDREN = 0x8
  759. ; DCX_CLIPSIBLINGS = 0x10
  760. ; DCX_EXCLUDERGN = 0x40
  761. ; DCX_EXCLUDEUPDATE = 0x100
  762. ; DCX_INTERSECTRGN = 0x80
  763. ; DCX_INTERSECTUPDATE = 0x200
  764. ; DCX_LOCKWINDOWUPDATE = 0x400
  765. ; DCX_NORECOMPUTE = 0x100000
  766. ; DCX_NORESETATTRS = 0x4
  767. ; DCX_PARENTCLIP = 0x20
  768. ; DCX_VALIDATE = 0x200000
  769. ; DCX_WINDOW = 0x1
  770.  
  771. GetDCEx(hwnd, flags=0, hrgnClip=0)
  772. {
  773.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  774.    
  775.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  776. }
  777.  
  778. ;#####################################################################################
  779.  
  780. ; Function              ReleaseDC
  781. ; 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
  782. ;
  783. ; hdc                   Handle to the device context to be released
  784. ; hwnd                  Handle to the window whose device context is to be released
  785. ;
  786. ; return                1 = released
  787. ;                       0 = not released
  788. ;
  789. ; 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
  790. ;                       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.
  791.  
  792. ReleaseDC(hdc, hwnd=0)
  793. {
  794.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  795.    
  796.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  797. }
  798.  
  799. ;#####################################################################################
  800.  
  801. ; Function              DeleteDC
  802. ; Description           The DeleteDC function deletes the specified device context (DC)
  803. ;
  804. ; hdc                   A handle to the device context
  805. ;
  806. ; return                If the function succeeds, the return value is nonzero
  807. ;
  808. ; 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
  809.  
  810. DeleteDC(hdc)
  811. {
  812.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  813. }
  814. ;#####################################################################################
  815.  
  816. ; Function              Gdip_LibraryVersion
  817. ; Description           Get the current library version
  818. ;
  819. ; return                the library version
  820. ;
  821. ; notes                 This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  822.  
  823. Gdip_LibraryVersion()
  824. {
  825.     return 1.45
  826. }
  827.  
  828. ;#####################################################################################
  829.  
  830. ; Function              Gdip_LibrarySubVersion
  831. ; Description           Get the current library sub version
  832. ;
  833. ; return                the library sub version
  834. ;
  835. ; notes                 This is the sub-version currently maintained by Rseding91
  836. Gdip_LibrarySubVersion()
  837. {
  838.     return 1.47
  839. }
  840.  
  841. ;#####################################################################################
  842.  
  843. ; Function:             Gdip_BitmapFromBRA
  844. ; Description:          Gets a pointer to a gdi+ bitmap from a BRA file
  845. ;
  846. ; BRAFromMemIn          The variable for a BRA file read to memory
  847. ; File                  The name of the file, or its number that you would like (This depends on alternate parameter)
  848. ; Alternate             Changes whether the File parameter is the file name or its number
  849. ;
  850. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  851. ;                       -1 = The BRA variable is empty
  852. ;                       -2 = The BRA has an incorrect header
  853. ;                       -3 = The BRA has information missing
  854. ;                       -4 = Could not find file inside the BRA
  855.  
  856. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  857. {
  858.     Static FName = "ObjRelease"
  859.    
  860.     if !BRAFromMemIn
  861.         return -1
  862.     Loop, Parse, BRAFromMemIn, `n
  863.     {
  864.         if (A_Index = 1)
  865.         {
  866.             StringSplit, Header, A_LoopField, |
  867.             if (Header0 != 4 || Header2 != "BRA!")
  868.                 return -2
  869.         }
  870.         else if (A_Index = 2)
  871.         {
  872.             StringSplit, Info, A_LoopField, |
  873.             if (Info0 != 3)
  874.                 return -3
  875.         }
  876.         else
  877.             break
  878.     }
  879.     if !Alternate
  880.         StringReplace, File, File, \, \\, All
  881.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  882.     if !FileInfo
  883.         return -4
  884.    
  885.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  886.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  887.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  888.     DllCall("GlobalUnlock", Ptr, hData)
  889.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  890.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  891.     If (A_PtrSize)
  892.         %FName%(pStream)
  893.     Else
  894.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  895.     return pBitmap
  896. }
  897.  
  898. ;#####################################################################################
  899.  
  900. ; Function              Gdip_DrawRectangle
  901. ; Description           This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  902. ;
  903. ; pGraphics             Pointer to the Graphics of a bitmap
  904. ; pPen                  Pointer to a pen
  905. ; x                     x-coordinate of the top left of the rectangle
  906. ; y                     y-coordinate of the top left of the rectangle
  907. ; w                     width of the rectanlge
  908. ; h                     height of the rectangle
  909. ;
  910. ; return                status enumeration. 0 = success
  911. ;
  912. ; 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
  913.  
  914. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  915. {
  916.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  917.    
  918.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  919. }
  920.  
  921. ;#####################################################################################
  922.  
  923. ; Function              Gdip_DrawRoundedRectangle
  924. ; Description           This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  925. ;
  926. ; pGraphics             Pointer to the Graphics of a bitmap
  927. ; pPen                  Pointer to a pen
  928. ; x                     x-coordinate of the top left of the rounded rectangle
  929. ; y                     y-coordinate of the top left of the rounded rectangle
  930. ; w                     width of the rectanlge
  931. ; h                     height of the rectangle
  932. ; r                     radius of the rounded corners
  933. ;
  934. ; return                status enumeration. 0 = success
  935. ;
  936. ; 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
  937.  
  938. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  939. {
  940.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  941.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  942.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  943.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  944.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  945.     Gdip_ResetClip(pGraphics)
  946.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  947.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  948.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  949.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  950.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  951.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  952.     Gdip_ResetClip(pGraphics)
  953.     return E
  954. }
  955.  
  956. ;#####################################################################################
  957.  
  958. ; Function              Gdip_DrawEllipse
  959. ; Description           This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  960. ;
  961. ; pGraphics             Pointer to the Graphics of a bitmap
  962. ; pPen                  Pointer to a pen
  963. ; x                     x-coordinate of the top left of the rectangle the ellipse will be drawn into
  964. ; y                     y-coordinate of the top left of the rectangle the ellipse will be drawn into
  965. ; w                     width of the ellipse
  966. ; h                     height of the ellipse
  967. ;
  968. ; return                status enumeration. 0 = success
  969. ;
  970. ; 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
  971.  
  972. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  973. {
  974.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  975.    
  976.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  977. }
  978.  
  979. ;#####################################################################################
  980.  
  981. ; Function              Gdip_DrawBezier
  982. ; Description           This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  983. ;
  984. ; pGraphics             Pointer to the Graphics of a bitmap
  985. ; pPen                  Pointer to a pen
  986. ; x1                    x-coordinate of the start of the bezier
  987. ; y1                    y-coordinate of the start of the bezier
  988. ; x2                    x-coordinate of the first arc of the bezier
  989. ; y2                    y-coordinate of the first arc of the bezier
  990. ; x3                    x-coordinate of the second arc of the bezier
  991. ; y3                    y-coordinate of the second arc of the bezier
  992. ; x4                    x-coordinate of the end of the bezier
  993. ; y4                    y-coordinate of the end of the bezier
  994. ;
  995. ; return                status enumeration. 0 = success
  996. ;
  997. ; 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
  998.  
  999. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  1000. {
  1001.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1002.    
  1003.     return DllCall("gdiplus\GdipDrawBezier"
  1004.                     , Ptr, pgraphics
  1005.                     , Ptr, pPen
  1006.                     , "float", x1
  1007.                     , "float", y1
  1008.                     , "float", x2
  1009.                     , "float", y2
  1010.                     , "float", x3
  1011.                     , "float", y3
  1012.                     , "float", x4
  1013.                     , "float", y4)
  1014. }
  1015.  
  1016. ;#####################################################################################
  1017.  
  1018. ; Function              Gdip_DrawArc
  1019. ; Description           This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1020. ;
  1021. ; pGraphics             Pointer to the Graphics of a bitmap
  1022. ; pPen                  Pointer to a pen
  1023. ; x                     x-coordinate of the start of the arc
  1024. ; y                     y-coordinate of the start of the arc
  1025. ; w                     width of the arc
  1026. ; h                     height of the arc
  1027. ; StartAngle            specifies the angle between the x-axis and the starting point of the arc
  1028. ; SweepAngle            specifies the angle between the starting and ending points of the arc
  1029. ;
  1030. ; return                status enumeration. 0 = success
  1031. ;
  1032. ; 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
  1033.  
  1034. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1035. {
  1036.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1037.    
  1038.     return DllCall("gdiplus\GdipDrawArc"
  1039.                     , Ptr, pGraphics
  1040.                     , Ptr, pPen
  1041.                     , "float", x
  1042.                     , "float", y
  1043.                     , "float", w
  1044.                     , "float", h
  1045.                     , "float", StartAngle
  1046.                     , "float", SweepAngle)
  1047. }
  1048.  
  1049. ;#####################################################################################
  1050.  
  1051. ; Function              Gdip_DrawPie
  1052. ; Description           This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1053. ;
  1054. ; pGraphics             Pointer to the Graphics of a bitmap
  1055. ; pPen                  Pointer to a pen
  1056. ; x                     x-coordinate of the start of the pie
  1057. ; y                     y-coordinate of the start of the pie
  1058. ; w                     width of the pie
  1059. ; h                     height of the pie
  1060. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1061. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1062. ;
  1063. ; return                status enumeration. 0 = success
  1064. ;
  1065. ; 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
  1066.  
  1067. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1068. {
  1069.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1070.    
  1071.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1072. }
  1073.  
  1074. ;#####################################################################################
  1075.  
  1076. ; Function              Gdip_DrawLine
  1077. ; Description           This function uses a pen to draw a line into the Graphics of a bitmap
  1078. ;
  1079. ; pGraphics             Pointer to the Graphics of a bitmap
  1080. ; pPen                  Pointer to a pen
  1081. ; x1                    x-coordinate of the start of the line
  1082. ; y1                    y-coordinate of the start of the line
  1083. ; x2                    x-coordinate of the end of the line
  1084. ; y2                    y-coordinate of the end of the line
  1085. ;
  1086. ; return                status enumeration. 0 = success    
  1087.  
  1088. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1089. {
  1090.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1091.    
  1092.     return DllCall("gdiplus\GdipDrawLine"
  1093.                     , Ptr, pGraphics
  1094.                     , Ptr, pPen
  1095.                     , "float", x1
  1096.                     , "float", y1
  1097.                     , "float", x2
  1098.                     , "float", y2)
  1099. }
  1100.  
  1101. ;#####################################################################################
  1102.  
  1103. ; Function              Gdip_DrawLines
  1104. ; Description           This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1105. ;
  1106. ; pGraphics             Pointer to the Graphics of a bitmap
  1107. ; pPen                  Pointer to a pen
  1108. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1109. ;
  1110. ; return                status enumeration. 0 = success            
  1111.  
  1112. Gdip_DrawLines(pGraphics, pPen, Points)
  1113. {
  1114.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1115.     StringSplit, Points, Points, |
  1116.     VarSetCapacity(PointF, 8*Points0)  
  1117.     Loop, %Points0%
  1118.     {
  1119.         StringSplit, Coord, Points%A_Index%, `,
  1120.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1121.     }
  1122.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  1123. }
  1124.  
  1125. ;#####################################################################################
  1126.  
  1127. ; Function              Gdip_FillRectangle
  1128. ; Description           This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1129. ;
  1130. ; pGraphics             Pointer to the Graphics of a bitmap
  1131. ; pBrush                Pointer to a brush
  1132. ; x                     x-coordinate of the top left of the rectangle
  1133. ; y                     y-coordinate of the top left of the rectangle
  1134. ; w                     width of the rectanlge
  1135. ; h                     height of the rectangle
  1136. ;
  1137. ; return                status enumeration. 0 = success
  1138.  
  1139. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1140. {
  1141.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1142.    
  1143.     return DllCall("gdiplus\GdipFillRectangle"
  1144.                     , Ptr, pGraphics
  1145.                     , Ptr, pBrush
  1146.                     , "float", x
  1147.                     , "float", y
  1148.                     , "float", w
  1149.                     , "float", h)
  1150. }
  1151.  
  1152. ;#####################################################################################
  1153.  
  1154. ; Function              Gdip_FillRoundedRectangle
  1155. ; Description           This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1156. ;
  1157. ; pGraphics             Pointer to the Graphics of a bitmap
  1158. ; pBrush                Pointer to a brush
  1159. ; x                     x-coordinate of the top left of the rounded rectangle
  1160. ; y                     y-coordinate of the top left of the rounded rectangle
  1161. ; w                     width of the rectanlge
  1162. ; h                     height of the rectangle
  1163. ; r                     radius of the rounded corners
  1164. ;
  1165. ; return                status enumeration. 0 = success
  1166.  
  1167. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1168. {
  1169.     Region := Gdip_GetClipRegion(pGraphics)
  1170.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1171.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1172.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1173.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1174.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1175.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1176.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1177.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1178.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1179.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1180.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1181.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1182.     Gdip_SetClipRegion(pGraphics, Region, 0)
  1183.     Gdip_DeleteRegion(Region)
  1184.     return E
  1185. }
  1186.  
  1187. ;#####################################################################################
  1188.  
  1189. ; Function              Gdip_FillPolygon
  1190. ; Description           This function uses a brush to fill a polygon in the Graphics of a bitmap
  1191. ;
  1192. ; pGraphics             Pointer to the Graphics of a bitmap
  1193. ; pBrush                Pointer to a brush
  1194. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1195. ;
  1196. ; return                status enumeration. 0 = success
  1197. ;
  1198. ; notes                 Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1199. ; Alternate             = 0
  1200. ; Winding               = 1
  1201.  
  1202. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1203. {
  1204.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1205.    
  1206.     StringSplit, Points, Points, |
  1207.     VarSetCapacity(PointF, 8*Points0)  
  1208.     Loop, %Points0%
  1209.     {
  1210.         StringSplit, Coord, Points%A_Index%, `,
  1211.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1212.     }  
  1213.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  1214. }
  1215.  
  1216. ;#####################################################################################
  1217.  
  1218. ; Function              Gdip_FillPie
  1219. ; Description           This function uses a brush to fill a pie in the Graphics of a bitmap
  1220. ;
  1221. ; pGraphics             Pointer to the Graphics of a bitmap
  1222. ; pBrush                Pointer to a brush
  1223. ; x                     x-coordinate of the top left of the pie
  1224. ; y                     y-coordinate of the top left of the pie
  1225. ; w                     width of the pie
  1226. ; h                     height of the pie
  1227. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  1228. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  1229. ;
  1230. ; return                status enumeration. 0 = success
  1231.  
  1232. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1233. {
  1234.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1235.    
  1236.     return DllCall("gdiplus\GdipFillPie"
  1237.                     , Ptr, pGraphics
  1238.                     , Ptr, pBrush
  1239.                     , "float", x
  1240.                     , "float", y
  1241.                     , "float", w
  1242.                     , "float", h
  1243.                     , "float", StartAngle
  1244.                     , "float", SweepAngle)
  1245. }
  1246.  
  1247. ;#####################################################################################
  1248.  
  1249. ; Function              Gdip_FillEllipse
  1250. ; Description           This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1251. ;
  1252. ; pGraphics             Pointer to the Graphics of a bitmap
  1253. ; pBrush                Pointer to a brush
  1254. ; x                     x-coordinate of the top left of the ellipse
  1255. ; y                     y-coordinate of the top left of the ellipse
  1256. ; w                     width of the ellipse
  1257. ; h                     height of the ellipse
  1258. ;
  1259. ; return                status enumeration. 0 = success
  1260.  
  1261. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1262. {
  1263.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1264.    
  1265.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  1266. }
  1267.  
  1268. ;#####################################################################################
  1269.  
  1270. ; Function              Gdip_FillRegion
  1271. ; Description           This function uses a brush to fill a region in the Graphics of a bitmap
  1272. ;
  1273. ; pGraphics             Pointer to the Graphics of a bitmap
  1274. ; pBrush                Pointer to a brush
  1275. ; Region                Pointer to a Region
  1276. ;
  1277. ; return                status enumeration. 0 = success
  1278. ;
  1279. ; notes                 You can create a region Gdip_CreateRegion() and then add to this
  1280.  
  1281. Gdip_FillRegion(pGraphics, pBrush, Region)
  1282. {
  1283.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1284.    
  1285.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  1286. }
  1287.  
  1288. ;#####################################################################################
  1289.  
  1290. ; Function              Gdip_FillPath
  1291. ; Description           This function uses a brush to fill a path in the Graphics of a bitmap
  1292. ;
  1293. ; pGraphics             Pointer to the Graphics of a bitmap
  1294. ; pBrush                Pointer to a brush
  1295. ; Region                Pointer to a Path
  1296. ;
  1297. ; return                status enumeration. 0 = success
  1298.  
  1299. Gdip_FillPath(pGraphics, pBrush, Path)
  1300. {
  1301.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1302.    
  1303.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  1304. }
  1305.  
  1306. ;#####################################################################################
  1307.  
  1308. ; Function              Gdip_DrawImagePointsRect
  1309. ; Description           This function draws a bitmap into the Graphics of another bitmap and skews it
  1310. ;
  1311. ; pGraphics             Pointer to the Graphics of a bitmap
  1312. ; pBitmap               Pointer to a bitmap to be drawn
  1313. ; Points                Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1314. ; sx                    x-coordinate of source upper-left corner
  1315. ; sy                    y-coordinate of source upper-left corner
  1316. ; sw                    width of source rectangle
  1317. ; sh                    height of source rectangle
  1318. ; Matrix                a matrix used to alter image attributes when drawing
  1319. ;
  1320. ; return                status enumeration. 0 = success
  1321. ;
  1322. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1323. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1324. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1325. ;                       Matrix can be passed as a matrix with any delimiter
  1326.  
  1327. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1328. {
  1329.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1330.    
  1331.     StringSplit, Points, Points, |
  1332.     VarSetCapacity(PointF, 8*Points0)  
  1333.     Loop, %Points0%
  1334.     {
  1335.         StringSplit, Coord, Points%A_Index%, `,
  1336.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1337.     }
  1338.  
  1339.     if (Matrix&1 = "")
  1340.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1341.     else if (Matrix != 1)
  1342.         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")
  1343.        
  1344.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1345.     {
  1346.         sx := 0, sy := 0
  1347.         sw := Gdip_GetImageWidth(pBitmap)
  1348.         sh := Gdip_GetImageHeight(pBitmap)
  1349.     }
  1350.  
  1351.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  1352.                 , Ptr, pGraphics
  1353.                 , Ptr, pBitmap
  1354.                 , Ptr, &PointF
  1355.                 , "int", Points0
  1356.                 , "float", sx
  1357.                 , "float", sy
  1358.                 , "float", sw
  1359.                 , "float", sh
  1360.                 , "int", 2
  1361.                 , Ptr, ImageAttr
  1362.                 , Ptr, 0
  1363.                 , Ptr, 0)
  1364.     if ImageAttr
  1365.         Gdip_DisposeImageAttributes(ImageAttr)
  1366.     return E
  1367. }
  1368.  
  1369. ;#####################################################################################
  1370.  
  1371. ; Function              Gdip_DrawImage
  1372. ; Description           This function draws a bitmap into the Graphics of another bitmap
  1373. ;
  1374. ; pGraphics             Pointer to the Graphics of a bitmap
  1375. ; pBitmap               Pointer to a bitmap to be drawn
  1376. ; dx                    x-coord of destination upper-left corner
  1377. ; dy                    y-coord of destination upper-left corner
  1378. ; dw                    width of destination image
  1379. ; dh                    height of destination image
  1380. ; sx                    x-coordinate of source upper-left corner
  1381. ; sy                    y-coordinate of source upper-left corner
  1382. ; sw                    width of source image
  1383. ; sh                    height of source image
  1384. ; Matrix                a matrix used to alter image attributes when drawing
  1385. ;
  1386. ; return                status enumeration. 0 = success
  1387. ;
  1388. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1389. ;                       Gdip_DrawImage performs faster
  1390. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  1391. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  1392. ;                       Matrix can be passed as a matrix with any delimiter. For example:
  1393. ;                       MatrixBright=
  1394. ;                       (
  1395. ;                       1.5     |0      |0      |0      |0
  1396. ;                       0       |1.5    |0      |0      |0
  1397. ;                       0       |0      |1.5    |0      |0
  1398. ;                       0       |0      |0      |1      |0
  1399. ;                       0.05    |0.05   |0.05   |0      |1
  1400. ;                       )
  1401. ;
  1402. ; 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
  1403. ;                       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
  1404. ;                       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
  1405.  
  1406. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1407. {
  1408.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1409.    
  1410.     if (Matrix&1 = "")
  1411.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1412.     else if (Matrix != 1)
  1413.         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")
  1414.  
  1415.     if (sx = "" && sy = "" && sw = "" && sh = "")
  1416.     {
  1417.         if (dx = "" && dy = "" && dw = "" && dh = "")
  1418.         {
  1419.             sx := dx := 0, sy := dy := 0
  1420.             sw := dw := Gdip_GetImageWidth(pBitmap)
  1421.             sh := dh := Gdip_GetImageHeight(pBitmap)
  1422.         }
  1423.         else
  1424.         {
  1425.             sx := sy := 0
  1426.             sw := Gdip_GetImageWidth(pBitmap)
  1427.             sh := Gdip_GetImageHeight(pBitmap)
  1428.         }
  1429.     }
  1430.  
  1431.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  1432.                 , Ptr, pGraphics
  1433.                 , Ptr, pBitmap
  1434.                 , "float", dx
  1435.                 , "float", dy
  1436.                 , "float", dw
  1437.                 , "float", dh
  1438.                 , "float", sx
  1439.                 , "float", sy
  1440.                 , "float", sw
  1441.                 , "float", sh
  1442.                 , "int", 2
  1443.                 , Ptr, ImageAttr
  1444.                 , Ptr, 0
  1445.                 , Ptr, 0)
  1446.     if ImageAttr
  1447.         Gdip_DisposeImageAttributes(ImageAttr)
  1448.     return E
  1449. }
  1450.  
  1451. ;#####################################################################################
  1452.  
  1453. ; Function              Gdip_SetImageAttributesColorMatrix
  1454. ; Description           This function creates an image matrix ready for drawing
  1455. ;
  1456. ; Matrix                a matrix used to alter image attributes when drawing
  1457. ;                       passed with any delimeter
  1458. ;
  1459. ; return                returns an image matrix on sucess or 0 if it fails
  1460. ;
  1461. ; 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
  1462. ;                       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
  1463. ;                       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
  1464.  
  1465. Gdip_SetImageAttributesColorMatrix(Matrix)
  1466. {
  1467.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1468.    
  1469.     VarSetCapacity(ColourMatrix, 100, 0)
  1470.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1471.     StringSplit, Matrix, Matrix, |
  1472.     Loop, 25
  1473.     {
  1474.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1475.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1476.     }
  1477.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  1478.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  1479.     return ImageAttr
  1480. }
  1481.  
  1482. ;#####################################################################################
  1483.  
  1484. ; Function              Gdip_GraphicsFromImage
  1485. ; Description           This function gets the graphics for a bitmap used for drawing functions
  1486. ;
  1487. ; pBitmap               Pointer to a bitmap to get the pointer to its graphics
  1488. ;
  1489. ; return                returns a pointer to the graphics of a bitmap
  1490. ;
  1491. ; notes                 a bitmap can be drawn into the graphics of another bitmap
  1492.  
  1493. Gdip_GraphicsFromImage(pBitmap)
  1494. {
  1495.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1496.     return pGraphics
  1497. }
  1498.  
  1499. ;#####################################################################################
  1500.  
  1501. ; Function              Gdip_GraphicsFromHDC
  1502. ; Description           This function gets the graphics from the handle to a device context
  1503. ;
  1504. ; hdc                   This is the handle to the device context
  1505. ;
  1506. ; return                returns a pointer to the graphics of a bitmap
  1507. ;
  1508. ; notes                 You can draw a bitmap into the graphics of another bitmap
  1509.  
  1510. Gdip_GraphicsFromHDC(hdc)
  1511. {
  1512.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  1513.     return pGraphics
  1514. }
  1515.  
  1516. ;#####################################################################################
  1517.  
  1518. ; Function              Gdip_GetDC
  1519. ; Description           This function gets the device context of the passed Graphics
  1520. ;
  1521. ; hdc                   This is the handle to the device context
  1522. ;
  1523. ; return                returns the device context for the graphics of a bitmap
  1524.  
  1525. Gdip_GetDC(pGraphics)
  1526. {
  1527.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  1528.     return hdc
  1529. }
  1530.  
  1531. ;#####################################################################################
  1532.  
  1533. ; Function              Gdip_ReleaseDC
  1534. ; Description           This function releases a device context from use for further use
  1535. ;
  1536. ; pGraphics             Pointer to the graphics of a bitmap
  1537. ; hdc                   This is the handle to the device context
  1538. ;
  1539. ; return                status enumeration. 0 = success
  1540.  
  1541. Gdip_ReleaseDC(pGraphics, hdc)
  1542. {
  1543.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1544.    
  1545.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  1546. }
  1547.  
  1548. ;#####################################################################################
  1549.  
  1550. ; Function              Gdip_GraphicsClear
  1551. ; Description           Clears the graphics of a bitmap ready for further drawing
  1552. ;
  1553. ; pGraphics             Pointer to the graphics of a bitmap
  1554. ; ARGB                  The colour to clear the graphics to
  1555. ;
  1556. ; return                status enumeration. 0 = success
  1557. ;
  1558. ; notes                 By default this will make the background invisible
  1559. ;                       Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1560.  
  1561. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1562. {
  1563.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  1564. }
  1565.  
  1566. ;#####################################################################################
  1567.  
  1568. ; Function              Gdip_BlurBitmap
  1569. ; Description           Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1570. ;
  1571. ; pBitmap               Pointer to a bitmap to be blurred
  1572. ; Blur                  The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1573. ;
  1574. ; return                If the function succeeds, the return value is a pointer to the new blurred bitmap
  1575. ;                       -1 = The blur parameter is outside the range 1-100
  1576. ;
  1577. ; notes                 This function will not dispose of the original bitmap
  1578.  
  1579. Gdip_BlurBitmap(pBitmap, Blur)
  1580. {
  1581.     if (Blur > 100) || (Blur < 1)
  1582.         return -1  
  1583.    
  1584.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1585.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1586.  
  1587.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1588.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  1589.     Gdip_SetInterpolationMode(G1, 7)
  1590.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1591.  
  1592.     Gdip_DeleteGraphics(G1)
  1593.  
  1594.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1595.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  1596.     Gdip_SetInterpolationMode(G2, 7)
  1597.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1598.  
  1599.     Gdip_DeleteGraphics(G2)
  1600.     Gdip_DisposeImage(pBitmap1)
  1601.     return pBitmap2
  1602. }
  1603.  
  1604. ;#####################################################################################
  1605.  
  1606. ; Function:             Gdip_SaveBitmapToFile
  1607. ; Description:          Saves a bitmap to a file in any supported format onto disk
  1608. ;  
  1609. ; pBitmap               Pointer to a bitmap
  1610. ; 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
  1611. ; Quality               If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1612. ;
  1613. ; return                If the function succeeds, the return value is zero, otherwise:
  1614. ;                       -1 = Extension supplied is not a supported file format
  1615. ;                       -2 = Could not get a list of encoders on system
  1616. ;                       -3 = Could not find matching encoder for specified file format
  1617. ;                       -4 = Could not get WideChar name of output file
  1618. ;                       -5 = Could not save file to disk
  1619. ;
  1620. ; notes                 This function will use the extension supplied from the sOutput parameter to determine the output format
  1621.  
  1622. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  1623. {
  1624.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1625.    
  1626.     SplitPath, sOutput,,, Extension
  1627.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1628.         return -1
  1629.     Extension := "." Extension
  1630.  
  1631.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1632.     VarSetCapacity(ci, nSize)
  1633.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  1634.     if !(nCount && nSize)
  1635.         return -2
  1636.    
  1637.     If (A_IsUnicode){
  1638.         StrGet_Name := "StrGet"
  1639.         Loop, %nCount%
  1640.         {
  1641.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  1642.             if !InStr(sString, "*" Extension)
  1643.                 continue
  1644.            
  1645.             pCodec := &ci+idx
  1646.             break
  1647.         }
  1648.     } else {
  1649.         Loop, %nCount%
  1650.         {
  1651.             Location := NumGet(ci, 76*(A_Index-1)+44)
  1652.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1653.             VarSetCapacity(sString, nSize)
  1654.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1655.             if !InStr(sString, "*" Extension)
  1656.                 continue
  1657.            
  1658.             pCodec := &ci+76*(A_Index-1)
  1659.             break
  1660.         }
  1661.     }
  1662.    
  1663.     if !pCodec
  1664.         return -3
  1665.  
  1666.     if (Quality != 75)
  1667.     {
  1668.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1669.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  1670.         {
  1671.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  1672.             VarSetCapacity(EncoderParameters, nSize, 0)
  1673.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  1674.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  1675.             {
  1676.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  1677.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  1678.                 {
  1679.                     p := elem+&EncoderParameters-pad-4
  1680.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  1681.                     break
  1682.                 }
  1683.             }      
  1684.         }
  1685.     }
  1686.  
  1687.     if (!A_IsUnicode)
  1688.     {
  1689.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  1690.         VarSetCapacity(wOutput, nSize*2)
  1691.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  1692.         VarSetCapacity(wOutput, -1)
  1693.         if !VarSetCapacity(wOutput)
  1694.             return -4
  1695.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  1696.     }
  1697.     else
  1698.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  1699.     return E ? -5 : 0
  1700. }
  1701.  
  1702. ;#####################################################################################
  1703.  
  1704. ; Function              Gdip_GetPixel
  1705. ; Description           Gets the ARGB of a pixel in a bitmap
  1706. ;
  1707. ; pBitmap               Pointer to a bitmap
  1708. ; x                     x-coordinate of the pixel
  1709. ; y                     y-coordinate of the pixel
  1710. ;
  1711. ; return                Returns the ARGB value of the pixel
  1712.  
  1713. Gdip_GetPixel(pBitmap, x, y)
  1714. {
  1715.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1716.     return ARGB
  1717. }
  1718.  
  1719. ;#####################################################################################
  1720.  
  1721. ; Function              Gdip_SetPixel
  1722. ; Description           Sets the ARGB of a pixel in a bitmap
  1723. ;
  1724. ; pBitmap               Pointer to a bitmap
  1725. ; x                     x-coordinate of the pixel
  1726. ; y                     y-coordinate of the pixel
  1727. ;
  1728. ; return                status enumeration. 0 = success
  1729.  
  1730. Gdip_SetPixel(pBitmap, x, y, ARGB)
  1731. {
  1732.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  1733. }
  1734.  
  1735. ;#####################################################################################
  1736.  
  1737. ; Function              Gdip_GetImageWidth
  1738. ; Description           Gives the width of a bitmap
  1739. ;
  1740. ; pBitmap               Pointer to a bitmap
  1741. ;
  1742. ; return                Returns the width in pixels of the supplied bitmap
  1743.  
  1744. Gdip_GetImageWidth(pBitmap)
  1745. {
  1746.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  1747.    return Width
  1748. }
  1749.  
  1750. ;#####################################################################################
  1751.  
  1752. ; Function              Gdip_GetImageHeight
  1753. ; Description           Gives the height of a bitmap
  1754. ;
  1755. ; pBitmap               Pointer to a bitmap
  1756. ;
  1757. ; return                Returns the height in pixels of the supplied bitmap
  1758.  
  1759. Gdip_GetImageHeight(pBitmap)
  1760. {
  1761.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  1762.    return Height
  1763. }
  1764.  
  1765. ;#####################################################################################
  1766.  
  1767. ; Function              Gdip_GetDimensions
  1768. ; Description           Gives the width and height of a bitmap
  1769. ;
  1770. ; pBitmap               Pointer to a bitmap
  1771. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  1772. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  1773. ;
  1774. ; return                No return value
  1775. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1776.  
  1777. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  1778. {
  1779.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1780.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  1781.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  1782. }
  1783.  
  1784. ;#####################################################################################
  1785.  
  1786. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  1787. {
  1788.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  1789. }
  1790.  
  1791. ;#####################################################################################
  1792.  
  1793. Gdip_GetImagePixelFormat(pBitmap)
  1794. {
  1795.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  1796.     return Format
  1797. }
  1798.  
  1799. ;#####################################################################################
  1800.  
  1801. ; Function              Gdip_GetDpiX
  1802. ; Description           Gives the horizontal dots per inch of the graphics of a bitmap
  1803. ;
  1804. ; pBitmap               Pointer to a bitmap
  1805. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  1806. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  1807. ;
  1808. ; return                No return value
  1809. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1810.  
  1811. Gdip_GetDpiX(pGraphics)
  1812. {
  1813.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  1814.     return Round(dpix)
  1815. }
  1816.  
  1817. ;#####################################################################################
  1818.  
  1819. Gdip_GetDpiY(pGraphics)
  1820. {
  1821.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  1822.     return Round(dpiy)
  1823. }
  1824.  
  1825. ;#####################################################################################
  1826.  
  1827. Gdip_GetImageHorizontalResolution(pBitmap)
  1828. {
  1829.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  1830.     return Round(dpix)
  1831. }
  1832.  
  1833. ;#####################################################################################
  1834.  
  1835. Gdip_GetImageVerticalResolution(pBitmap)
  1836. {
  1837.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  1838.     return Round(dpiy)
  1839. }
  1840.  
  1841. ;#####################################################################################
  1842.  
  1843. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  1844. {
  1845.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  1846. }
  1847.  
  1848. ;#####################################################################################
  1849.  
  1850. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  1851. {
  1852.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1853.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  1854.    
  1855.     SplitPath, sFile,,, ext
  1856.     if ext in exe,dll
  1857.     {
  1858.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  1859.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  1860.        
  1861.         VarSetCapacity(buf, BufSize, 0)
  1862.         Loop, Parse, Sizes, |
  1863.         {
  1864.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  1865.            
  1866.             if !hIcon
  1867.                 continue
  1868.  
  1869.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  1870.             {
  1871.                 DestroyIcon(hIcon)
  1872.                 continue
  1873.             }
  1874.            
  1875.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  1876.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  1877.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  1878.             {
  1879.                 DestroyIcon(hIcon)
  1880.                 continue
  1881.             }
  1882.             break
  1883.         }
  1884.         if !hIcon
  1885.             return -1
  1886.  
  1887.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  1888.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  1889.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  1890.         {
  1891.             DestroyIcon(hIcon)
  1892.             return -2
  1893.         }
  1894.        
  1895.         VarSetCapacity(dib, 104)
  1896.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  1897.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  1898.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  1899.         pBitmap := Gdip_CreateBitmap(Width, Height)
  1900.         G := Gdip_GraphicsFromImage(pBitmap)
  1901.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  1902.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  1903.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  1904.         DestroyIcon(hIcon)
  1905.     }
  1906.     else
  1907.     {
  1908.         if (!A_IsUnicode)
  1909.         {
  1910.             VarSetCapacity(wFile, 1024)
  1911.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  1912.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  1913.         }
  1914.         else
  1915.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  1916.     }
  1917.    
  1918.     return pBitmap
  1919. }
  1920.  
  1921. ;#####################################################################################
  1922.  
  1923. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  1924. {
  1925.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1926.    
  1927.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1928.     return pBitmap
  1929. }
  1930.  
  1931. ;#####################################################################################
  1932.  
  1933. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  1934. {
  1935.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  1936.     return hbm
  1937. }
  1938.  
  1939. ;#####################################################################################
  1940.  
  1941. Gdip_CreateBitmapFromHICON(hIcon)
  1942. {
  1943.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1944.     return pBitmap
  1945. }
  1946.  
  1947. ;#####################################################################################
  1948.  
  1949. Gdip_CreateHICONFromBitmap(pBitmap)
  1950. {
  1951.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  1952.     return hIcon
  1953. }
  1954.  
  1955. ;#####################################################################################
  1956.  
  1957. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  1958. {
  1959.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  1960.     Return pBitmap
  1961. }
  1962.  
  1963. ;#####################################################################################
  1964.  
  1965. Gdip_CreateBitmapFromClipboard()
  1966. {
  1967.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1968.    
  1969.     if !DllCall("OpenClipboard", Ptr, 0)
  1970.         return -1
  1971.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  1972.         return -2
  1973.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  1974.         return -3
  1975.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  1976.         return -4
  1977.     if !DllCall("CloseClipboard")
  1978.         return -5
  1979.     DeleteObject(hBitmap)
  1980.     return pBitmap
  1981. }
  1982.  
  1983. ;#####################################################################################
  1984.  
  1985. Gdip_SetBitmapToClipboard(pBitmap)
  1986. {
  1987.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  1988.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  1989.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  1990.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  1991.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  1992.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  1993.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  1994.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  1995.     DllCall("GlobalUnlock", Ptr, hdib)
  1996.     DllCall("DeleteObject", Ptr, hBitmap)
  1997.     DllCall("OpenClipboard", Ptr, 0)
  1998.     DllCall("EmptyClipboard")
  1999.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  2000.     DllCall("CloseClipboard")
  2001. }
  2002.  
  2003. ;#####################################################################################
  2004.  
  2005. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  2006. {
  2007.     DllCall("gdiplus\GdipCloneBitmapArea"
  2008.                     , "float", x
  2009.                     , "float", y
  2010.                     , "float", w
  2011.                     , "float", h
  2012.                     , "int", Format
  2013.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  2014.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  2015.     return pBitmapDest
  2016. }
  2017.  
  2018. ;#####################################################################################
  2019. ; Create resources
  2020. ;#####################################################################################
  2021.  
  2022. Gdip_CreatePen(ARGB, w)
  2023. {
  2024.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2025.    return pPen
  2026. }
  2027.  
  2028. ;#####################################################################################
  2029.  
  2030. Gdip_CreatePenFromBrush(pBrush, w)
  2031. {
  2032.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  2033.     return pPen
  2034. }
  2035.  
  2036. ;#####################################################################################
  2037.  
  2038. Gdip_BrushCreateSolid(ARGB=0xff000000)
  2039. {
  2040.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2041.     return pBrush
  2042. }
  2043.  
  2044. ;#####################################################################################
  2045.  
  2046. ; HatchStyleHorizontal = 0
  2047. ; HatchStyleVertical = 1
  2048. ; HatchStyleForwardDiagonal = 2
  2049. ; HatchStyleBackwardDiagonal = 3
  2050. ; HatchStyleCross = 4
  2051. ; HatchStyleDiagonalCross = 5
  2052. ; HatchStyle05Percent = 6
  2053. ; HatchStyle10Percent = 7
  2054. ; HatchStyle20Percent = 8
  2055. ; HatchStyle25Percent = 9
  2056. ; HatchStyle30Percent = 10
  2057. ; HatchStyle40Percent = 11
  2058. ; HatchStyle50Percent = 12
  2059. ; HatchStyle60Percent = 13
  2060. ; HatchStyle70Percent = 14
  2061. ; HatchStyle75Percent = 15
  2062. ; HatchStyle80Percent = 16
  2063. ; HatchStyle90Percent = 17
  2064. ; HatchStyleLightDownwardDiagonal = 18
  2065. ; HatchStyleLightUpwardDiagonal = 19
  2066. ; HatchStyleDarkDownwardDiagonal = 20
  2067. ; HatchStyleDarkUpwardDiagonal = 21
  2068. ; HatchStyleWideDownwardDiagonal = 22
  2069. ; HatchStyleWideUpwardDiagonal = 23
  2070. ; HatchStyleLightVertical = 24
  2071. ; HatchStyleLightHorizontal = 25
  2072. ; HatchStyleNarrowVertical = 26
  2073. ; HatchStyleNarrowHorizontal = 27
  2074. ; HatchStyleDarkVertical = 28
  2075. ; HatchStyleDarkHorizontal = 29
  2076. ; HatchStyleDashedDownwardDiagonal = 30
  2077. ; HatchStyleDashedUpwardDiagonal = 31
  2078. ; HatchStyleDashedHorizontal = 32
  2079. ; HatchStyleDashedVertical = 33
  2080. ; HatchStyleSmallConfetti = 34
  2081. ; HatchStyleLargeConfetti = 35
  2082. ; HatchStyleZigZag = 36
  2083. ; HatchStyleWave = 37
  2084. ; HatchStyleDiagonalBrick = 38
  2085. ; HatchStyleHorizontalBrick = 39
  2086. ; HatchStyleWeave = 40
  2087. ; HatchStylePlaid = 41
  2088. ; HatchStyleDivot = 42
  2089. ; HatchStyleDottedGrid = 43
  2090. ; HatchStyleDottedDiamond = 44
  2091. ; HatchStyleShingle = 45
  2092. ; HatchStyleTrellis = 46
  2093. ; HatchStyleSphere = 47
  2094. ; HatchStyleSmallGrid = 48
  2095. ; HatchStyleSmallCheckerBoard = 49
  2096. ; HatchStyleLargeCheckerBoard = 50
  2097. ; HatchStyleOutlinedDiamond = 51
  2098. ; HatchStyleSolidDiamond = 52
  2099. ; HatchStyleTotal = 53
  2100. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  2101. {
  2102.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  2103.     return pBrush
  2104. }
  2105.  
  2106. ;#####################################################################################
  2107.  
  2108. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  2109. {
  2110.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2111.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  2112.    
  2113.     if !(w && h)
  2114.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  2115.     else
  2116.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  2117.     return pBrush
  2118. }
  2119.  
  2120. ;#####################################################################################
  2121.  
  2122. ; WrapModeTile = 0
  2123. ; WrapModeTileFlipX = 1
  2124. ; WrapModeTileFlipY = 2
  2125. ; WrapModeTileFlipXY = 3
  2126. ; WrapModeClamp = 4
  2127. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2128. {
  2129.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2130.    
  2131.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  2132.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2133.     return LGpBrush
  2134. }
  2135.  
  2136. ;#####################################################################################
  2137.  
  2138. ; LinearGradientModeHorizontal = 0
  2139. ; LinearGradientModeVertical = 1
  2140. ; LinearGradientModeForwardDiagonal = 2
  2141. ; LinearGradientModeBackwardDiagonal = 3
  2142. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2143. {
  2144.     CreateRectF(RectF, x, y, w, h)
  2145.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  2146.     return LGpBrush
  2147. }
  2148.  
  2149. ;#####################################################################################
  2150.  
  2151. Gdip_CloneBrush(pBrush)
  2152. {
  2153.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  2154.     return pBrushClone
  2155. }
  2156.  
  2157. ;#####################################################################################
  2158. ; Delete resources
  2159. ;#####################################################################################
  2160.  
  2161. Gdip_DeletePen(pPen)
  2162. {
  2163.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  2164. }
  2165.  
  2166. ;#####################################################################################
  2167.  
  2168. Gdip_DeleteBrush(pBrush)
  2169. {
  2170.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  2171. }
  2172.  
  2173. ;#####################################################################################
  2174.  
  2175. Gdip_DisposeImage(pBitmap)
  2176. {
  2177.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  2178. }
  2179.  
  2180. ;#####################################################################################
  2181.  
  2182. Gdip_DeleteGraphics(pGraphics)
  2183. {
  2184.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2185. }
  2186.  
  2187. ;#####################################################################################
  2188.  
  2189. Gdip_DisposeImageAttributes(ImageAttr)
  2190. {
  2191.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  2192. }
  2193.  
  2194. ;#####################################################################################
  2195.  
  2196. Gdip_DeleteFont(hFont)
  2197. {
  2198.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  2199. }
  2200.  
  2201. ;#####################################################################################
  2202.  
  2203. Gdip_DeleteStringFormat(hFormat)
  2204. {
  2205.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  2206. }
  2207.  
  2208. ;#####################################################################################
  2209.  
  2210. Gdip_DeleteFontFamily(hFamily)
  2211. {
  2212.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  2213. }
  2214.  
  2215. ;#####################################################################################
  2216.  
  2217. Gdip_DeleteMatrix(Matrix)
  2218. {
  2219.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  2220. }
  2221.  
  2222. ;#####################################################################################
  2223. ; Text functions
  2224. ;#####################################################################################
  2225.  
  2226. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2227. {
  2228.     IWidth := Width, IHeight:= Height
  2229.    
  2230.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2231.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2232.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2233.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2234.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2235.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2236.     RegExMatch(Options, "i)NoWrap", NoWrap)
  2237.     RegExMatch(Options, "i)R(\d)", Rendering)
  2238.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2239.  
  2240.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2241.         PassBrush := 1, pBrush := Colour2
  2242.    
  2243.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2244.         return -1
  2245.  
  2246.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2247.     Loop, Parse, Styles, |
  2248.     {
  2249.         if RegExMatch(Options, "\b" A_loopField)
  2250.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2251.     }
  2252.  
  2253.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2254.     Loop, Parse, Alignments, |
  2255.     {
  2256.         if RegExMatch(Options, "\b" A_loopField)
  2257.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  2258.     }
  2259.  
  2260.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2261.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2262.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2263.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2264.     if !PassBrush
  2265.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2266.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2267.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2268.  
  2269.     hFamily := Gdip_FontFamilyCreate(Font)
  2270.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  2271.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  2272.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  2273.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2274.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2275.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2276.    
  2277.     CreateRectF(RC, xpos, ypos, Width, Height)
  2278.     Gdip_SetStringFormatAlign(hFormat, Align)
  2279.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2280.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2281.  
  2282.     if vPos
  2283.     {
  2284.         StringSplit, ReturnRC, ReturnRC, |
  2285.        
  2286.         if (vPos = "vCentre") || (vPos = "vCenter")
  2287.             ypos += (Height-ReturnRC4)//2
  2288.         else if (vPos = "Top") || (vPos = "Up")
  2289.             ypos := 0
  2290.         else if (vPos = "Bottom") || (vPos = "Down")
  2291.             ypos := Height-ReturnRC4
  2292.        
  2293.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2294.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2295.     }
  2296.  
  2297.     if !Measure
  2298.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2299.  
  2300.     if !PassBrush
  2301.         Gdip_DeleteBrush(pBrush)
  2302.     Gdip_DeleteStringFormat(hFormat)  
  2303.     Gdip_DeleteFont(hFont)
  2304.     Gdip_DeleteFontFamily(hFamily)
  2305.     return E ? E : ReturnRC
  2306. }
  2307.  
  2308. ;#####################################################################################
  2309.  
  2310. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2311. {
  2312.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2313.    
  2314.     if (!A_IsUnicode)
  2315.     {
  2316.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  2317.         VarSetCapacity(wString, nSize*2)
  2318.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2319.     }
  2320.    
  2321.     return DllCall("gdiplus\GdipDrawString"
  2322.                     , Ptr, pGraphics
  2323.                     , Ptr, A_IsUnicode ? &sString : &wString
  2324.                     , "int", -1
  2325.                     , Ptr, hFont
  2326.                     , Ptr, &RectF
  2327.                     , Ptr, hFormat
  2328.                     , Ptr, pBrush)
  2329. }
  2330.  
  2331. ;#####################################################################################
  2332.  
  2333. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2334. {
  2335.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2336.    
  2337.     VarSetCapacity(RC, 16)
  2338.     if !A_IsUnicode
  2339.     {
  2340.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  2341.         VarSetCapacity(wString, nSize*2)  
  2342.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  2343.     }
  2344.    
  2345.     DllCall("gdiplus\GdipMeasureString"
  2346.                     , Ptr, pGraphics
  2347.                     , Ptr, A_IsUnicode ? &sString : &wString
  2348.                     , "int", -1
  2349.                     , Ptr, hFont
  2350.                     , Ptr, &RectF
  2351.                     , Ptr, hFormat
  2352.                     , Ptr, &RC
  2353.                     , "uint*", Chars
  2354.                     , "uint*", Lines)
  2355.    
  2356.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2357. }
  2358.  
  2359. ; Near = 0
  2360. ; Center = 1
  2361. ; Far = 2
  2362. Gdip_SetStringFormatAlign(hFormat, Align)
  2363. {
  2364.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  2365. }
  2366.  
  2367. ; StringFormatFlagsDirectionRightToLeft    = 0x00000001
  2368. ; StringFormatFlagsDirectionVertical       = 0x00000002
  2369. ; StringFormatFlagsNoFitBlackBox           = 0x00000004
  2370. ; StringFormatFlagsDisplayFormatControl    = 0x00000020
  2371. ; StringFormatFlagsNoFontFallback          = 0x00000400
  2372. ; StringFormatFlagsMeasureTrailingSpaces   = 0x00000800
  2373. ; StringFormatFlagsNoWrap                  = 0x00001000
  2374. ; StringFormatFlagsLineLimit               = 0x00002000
  2375. ; StringFormatFlagsNoClip                  = 0x00004000
  2376. Gdip_StringFormatCreate(Format=0, Lang=0)
  2377. {
  2378.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  2379.    return hFormat
  2380. }
  2381.  
  2382. ; Regular = 0
  2383. ; Bold = 1
  2384. ; Italic = 2
  2385. ; BoldItalic = 3
  2386. ; Underline = 4
  2387. ; Strikeout = 8
  2388. Gdip_FontCreate(hFamily, Size, Style=0)
  2389. {
  2390.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  2391.    return hFont
  2392. }
  2393.  
  2394. Gdip_FontFamilyCreate(Font)
  2395. {
  2396.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2397.    
  2398.     if (!A_IsUnicode)
  2399.     {
  2400.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  2401.         VarSetCapacity(wFont, nSize*2)
  2402.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  2403.     }
  2404.    
  2405.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  2406.                     , Ptr, A_IsUnicode ? &Font : &wFont
  2407.                     , "uint", 0
  2408.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  2409.    
  2410.     return hFamily
  2411. }
  2412.  
  2413. ;#####################################################################################
  2414. ; Matrix functions
  2415. ;#####################################################################################
  2416.  
  2417. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2418. {
  2419.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2420.    return Matrix
  2421. }
  2422.  
  2423. Gdip_CreateMatrix()
  2424. {
  2425.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  2426.    return Matrix
  2427. }
  2428.  
  2429. ;#####################################################################################
  2430. ; GraphicsPath functions
  2431. ;#####################################################################################
  2432.  
  2433. ; Alternate = 0
  2434. ; Winding = 1
  2435. Gdip_CreatePath(BrushMode=0)
  2436. {
  2437.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  2438.     return Path
  2439. }
  2440.  
  2441. Gdip_AddPathEllipse(Path, x, y, w, h)
  2442. {
  2443.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  2444. }
  2445.  
  2446. Gdip_AddPathPolygon(Path, Points)
  2447. {
  2448.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2449.    
  2450.     StringSplit, Points, Points, |
  2451.     VarSetCapacity(PointF, 8*Points0)  
  2452.     Loop, %Points0%
  2453.     {
  2454.         StringSplit, Coord, Points%A_Index%, `,
  2455.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2456.     }  
  2457.  
  2458.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  2459. }
  2460.  
  2461. Gdip_DeletePath(Path)
  2462. {
  2463.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  2464. }
  2465.  
  2466. ;#####################################################################################
  2467. ; Quality functions
  2468. ;#####################################################################################
  2469.  
  2470. ; SystemDefault = 0
  2471. ; SingleBitPerPixelGridFit = 1
  2472. ; SingleBitPerPixel = 2
  2473. ; AntiAliasGridFit = 3
  2474. ; AntiAlias = 4
  2475. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2476. {
  2477.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  2478. }
  2479.  
  2480. ; Default = 0
  2481. ; LowQuality = 1
  2482. ; HighQuality = 2
  2483. ; Bilinear = 3
  2484. ; Bicubic = 4
  2485. ; NearestNeighbor = 5
  2486. ; HighQualityBilinear = 6
  2487. ; HighQualityBicubic = 7
  2488. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2489. {
  2490.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  2491. }
  2492.  
  2493. ; Default = 0
  2494. ; HighSpeed = 1
  2495. ; HighQuality = 2
  2496. ; None = 3
  2497. ; AntiAlias = 4
  2498. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2499. {
  2500.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  2501. }
  2502.  
  2503. ; CompositingModeSourceOver = 0 (blended)
  2504. ; CompositingModeSourceCopy = 1 (overwrite)
  2505. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2506. {
  2507.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  2508. }
  2509.  
  2510. ;#####################################################################################
  2511. ; Extra functions
  2512. ;#####################################################################################
  2513.  
  2514. Gdip_Startup()
  2515. {
  2516.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2517.    
  2518.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2519.         DllCall("LoadLibrary", "str", "gdiplus")
  2520.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  2521.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  2522.     return pToken
  2523. }
  2524.  
  2525. Gdip_Shutdown(pToken)
  2526. {
  2527.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2528.    
  2529.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  2530.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  2531.         DllCall("FreeLibrary", Ptr, hModule)
  2532.     return 0
  2533. }
  2534.  
  2535. ; Prepend = 0; The new operation is applied before the old operation.
  2536. ; Append = 1; The new operation is applied after the old operation.
  2537. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2538. {
  2539.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  2540. }
  2541.  
  2542. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2543. {
  2544.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2545. }
  2546.  
  2547. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2548. {
  2549.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2550. }
  2551.  
  2552. Gdip_ResetWorldTransform(pGraphics)
  2553. {
  2554.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2555. }
  2556.  
  2557. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2558. {
  2559.     pi := 3.14159, TAngle := Angle*(pi/180)
  2560.  
  2561.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2562.     if ((Bound >= 0) && (Bound <= 90))
  2563.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  2564.     else if ((Bound > 90) && (Bound <= 180))
  2565.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2566.     else if ((Bound > 180) && (Bound <= 270))
  2567.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2568.     else if ((Bound > 270) && (Bound <= 360))
  2569.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2570. }
  2571.  
  2572. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2573. {
  2574.     pi := 3.14159, TAngle := Angle*(pi/180)
  2575.     if !(Width && Height)
  2576.         return -1
  2577.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2578.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2579. }
  2580.  
  2581. ; RotateNoneFlipNone   = 0
  2582. ; Rotate90FlipNone     = 1
  2583. ; Rotate180FlipNone    = 2
  2584. ; Rotate270FlipNone    = 3
  2585. ; RotateNoneFlipX      = 4
  2586. ; Rotate90FlipX        = 5
  2587. ; Rotate180FlipX       = 6
  2588. ; Rotate270FlipX       = 7
  2589. ; RotateNoneFlipY      = Rotate180FlipX
  2590. ; Rotate90FlipY        = Rotate270FlipX
  2591. ; Rotate180FlipY       = RotateNoneFlipX
  2592. ; Rotate270FlipY       = Rotate90FlipX
  2593. ; RotateNoneFlipXY     = Rotate180FlipNone
  2594. ; Rotate90FlipXY       = Rotate270FlipNone
  2595. ; Rotate180FlipXY      = RotateNoneFlipNone
  2596. ; Rotate270FlipXY      = Rotate90FlipNone
  2597.  
  2598. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  2599. {
  2600.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  2601. }
  2602.  
  2603. ; Replace = 0
  2604. ; Intersect = 1
  2605. ; Union = 2
  2606. ; Xor = 3
  2607. ; Exclude = 4
  2608. ; Complement = 5
  2609. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2610. {
  2611.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2612. }
  2613.  
  2614. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2615. {
  2616.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2617.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  2618. }
  2619.  
  2620. Gdip_ResetClip(pGraphics)
  2621. {
  2622.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  2623. }
  2624.  
  2625. Gdip_GetClipRegion(pGraphics)
  2626. {
  2627.     Region := Gdip_CreateRegion()
  2628.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  2629.     return Region
  2630. }
  2631.  
  2632. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  2633. {
  2634.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2635.    
  2636.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  2637. }
  2638.  
  2639. Gdip_CreateRegion()
  2640. {
  2641.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  2642.     return Region
  2643. }
  2644.  
  2645. Gdip_DeleteRegion(Region)
  2646. {
  2647.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  2648. }
  2649.  
  2650. ;#####################################################################################
  2651. ; BitmapLockBits
  2652. ;#####################################################################################
  2653.  
  2654. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  2655. {
  2656.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2657.    
  2658.     CreateRect(Rect, x, y, w, h)
  2659.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  2660.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  2661.     Stride := NumGet(BitmapData, 8, "Int")
  2662.     Scan0 := NumGet(BitmapData, 16, Ptr)
  2663.     return E
  2664. }
  2665.  
  2666. ;#####################################################################################
  2667.  
  2668. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  2669. {
  2670.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2671.    
  2672.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  2673. }
  2674.  
  2675. ;#####################################################################################
  2676.  
  2677. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  2678. {
  2679.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  2680. }
  2681.  
  2682. ;#####################################################################################
  2683.  
  2684. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  2685. {
  2686.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  2687. }
  2688.  
  2689. ;#####################################################################################
  2690.  
  2691. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  2692. {
  2693.     static PixelateBitmap
  2694.    
  2695.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  2696.    
  2697.     if (!PixelateBitmap)
  2698.     {
  2699.         if A_PtrSize != 8 ; x86 machine code
  2700.         MCode_PixelateBitmap =
  2701.         (LTrim Join
  2702.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  2703.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  2704.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  2705.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  2706.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  2707.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  2708.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  2709.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  2710.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  2711.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  2712.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  2713.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  2714.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  2715.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  2716.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  2717.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  2718.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  2719.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  2720.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  2721.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  2722.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  2723.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  2724.         )
  2725.         else ; x64 machine code
  2726.         MCode_PixelateBitmap =
  2727.         (LTrim Join
  2728.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  2729.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  2730.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  2731.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  2732.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  2733.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  2734.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  2735.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  2736.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  2737.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  2738.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  2739.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  2740.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  2741.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  2742.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  2743.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  2744.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  2745.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  2746.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  2747.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  2748.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  2749.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  2750.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  2751.         )
  2752.        
  2753.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  2754.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  2755.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  2756.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  2757.     }
  2758.  
  2759.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  2760.    
  2761.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  2762.         return -1
  2763.     if (BlockSize > Width || BlockSize > Height)
  2764.         return -2
  2765.  
  2766.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  2767.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  2768.     if (E1 || E2)
  2769.         return -3
  2770.  
  2771.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  2772.    
  2773.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  2774.     return 0
  2775. }
  2776.  
  2777. ;#####################################################################################
  2778.  
  2779. Gdip_ToARGB(A, R, G, B)
  2780. {
  2781.     return (A << 24) | (R << 16) | (G << 8) | B
  2782. }
  2783.  
  2784. ;#####################################################################################
  2785.  
  2786. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  2787. {
  2788.     A := (0xff000000 & ARGB) >> 24
  2789.     R := (0x00ff0000 & ARGB) >> 16
  2790.     G := (0x0000ff00 & ARGB) >> 8
  2791.     B := 0x000000ff & ARGB
  2792. }
  2793.  
  2794. ;#####################################################################################
  2795.  
  2796. Gdip_AFromARGB(ARGB)
  2797. {
  2798.     return (0xff000000 & ARGB) >> 24
  2799. }
  2800.  
  2801. ;#####################################################################################
  2802.  
  2803. Gdip_RFromARGB(ARGB)
  2804. {
  2805.     return (0x00ff0000 & ARGB) >> 16
  2806. }
  2807.  
  2808. ;#####################################################################################
  2809.  
  2810. Gdip_GFromARGB(ARGB)
  2811. {
  2812.     return (0x0000ff00 & ARGB) >> 8
  2813. }
  2814.  
  2815. ;#####################################################################################
  2816.  
  2817. Gdip_BFromARGB(ARGB)
  2818. {
  2819.     return 0x000000ff & ARGB
  2820. }
  2821.  
  2822. ;#####################################################################################
  2823.  
  2824. StrGetB(Address, Length=-1, Encoding=0)
  2825. {
  2826.     ; Flexible parameter handling:
  2827.     if Length is not integer
  2828.     Encoding := Length,  Length := -1
  2829.  
  2830.     ; Check for obvious errors.
  2831.     if (Address+0 < 1024)
  2832.         return
  2833.  
  2834.     ; Ensure 'Encoding' contains a numeric identifier.
  2835.     if Encoding = UTF-16
  2836.         Encoding = 1200
  2837.     else if Encoding = UTF-8
  2838.         Encoding = 65001
  2839.     else if SubStr(Encoding,1,2)="CP"
  2840.         Encoding := SubStr(Encoding,3)
  2841.  
  2842.     if !Encoding ; "" or 0
  2843.     {
  2844.         ; No conversion necessary, but we might not want the whole string.
  2845.         if (Length == -1)
  2846.             Length := DllCall("lstrlen", "uint", Address)
  2847.         VarSetCapacity(String, Length)
  2848.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  2849.     }
  2850.     else if Encoding = 1200 ; UTF-16
  2851.     {
  2852.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  2853.         VarSetCapacity(String, char_count)
  2854.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  2855.     }
  2856.     else if Encoding is integer
  2857.     {
  2858.         ; Convert from target encoding to UTF-16 then to the active code page.
  2859.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  2860.         VarSetCapacity(String, char_count * 2)
  2861.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  2862.         String := StrGetB(&String, char_count, 1200)
  2863.     }
  2864.    
  2865.     return String
  2866. }
  2867.  
  2868.  
  2869.  
  2870.  
  2871.  
  2872.  
  2873.  
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890. ;                                               End Of Gdip Lib
  2891. ;-----------------------------------------------------------------------------------------------------------
  2892. ;-----------------------------------------------------------------------------------------------------------
  2893. ;-----------------------------------------------------------------------------------------------------------
  2894.  
  2895.  
  2896. set_Temp(){
  2897. global
  2898. temp=
  2899. (% ` Join`r`n
  2900. îUpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  2901. îBitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  2902. îStretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  2903. îSetStretchBltMode(hdc, iStretchMode=4)
  2904. îSetImage(hwnd, hBitmap)
  2905. îSetSysColorToControl(hwnd, SysColor=15)
  2906. îGdip_BitmapFromScreen(Screen=0, Raster="")
  2907. îGdip_BitmapFromHWND(hwnd)
  2908. îCreateRectF(ByRef RectF, x, y, w, h)
  2909. îCreateRect(ByRef Rect, x, y, w, h)
  2910. îCreateSizeF(ByRef SizeF, w, h)
  2911. îCreatePointF(ByRef PointF, x, y)
  2912. îCreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  2913. îPrintWindow(hwnd, hdc, Flags=0)
  2914. îDestroyIcon(hIcon)
  2915. îPaintDesktop(hdc)
  2916. îCreateCompatibleBitmap(hdc, w, h)
  2917. îCreateCompatibleDC(hdc=0)
  2918. îSelectObject(hdc, hgdiobj)
  2919. îDeleteObject(hObject)
  2920. îGetDC(hwnd=0)
  2921. îGetDCEx(hwnd, flags=0, hrgnClip=0)
  2922. îReleaseDC(hdc, hwnd=0)
  2923. îDeleteDC(hdc)
  2924. îGdip_LibraryVersion()
  2925. îGdip_LibrarySubVersion()
  2926. îGdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  2927. îGdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  2928. îGdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  2929. îGdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  2930. îGdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  2931. îGdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  2932. îGdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  2933. îGdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  2934. îGdip_DrawLines(pGraphics, pPen, Points)
  2935. îGdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  2936. îGdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  2937. îGdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  2938. îGdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  2939. îGdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  2940. îGdip_FillRegion(pGraphics, pBrush, Region)
  2941. îGdip_FillPath(pGraphics, pBrush, Path)
  2942. îGdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  2943. îGdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  2944. îGdip_SetImageAttributesColorMatrix(Matrix)
  2945. îGdip_GraphicsFromImage(pBitmap)
  2946. îGdip_GraphicsFromHDC(hdc)
  2947. îGdip_GetDC(pGraphics)
  2948. îGdip_ReleaseDC(pGraphics, hdc)
  2949. îGdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  2950. îGdip_BlurBitmap(pBitmap, Blur)
  2951. îGdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  2952. îGdip_GetPixel(pBitmap, x, y)
  2953. îGdip_SetPixel(pBitmap, x, y, ARGB)
  2954. îGdip_GetImageWidth(pBitmap)
  2955. îGdip_GetImageHeight(pBitmap)
  2956. îGdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  2957. îGdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  2958. îGdip_GetImagePixelFormat(pBitmap)
  2959. îGdip_GetDpiX(pGraphics)
  2960. îGdip_GetDpiY(pGraphics)
  2961. îGdip_GetImageHorizontalResolution(pBitmap)
  2962. îGdip_GetImageVerticalResolution(pBitmap)
  2963. îGdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  2964. îGdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  2965. îGdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  2966. îGdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  2967. îGdip_CreateBitmapFromHICON(hIcon)
  2968. îGdip_CreateHICONFromBitmap(pBitmap)
  2969. îGdip_CreateBitmap(Width, Height, Format=0x26200A)
  2970. îGdip_CreateBitmapFromClipboard()
  2971. îGdip_SetBitmapToClipboard(pBitmap)
  2972. îGdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  2973. îGdip_CreatePen(ARGB, w)
  2974. îGdip_CreatePenFromBrush(pBrush, w)
  2975. îGdip_BrushCreateSolid(ARGB=0xff000000)
  2976. îGdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  2977. îGdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  2978. îGdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2979. îGdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2980. îGdip_CloneBrush(pBrush)
  2981. îGdip_DeletePen(pPen)
  2982. îGdip_DeleteBrush(pBrush)
  2983. îGdip_DisposeImage(pBitmap)
  2984. îGdip_DeleteGraphics(pGraphics)
  2985. îGdip_DisposeImageAttributes(ImageAttr)
  2986. îGdip_DeleteFont(hFont)
  2987. îGdip_DeleteStringFormat(hFormat)
  2988. îGdip_DeleteFontFamily(hFamily)
  2989. îGdip_DeleteMatrix(Matrix)
  2990. îGdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2991. îGdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2992. îGdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2993. îGdip_SetStringFormatAlign(hFormat, Align)
  2994. îGdip_StringFormatCreate(Format=0, Lang=0)
  2995. îGdip_FontCreate(hFamily, Size, Style=0)
  2996. îGdip_FontFamilyCreate(Font)
  2997. îGdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2998. îGdip_CreateMatrix()
  2999. îGdip_CreatePath(BrushMode=0)
  3000. îGdip_AddPathEllipse(Path, x, y, w, h)
  3001. îGdip_AddPathPolygon(Path, Points)
  3002. îGdip_DeletePath(Path)
  3003. îGdip_SetTextRenderingHint(pGraphics, RenderingHint)
  3004. îGdip_SetInterpolationMode(pGraphics, InterpolationMode)
  3005. îGdip_SetSmoothingMode(pGraphics, SmoothingMode)
  3006. îGdip_SetCompositingMode(pGraphics, CompositingMode=0)
  3007. îGdip_Startup()
  3008. îGdip_Shutdown(pToken)
  3009. îGdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  3010. îGdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  3011. îGdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  3012. îGdip_ResetWorldTransform(pGraphics)
  3013. îGdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  3014. îGdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  3015. îGdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  3016. îGdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  3017. îGdip_SetClipPath(pGraphics, Path, CombineMode=0)
  3018. îGdip_ResetClip(pGraphics)
  3019. îGdip_GetClipRegion(pGraphics)
  3020. îGdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  3021. îGdip_CreateRegion()
  3022. îGdip_DeleteRegion(Region)
  3023. îGdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  3024. îGdip_UnlockBits(pBitmap, ByRef BitmapData)
  3025. îGdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  3026. îGdip_GetLockBitPixel(Scan0, x, y, Stride)
  3027. îGdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  3028. îGdip_ToARGB(A, R, G, B)
  3029. îGdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  3030. îGdip_AFromARGB(ARGB)
  3031. îGdip_RFromARGB(ARGB)
  3032. îGdip_GFromARGB(ARGB)
  3033. îGdip_BFromARGB(ARGB)
  3034. îStrGetB(Address, Length=-1, Encoding=0)
  3035. )
  3036.  
  3037. }  
  3038.  
  3039. /*
  3040.  
  3041.  
  3042. •;#####################################################################################
  3043.  
  3044. ; Function:                 UpdateLayeredWindow
  3045. ; Description:              Updates a layered window with the handle to the DC of a gdi bitmap
  3046. ;
  3047. ; hwnd                      Handle of the layered window to update
  3048. ; hdc                       Handle to the DC of the GDI bitmap to update the window with
  3049. ; Layeredx                  x position to place the window
  3050. ; Layeredy                  y position to place the window
  3051. ; Layeredw                  Width of the window
  3052. ; Layeredh                  Height of the window
  3053. ; Alpha                     Default = 255 : The transparency (0-255) to set the window transparency
  3054. ;
  3055. ; return                    If the function succeeds, the return value is nonzero
  3056. ;
  3057. ; notes                     If x or y omitted, then layered window will use its current coordinates
  3058. ;                           If w or h omitted then current width and height will be used
  3059.  
  3060. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  3061. {
  3062.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3063.    
  3064.     if ((x != "") && (y != ""))
  3065.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  3066.  
  3067.     if (w = "") ||(h = "")
  3068.         WinGetPos,,, w, h, ahk_id %hwnd%
  3069.    
  3070.     return DllCall("UpdateLayeredWindow"
  3071.                     , Ptr, hwnd
  3072.                     , Ptr, 0
  3073.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  3074.                     , "int64*", w|h<<32
  3075.                     , Ptr, hdc
  3076.                     , "int64*", 0
  3077.                     , "uint", 0
  3078.                     , "UInt*", Alpha<<16|1<<24
  3079.                     , "uint", 2)
  3080. }
  3081.  
  3082. •;#####################################################################################
  3083.  
  3084. ; Function              BitBlt
  3085. ; Description           The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  3086. ;                       of pixels from the specified source device context into a destination device context.
  3087. ;
  3088. ; dDC                   handle to destination DC
  3089. ; dx                    x-coord of destination upper-left corner
  3090. ; dy                    y-coord of destination upper-left corner
  3091. ; dw                    width of the area to copy
  3092. ; dh                    height of the area to copy
  3093. ; sDC                   handle to source DC
  3094. ; sx                    x-coordinate of source upper-left corner
  3095. ; sy                    y-coordinate of source upper-left corner
  3096. ; Raster                raster operation code
  3097. ;
  3098. ; return                If the function succeeds, the return value is nonzero
  3099. ;
  3100. ; notes                 If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  3101. ;
  3102. ; BLACKNESS             = 0x00000042
  3103. ; NOTSRCERASE           = 0x001100A6
  3104. ; NOTSRCCOPY            = 0x00330008
  3105. ; SRCERASE              = 0x00440328
  3106. ; DSTINVERT             = 0x00550009
  3107. ; PATINVERT             = 0x005A0049
  3108. ; SRCINVERT             = 0x00660046
  3109. ; SRCAND                = 0x008800C6
  3110. ; MERGEPAINT            = 0x00BB0226
  3111. ; MERGECOPY             = 0x00C000CA
  3112. ; SRCCOPY               = 0x00CC0020
  3113. ; SRCPAINT              = 0x00EE0086
  3114. ; PATCOPY               = 0x00F00021
  3115. ; PATPAINT              = 0x00FB0A09
  3116. ; WHITENESS             = 0x00FF0062
  3117. ; CAPTUREBLT            = 0x40000000
  3118. ; NOMIRRORBITMAP        = 0x80000000
  3119.  
  3120. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  3121. {
  3122.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3123.    
  3124.     return DllCall("gdi32\BitBlt"
  3125.                     , Ptr, dDC
  3126.                     , "int", dx
  3127.                     , "int", dy
  3128.                     , "int", dw
  3129.                     , "int", dh
  3130.                     , Ptr, sDC
  3131.                     , "int", sx
  3132.                     , "int", sy
  3133.                     , "uint", Raster ? Raster : 0x00CC0020)
  3134. }
  3135.  
  3136. •;#####################################################################################
  3137.  
  3138. ; Function              StretchBlt
  3139. ; Description           The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  3140. ;                       stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  3141. ;                       The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  3142. ;
  3143. ; ddc                   handle to destination DC
  3144. ; dx                    x-coord of destination upper-left corner
  3145. ; dy                    y-coord of destination upper-left corner
  3146. ; dw                    width of destination rectangle
  3147. ; dh                    height of destination rectangle
  3148. ; sdc                   handle to source DC
  3149. ; sx                    x-coordinate of source upper-left corner
  3150. ; sy                    y-coordinate of source upper-left corner
  3151. ; sw                    width of source rectangle
  3152. ; sh                    height of source rectangle
  3153. ; Raster                raster operation code
  3154. ;
  3155. ; return                If the function succeeds, the return value is nonzero
  3156. ;
  3157. ; notes                 If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt    
  3158.  
  3159. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  3160. {
  3161.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3162.    
  3163.     return DllCall("gdi32\StretchBlt"
  3164.                     , Ptr, ddc
  3165.                     , "int", dx
  3166.                     , "int", dy
  3167.                     , "int", dw
  3168.                     , "int", dh
  3169.                     , Ptr, sdc
  3170.                     , "int", sx
  3171.                     , "int", sy
  3172.                     , "int", sw
  3173.                     , "int", sh
  3174.                     , "uint", Raster ? Raster : 0x00CC0020)
  3175. }
  3176.  
  3177. •;#####################################################################################
  3178.  
  3179. ; Function              SetStretchBltMode
  3180. ; Description           The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  3181. ;
  3182. ; hdc                   handle to the DC
  3183. ; iStretchMode          The stretching mode, describing how the target will be stretched
  3184. ;
  3185. ; return                If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  3186. ;
  3187. ; STRETCH_ANDSCANS      = 0x01
  3188. ; STRETCH_ORSCANS       = 0x02
  3189. ; STRETCH_DELETESCANS   = 0x03
  3190. ; STRETCH_HALFTONE      = 0x04
  3191.  
  3192. SetStretchBltMode(hdc, iStretchMode=4)
  3193. {
  3194.     return DllCall("gdi32\SetStretchBltMode"
  3195.                     , A_PtrSize ? "UPtr" : "UInt", hdc
  3196.                     , "int", iStretchMode)
  3197. }
  3198.  
  3199. •;#####################################################################################
  3200.  
  3201. ; Function              SetImage
  3202. ; Description           Associates a new image with a static control
  3203. ;
  3204. ; hwnd                  handle of the control to update
  3205. ; hBitmap               a gdi bitmap to associate the static control with
  3206. ;
  3207. ; return                If the function succeeds, the return value is nonzero
  3208.  
  3209. SetImage(hwnd, hBitmap)
  3210. {
  3211.     SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  3212.     E := ErrorLevel
  3213.     DeleteObject(E)
  3214.     return E
  3215. }
  3216.  
  3217. •;#####################################################################################
  3218.  
  3219. ; Function              SetSysColorToControl
  3220. ; Description           Sets a solid colour to a control
  3221. ;
  3222. ; hwnd                  handle of the control to update
  3223. ; SysColor              A system colour to set to the control
  3224. ;
  3225. ; return                If the function succeeds, the return value is zero
  3226. ;
  3227. ; notes                 A control must have the 0xE style set to it so it is recognised as a bitmap
  3228. ;                       By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  3229. ;
  3230. ; COLOR_3DDKSHADOW              = 21
  3231. ; COLOR_3DFACE                  = 15
  3232. ; COLOR_3DHIGHLIGHT             = 20
  3233. ; COLOR_3DHILIGHT               = 20
  3234. ; COLOR_3DLIGHT                 = 22
  3235. ; COLOR_3DSHADOW                = 16
  3236. ; COLOR_ACTIVEBORDER            = 10
  3237. ; COLOR_ACTIVECAPTION           = 2
  3238. ; COLOR_APPWORKSPACE            = 12
  3239. ; COLOR_BACKGROUND              = 1
  3240. ; COLOR_BTNFACE                 = 15
  3241. ; COLOR_BTNHIGHLIGHT            = 20
  3242. ; COLOR_BTNHILIGHT              = 20
  3243. ; COLOR_BTNSHADOW               = 16
  3244. ; COLOR_BTNTEXT                 = 18
  3245. ; COLOR_CAPTIONTEXT             = 9
  3246. ; COLOR_DESKTOP                 = 1
  3247. ; COLOR_GRADIENTACTIVECAPTION   = 27
  3248. ; COLOR_GRADIENTINACTIVECAPTION = 28
  3249. ; COLOR_GRAYTEXT                = 17
  3250. ; COLOR_HIGHLIGHT               = 13
  3251. ; COLOR_HIGHLIGHTTEXT           = 14
  3252. ; COLOR_HOTLIGHT                = 26
  3253. ; COLOR_INACTIVEBORDER          = 11
  3254. ; COLOR_INACTIVECAPTION         = 3
  3255. ; COLOR_INACTIVECAPTIONTEXT     = 19
  3256. ; COLOR_INFOBK                  = 24
  3257. ; COLOR_INFOTEXT                = 23
  3258. ; COLOR_MENU                    = 4
  3259. ; COLOR_MENUHILIGHT             = 29
  3260. ; COLOR_MENUBAR                 = 30
  3261. ; COLOR_MENUTEXT                = 7
  3262. ; COLOR_SCROLLBAR               = 0
  3263. ; COLOR_WINDOW                  = 5
  3264. ; COLOR_WINDOWFRAME             = 6
  3265. ; COLOR_WINDOWTEXT              = 8
  3266.  
  3267. SetSysColorToControl(hwnd, SysColor=15)
  3268. {
  3269.    WinGetPos,,, w, h, ahk_id %hwnd%
  3270.    bc := DllCall("GetSysColor", "Int", SysColor, "UInt")
  3271.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  3272.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  3273.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  3274.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  3275.    SetImage(hwnd, hBitmap)
  3276.    Gdip_DeleteBrush(pBrushClear)
  3277.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  3278.    return 0
  3279. }
  3280.  
  3281. •;#####################################################################################
  3282.  
  3283. ; Function              Gdip_BitmapFromScreen
  3284. ; Description           Gets a gdi+ bitmap from the screen
  3285. ;
  3286. ; Screen                0 = All screens
  3287. ;                       Any numerical value = Just that screen
  3288. ;                       x|y|w|h = Take specific coordinates with a width and height
  3289. ; Raster                raster operation code
  3290. ;
  3291. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  3292. ;                       -1:     one or more of x,y,w,h not passed properly
  3293. ;
  3294. ; notes                 If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  3295.  
  3296. Gdip_BitmapFromScreen(Screen=0, Raster="")
  3297. {
  3298.     if (Screen = 0)
  3299.     {
  3300.         Sysget, x, 76
  3301.         Sysget, y, 77  
  3302.         Sysget, w, 78
  3303.         Sysget, h, 79
  3304.     }
  3305.     else if (SubStr(Screen, 1, 5) = "hwnd:")
  3306.     {
  3307.         Screen := SubStr(Screen, 6)
  3308.         if !WinExist( "ahk_id " Screen)
  3309.             return -2
  3310.         WinGetPos,,, w, h, ahk_id %Screen%
  3311.         x := y := 0
  3312.         hhdc := GetDCEx(Screen, 3)
  3313.     }
  3314.     else if (Screen&1 != "")
  3315.     {
  3316.         Sysget, M, Monitor, %Screen%
  3317.         x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  3318.     }
  3319.     else
  3320.     {
  3321.         StringSplit, S, Screen, |
  3322.         x := S1, y := S2, w := S3, h := S4
  3323.     }
  3324.  
  3325.     if (x = "") || (y = "") || (w = "") || (h = "")
  3326.         return -1
  3327.  
  3328.     chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC()
  3329.     BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  3330.     ReleaseDC(hhdc)
  3331.    
  3332.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  3333.     SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  3334.     return pBitmap
  3335. }
  3336.  
  3337. •;#####################################################################################
  3338.  
  3339. ; Function              Gdip_BitmapFromHWND
  3340. ; Description           Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  3341. ;
  3342. ; hwnd                  handle to the window to get a bitmap from
  3343. ;
  3344. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  3345. ;
  3346. ; notes                 Window must not be not minimised in order to get a handle to it's client area
  3347.  
  3348. Gdip_BitmapFromHWND(hwnd)
  3349. {
  3350.     WinGetPos,,, Width, Height, ahk_id %hwnd%
  3351.     hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  3352.     PrintWindow(hwnd, hdc)
  3353.     pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  3354.     SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  3355.     return pBitmap
  3356. }
  3357.  
  3358. •;#####################################################################################
  3359.  
  3360. ; Function              CreateRectF
  3361. ; Description           Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  3362. ;
  3363. ; RectF                 Name to call the RectF object
  3364. ; x                     x-coordinate of the upper left corner of the rectangle
  3365. ; y                     y-coordinate of the upper left corner of the rectangle
  3366. ; w                     Width of the rectangle
  3367. ; h                     Height of the rectangle
  3368. ;
  3369. ; return                No return value
  3370.  
  3371. CreateRectF(ByRef RectF, x, y, w, h)
  3372. {
  3373.    VarSetCapacity(RectF, 16)
  3374.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  3375. }
  3376.  
  3377. •;#####################################################################################
  3378.  
  3379. ; Function              CreateRect
  3380. ; Description           Creates a Rect object, containing a the coordinates and dimensions of a rectangle
  3381. ;
  3382. ; RectF                 Name to call the RectF object
  3383. ; x                     x-coordinate of the upper left corner of the rectangle
  3384. ; y                     y-coordinate of the upper left corner of the rectangle
  3385. ; w                     Width of the rectangle
  3386. ; h                     Height of the rectangle
  3387. ;
  3388. ; return                No return value
  3389.  
  3390. CreateRect(ByRef Rect, x, y, w, h)
  3391. {
  3392.     VarSetCapacity(Rect, 16)
  3393.     NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint")
  3394. }
  3395. •;#####################################################################################
  3396.  
  3397. ; Function              CreateSizeF
  3398. ; Description           Creates a SizeF object, containing an 2 values
  3399. ;
  3400. ; SizeF                 Name to call the SizeF object
  3401. ; w                     w-value for the SizeF object
  3402. ; h                     h-value for the SizeF object
  3403. ;
  3404. ; return                No Return value
  3405.  
  3406. CreateSizeF(ByRef SizeF, w, h)
  3407. {
  3408.    VarSetCapacity(SizeF, 8)
  3409.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  3410. }
  3411. •;#####################################################################################
  3412.  
  3413. ; Function              CreatePointF
  3414. ; Description           Creates a SizeF object, containing an 2 values
  3415. ;
  3416. ; SizeF                 Name to call the SizeF object
  3417. ; w                     w-value for the SizeF object
  3418. ; h                     h-value for the SizeF object
  3419. ;
  3420. ; return                No Return value
  3421.  
  3422. CreatePointF(ByRef PointF, x, y)
  3423. {
  3424.    VarSetCapacity(PointF, 8)
  3425.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  3426. }
  3427. •;#####################################################################################
  3428.  
  3429. ; Function              CreateDIBSection
  3430. ; Description           The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  3431. ;
  3432. ; w                     width of the bitmap to create
  3433. ; h                     height of the bitmap to create
  3434. ; hdc                   a handle to the device context to use the palette from
  3435. ; bpp                   bits per pixel (32 = ARGB)
  3436. ; ppvBits               A pointer to a variable that receives a pointer to the location of the DIB bit values
  3437. ;
  3438. ; return                returns a DIB. A gdi bitmap
  3439. ;
  3440. ; notes                 ppvBits will receive the location of the pixels in the DIB
  3441.  
  3442. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  3443. {
  3444.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3445.    
  3446.     hdc2 := hdc ? hdc : GetDC()
  3447.     VarSetCapacity(bi, 40, 0)
  3448.    
  3449.     NumPut(w, bi, 4, "uint")
  3450.     , NumPut(h, bi, 8, "uint")
  3451.     , NumPut(40, bi, 0, "uint")
  3452.     , NumPut(1, bi, 12, "ushort")
  3453.     , NumPut(0, bi, 16, "uInt")
  3454.     , NumPut(bpp, bi, 14, "ushort")
  3455.    
  3456.     hbm := DllCall("CreateDIBSection"
  3457.                     , Ptr, hdc2
  3458.                     , Ptr, &bi
  3459.                     , "uint", 0
  3460.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  3461.                     , Ptr, 0
  3462.                     , "uint", 0, Ptr)
  3463.  
  3464.     if !hdc
  3465.         ReleaseDC(hdc2)
  3466.     return hbm
  3467. }
  3468.  
  3469. •;#####################################################################################
  3470.  
  3471. ; Function              PrintWindow
  3472. ; Description           The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  3473. ;
  3474. ; hwnd                  A handle to the window that will be copied
  3475. ; hdc                   A handle to the device context
  3476. ; Flags                 Drawing options
  3477. ;
  3478. ; return                If the function succeeds, it returns a nonzero value
  3479. ;
  3480. ; PW_CLIENTONLY         = 1
  3481.  
  3482. PrintWindow(hwnd, hdc, Flags=0)
  3483. {
  3484.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3485.    
  3486.     return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags)
  3487. }
  3488.  
  3489. •;#####################################################################################
  3490.  
  3491. ; Function              DestroyIcon
  3492. ; Description           Destroys an icon and frees any memory the icon occupied
  3493. ;
  3494. ; hIcon                 Handle to the icon to be destroyed. The icon must not be in use
  3495. ;
  3496. ; return                If the function succeeds, the return value is nonzero
  3497.  
  3498. DestroyIcon(hIcon)
  3499. {
  3500.     return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon)
  3501. }
  3502.  
  3503. •;#####################################################################################
  3504.  
  3505. PaintDesktop(hdc)
  3506. {
  3507.     return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc)
  3508. }
  3509.  
  3510. •;#####################################################################################
  3511.  
  3512. CreateCompatibleBitmap(hdc, w, h)
  3513. {
  3514.     return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h)
  3515. }
  3516.  
  3517. •;#####################################################################################
  3518.  
  3519. ; Function              CreateCompatibleDC
  3520. ; Description           This function creates a memory device context (DC) compatible with the specified device
  3521. ;
  3522. ; hdc                   Handle to an existing device context                   
  3523. ;
  3524. ; return                returns the handle to a device context or 0 on failure
  3525. ;
  3526. ; notes                 If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  3527.  
  3528. CreateCompatibleDC(hdc=0)
  3529. {
  3530.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  3531. }
  3532.  
  3533. •;#####################################################################################
  3534.  
  3535. ; Function              SelectObject
  3536. ; Description           The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  3537. ;
  3538. ; hdc                   Handle to a DC
  3539. ; hgdiobj               A handle to the object to be selected into the DC
  3540. ;
  3541. ; return                If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  3542. ;
  3543. ; notes                 The specified object must have been created by using one of the following functions
  3544. ;                       Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  3545. ;                       Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  3546. ;                       Font - CreateFont, CreateFontIndirect
  3547. ;                       Pen - CreatePen, CreatePenIndirect
  3548. ;                       Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  3549. ;
  3550. ; notes                 If the selected object is a region and the function succeeds, the return value is one of the following value
  3551. ;
  3552. ; SIMPLEREGION          = 2 Region consists of a single rectangle
  3553. ; COMPLEXREGION         = 3 Region consists of more than one rectangle
  3554. ; NULLREGION            = 1 Region is empty
  3555.  
  3556. SelectObject(hdc, hgdiobj)
  3557. {
  3558.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3559.    
  3560.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  3561. }
  3562.  
  3563. •;#####################################################################################
  3564.  
  3565. ; Function              DeleteObject
  3566. ; Description           This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  3567. ;                       After the object is deleted, the specified handle is no longer valid
  3568. ;
  3569. ; hObject               Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  3570. ;
  3571. ; return                Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  3572.  
  3573. DeleteObject(hObject)
  3574. {
  3575.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  3576. }
  3577.  
  3578. •;#####################################################################################
  3579.  
  3580. ; Function              GetDC
  3581. ; Description           This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  3582. ;                       The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  3583. ;
  3584. ; 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                  
  3585. ;
  3586. ; return                The handle the device context for the specified window's client area indicates success. NULL indicates failure
  3587.  
  3588. GetDC(hwnd=0)
  3589. {
  3590.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  3591. }
  3592.  
  3593. •;#####################################################################################
  3594.  
  3595. ; DCX_CACHE = 0x2
  3596. ; DCX_CLIPCHILDREN = 0x8
  3597. ; DCX_CLIPSIBLINGS = 0x10
  3598. ; DCX_EXCLUDERGN = 0x40
  3599. ; DCX_EXCLUDEUPDATE = 0x100
  3600. ; DCX_INTERSECTRGN = 0x80
  3601. ; DCX_INTERSECTUPDATE = 0x200
  3602. ; DCX_LOCKWINDOWUPDATE = 0x400
  3603. ; DCX_NORECOMPUTE = 0x100000
  3604. ; DCX_NORESETATTRS = 0x4
  3605. ; DCX_PARENTCLIP = 0x20
  3606. ; DCX_VALIDATE = 0x200000
  3607. ; DCX_WINDOW = 0x1
  3608.  
  3609. GetDCEx(hwnd, flags=0, hrgnClip=0)
  3610. {
  3611.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3612.    
  3613.     return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags)
  3614. }
  3615.  
  3616. •;#####################################################################################
  3617.  
  3618. ; Function              ReleaseDC
  3619. ; 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
  3620. ;
  3621. ; hdc                   Handle to the device context to be released
  3622. ; hwnd                  Handle to the window whose device context is to be released
  3623. ;
  3624. ; return                1 = released
  3625. ;                       0 = not released
  3626. ;
  3627. ; 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
  3628. ;                       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.
  3629.  
  3630. ReleaseDC(hdc, hwnd=0)
  3631. {
  3632.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3633.    
  3634.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  3635. }
  3636.  
  3637. •;#####################################################################################
  3638.  
  3639. ; Function              DeleteDC
  3640. ; Description           The DeleteDC function deletes the specified device context (DC)
  3641. ;
  3642. ; hdc                   A handle to the device context
  3643. ;
  3644. ; return                If the function succeeds, the return value is nonzero
  3645. ;
  3646. ; 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
  3647.  
  3648. DeleteDC(hdc)
  3649. {
  3650.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  3651. }
  3652. •;#####################################################################################
  3653.  
  3654. ; Function              Gdip_LibraryVersion
  3655. ; Description           Get the current library version
  3656. ;
  3657. ; return                the library version
  3658. ;
  3659. ; notes                 This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  3660.  
  3661. Gdip_LibraryVersion()
  3662. {
  3663.     return 1.45
  3664. }
  3665.  
  3666. •;#####################################################################################
  3667.  
  3668. ; Function              Gdip_LibrarySubVersion
  3669. ; Description           Get the current library sub version
  3670. ;
  3671. ; return                the library sub version
  3672. ;
  3673. ; notes                 This is the sub-version currently maintained by Rseding91
  3674. Gdip_LibrarySubVersion()
  3675. {
  3676.     return 1.47
  3677. }
  3678.  
  3679. •;#####################################################################################
  3680.  
  3681. ; Function:             Gdip_BitmapFromBRA
  3682. ; Description:          Gets a pointer to a gdi+ bitmap from a BRA file
  3683. ;
  3684. ; BRAFromMemIn          The variable for a BRA file read to memory
  3685. ; File                  The name of the file, or its number that you would like (This depends on alternate parameter)
  3686. ; Alternate             Changes whether the File parameter is the file name or its number
  3687. ;
  3688. ; return                If the function succeeds, the return value is a pointer to a gdi+ bitmap
  3689. ;                       -1 = The BRA variable is empty
  3690. ;                       -2 = The BRA has an incorrect header
  3691. ;                       -3 = The BRA has information missing
  3692. ;                       -4 = Could not find file inside the BRA
  3693.  
  3694. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  3695. {
  3696.     Static FName = "ObjRelease"
  3697.    
  3698.     if !BRAFromMemIn
  3699.         return -1
  3700.     Loop, Parse, BRAFromMemIn, `n
  3701.     {
  3702.         if (A_Index = 1)
  3703.         {
  3704.             StringSplit, Header, A_LoopField, |
  3705.             if (Header0 != 4 || Header2 != "BRA!")
  3706.                 return -2
  3707.         }
  3708.         else if (A_Index = 2)
  3709.         {
  3710.             StringSplit, Info, A_LoopField, |
  3711.             if (Info0 != 3)
  3712.                 return -3
  3713.         }
  3714.         else
  3715.             break
  3716.     }
  3717.     if !Alternate
  3718.         StringReplace, File, File, \, \\, All
  3719.     RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  3720.     if !FileInfo
  3721.         return -4
  3722.    
  3723.     hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr)
  3724.     pData := DllCall("GlobalLock", Ptr, hData, Ptr)
  3725.     DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2)
  3726.     DllCall("GlobalUnlock", Ptr, hData)
  3727.     DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream)
  3728.     DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap)
  3729.     If (A_PtrSize)
  3730.         %FName%(pStream)
  3731.     Else
  3732.         DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  3733.     return pBitmap
  3734. }
  3735.  
  3736. •;#####################################################################################
  3737.  
  3738. ; Function              Gdip_DrawRectangle
  3739. ; Description           This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  3740. ;
  3741. ; pGraphics             Pointer to the Graphics of a bitmap
  3742. ; pPen                  Pointer to a pen
  3743. ; x                     x-coordinate of the top left of the rectangle
  3744. ; y                     y-coordinate of the top left of the rectangle
  3745. ; w                     width of the rectanlge
  3746. ; h                     height of the rectangle
  3747. ;
  3748. ; return                status enumeration. 0 = success
  3749. ;
  3750. ; 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
  3751.  
  3752. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  3753. {
  3754.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3755.    
  3756.     return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  3757. }
  3758.  
  3759. •;#####################################################################################
  3760.  
  3761. ; Function              Gdip_DrawRoundedRectangle
  3762. ; Description           This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  3763. ;
  3764. ; pGraphics             Pointer to the Graphics of a bitmap
  3765. ; pPen                  Pointer to a pen
  3766. ; x                     x-coordinate of the top left of the rounded rectangle
  3767. ; y                     y-coordinate of the top left of the rounded rectangle
  3768. ; w                     width of the rectanlge
  3769. ; h                     height of the rectangle
  3770. ; r                     radius of the rounded corners
  3771. ;
  3772. ; return                status enumeration. 0 = success
  3773. ;
  3774. ; 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
  3775.  
  3776. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  3777. {
  3778.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  3779.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  3780.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  3781.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  3782.     E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  3783.     Gdip_ResetClip(pGraphics)
  3784.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  3785.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  3786.     Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  3787.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  3788.     Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  3789.     Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  3790.     Gdip_ResetClip(pGraphics)
  3791.     return E
  3792. }
  3793.  
  3794. •;#####################################################################################
  3795.  
  3796. ; Function              Gdip_DrawEllipse
  3797. ; Description           This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  3798. ;
  3799. ; pGraphics             Pointer to the Graphics of a bitmap
  3800. ; pPen                  Pointer to a pen
  3801. ; x                     x-coordinate of the top left of the rectangle the ellipse will be drawn into
  3802. ; y                     y-coordinate of the top left of the rectangle the ellipse will be drawn into
  3803. ; w                     width of the ellipse
  3804. ; h                     height of the ellipse
  3805. ;
  3806. ; return                status enumeration. 0 = success
  3807. ;
  3808. ; 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
  3809.  
  3810. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  3811. {
  3812.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3813.    
  3814.     return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h)
  3815. }
  3816.  
  3817. •;#####################################################################################
  3818.  
  3819. ; Function              Gdip_DrawBezier
  3820. ; Description           This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  3821. ;
  3822. ; pGraphics             Pointer to the Graphics of a bitmap
  3823. ; pPen                  Pointer to a pen
  3824. ; x1                    x-coordinate of the start of the bezier
  3825. ; y1                    y-coordinate of the start of the bezier
  3826. ; x2                    x-coordinate of the first arc of the bezier
  3827. ; y2                    y-coordinate of the first arc of the bezier
  3828. ; x3                    x-coordinate of the second arc of the bezier
  3829. ; y3                    y-coordinate of the second arc of the bezier
  3830. ; x4                    x-coordinate of the end of the bezier
  3831. ; y4                    y-coordinate of the end of the bezier
  3832. ;
  3833. ; return                status enumeration. 0 = success
  3834. ;
  3835. ; 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
  3836.  
  3837. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  3838. {
  3839.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3840.    
  3841.     return DllCall("gdiplus\GdipDrawBezier"
  3842.                     , Ptr, pgraphics
  3843.                     , Ptr, pPen
  3844.                     , "float", x1
  3845.                     , "float", y1
  3846.                     , "float", x2
  3847.                     , "float", y2
  3848.                     , "float", x3
  3849.                     , "float", y3
  3850.                     , "float", x4
  3851.                     , "float", y4)
  3852. }
  3853.  
  3854. •;#####################################################################################
  3855.  
  3856. ; Function              Gdip_DrawArc
  3857. ; Description           This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  3858. ;
  3859. ; pGraphics             Pointer to the Graphics of a bitmap
  3860. ; pPen                  Pointer to a pen
  3861. ; x                     x-coordinate of the start of the arc
  3862. ; y                     y-coordinate of the start of the arc
  3863. ; w                     width of the arc
  3864. ; h                     height of the arc
  3865. ; StartAngle            specifies the angle between the x-axis and the starting point of the arc
  3866. ; SweepAngle            specifies the angle between the starting and ending points of the arc
  3867. ;
  3868. ; return                status enumeration. 0 = success
  3869. ;
  3870. ; 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
  3871.  
  3872. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  3873. {
  3874.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3875.    
  3876.     return DllCall("gdiplus\GdipDrawArc"
  3877.                     , Ptr, pGraphics
  3878.                     , Ptr, pPen
  3879.                     , "float", x
  3880.                     , "float", y
  3881.                     , "float", w
  3882.                     , "float", h
  3883.                     , "float", StartAngle
  3884.                     , "float", SweepAngle)
  3885. }
  3886.  
  3887. •;#####################################################################################
  3888.  
  3889. ; Function              Gdip_DrawPie
  3890. ; Description           This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  3891. ;
  3892. ; pGraphics             Pointer to the Graphics of a bitmap
  3893. ; pPen                  Pointer to a pen
  3894. ; x                     x-coordinate of the start of the pie
  3895. ; y                     y-coordinate of the start of the pie
  3896. ; w                     width of the pie
  3897. ; h                     height of the pie
  3898. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  3899. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  3900. ;
  3901. ; return                status enumeration. 0 = success
  3902. ;
  3903. ; 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
  3904.  
  3905. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  3906. {
  3907.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3908.    
  3909.     return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  3910. }
  3911.  
  3912. •;#####################################################################################
  3913.  
  3914. ; Function              Gdip_DrawLine
  3915. ; Description           This function uses a pen to draw a line into the Graphics of a bitmap
  3916. ;
  3917. ; pGraphics             Pointer to the Graphics of a bitmap
  3918. ; pPen                  Pointer to a pen
  3919. ; x1                    x-coordinate of the start of the line
  3920. ; y1                    y-coordinate of the start of the line
  3921. ; x2                    x-coordinate of the end of the line
  3922. ; y2                    y-coordinate of the end of the line
  3923. ;
  3924. ; return                status enumeration. 0 = success    
  3925.  
  3926. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  3927. {
  3928.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3929.    
  3930.     return DllCall("gdiplus\GdipDrawLine"
  3931.                     , Ptr, pGraphics
  3932.                     , Ptr, pPen
  3933.                     , "float", x1
  3934.                     , "float", y1
  3935.                     , "float", x2
  3936.                     , "float", y2)
  3937. }
  3938.  
  3939. •;#####################################################################################
  3940.  
  3941. ; Function              Gdip_DrawLines
  3942. ; Description           This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  3943. ;
  3944. ; pGraphics             Pointer to the Graphics of a bitmap
  3945. ; pPen                  Pointer to a pen
  3946. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  3947. ;
  3948. ; return                status enumeration. 0 = success            
  3949.  
  3950. Gdip_DrawLines(pGraphics, pPen, Points)
  3951. {
  3952.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3953.     StringSplit, Points, Points, |
  3954.     VarSetCapacity(PointF, 8*Points0)  
  3955.     Loop, %Points0%
  3956.     {
  3957.         StringSplit, Coord, Points%A_Index%, `,
  3958.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  3959.     }
  3960.     return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0)
  3961. }
  3962.  
  3963. •;#####################################################################################
  3964.  
  3965. ; Function              Gdip_FillRectangle
  3966. ; Description           This function uses a brush to fill a rectangle in the Graphics of a bitmap
  3967. ;
  3968. ; pGraphics             Pointer to the Graphics of a bitmap
  3969. ; pBrush                Pointer to a brush
  3970. ; x                     x-coordinate of the top left of the rectangle
  3971. ; y                     y-coordinate of the top left of the rectangle
  3972. ; w                     width of the rectanlge
  3973. ; h                     height of the rectangle
  3974. ;
  3975. ; return                status enumeration. 0 = success
  3976.  
  3977. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  3978. {
  3979.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  3980.    
  3981.     return DllCall("gdiplus\GdipFillRectangle"
  3982.                     , Ptr, pGraphics
  3983.                     , Ptr, pBrush
  3984.                     , "float", x
  3985.                     , "float", y
  3986.                     , "float", w
  3987.                     , "float", h)
  3988. }
  3989.  
  3990. •;#####################################################################################
  3991.  
  3992. ; Function              Gdip_FillRoundedRectangle
  3993. ; Description           This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  3994. ;
  3995. ; pGraphics             Pointer to the Graphics of a bitmap
  3996. ; pBrush                Pointer to a brush
  3997. ; x                     x-coordinate of the top left of the rounded rectangle
  3998. ; y                     y-coordinate of the top left of the rounded rectangle
  3999. ; w                     width of the rectanlge
  4000. ; h                     height of the rectangle
  4001. ; r                     radius of the rounded corners
  4002. ;
  4003. ; return                status enumeration. 0 = success
  4004.  
  4005. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  4006. {
  4007.     Region := Gdip_GetClipRegion(pGraphics)
  4008.     Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  4009.     Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  4010.     Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  4011.     Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  4012.     E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  4013.     Gdip_SetClipRegion(pGraphics, Region, 0)
  4014.     Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  4015.     Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  4016.     Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  4017.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  4018.     Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  4019.     Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  4020.     Gdip_SetClipRegion(pGraphics, Region, 0)
  4021.     Gdip_DeleteRegion(Region)
  4022.     return E
  4023. }
  4024.  
  4025. •;#####################################################################################
  4026.  
  4027. ; Function              Gdip_FillPolygon
  4028. ; Description           This function uses a brush to fill a polygon in the Graphics of a bitmap
  4029. ;
  4030. ; pGraphics             Pointer to the Graphics of a bitmap
  4031. ; pBrush                Pointer to a brush
  4032. ; Points                the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  4033. ;
  4034. ; return                status enumeration. 0 = success
  4035. ;
  4036. ; notes                 Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  4037. ; Alternate             = 0
  4038. ; Winding               = 1
  4039.  
  4040. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  4041. {
  4042.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4043.    
  4044.     StringSplit, Points, Points, |
  4045.     VarSetCapacity(PointF, 8*Points0)  
  4046.     Loop, %Points0%
  4047.     {
  4048.         StringSplit, Coord, Points%A_Index%, `,
  4049.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  4050.     }  
  4051.     return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode)
  4052. }
  4053.  
  4054. •;#####################################################################################
  4055.  
  4056. ; Function              Gdip_FillPie
  4057. ; Description           This function uses a brush to fill a pie in the Graphics of a bitmap
  4058. ;
  4059. ; pGraphics             Pointer to the Graphics of a bitmap
  4060. ; pBrush                Pointer to a brush
  4061. ; x                     x-coordinate of the top left of the pie
  4062. ; y                     y-coordinate of the top left of the pie
  4063. ; w                     width of the pie
  4064. ; h                     height of the pie
  4065. ; StartAngle            specifies the angle between the x-axis and the starting point of the pie
  4066. ; SweepAngle            specifies the angle between the starting and ending points of the pie
  4067. ;
  4068. ; return                status enumeration. 0 = success
  4069.  
  4070. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  4071. {
  4072.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4073.    
  4074.     return DllCall("gdiplus\GdipFillPie"
  4075.                     , Ptr, pGraphics
  4076.                     , Ptr, pBrush
  4077.                     , "float", x
  4078.                     , "float", y
  4079.                     , "float", w
  4080.                     , "float", h
  4081.                     , "float", StartAngle
  4082.                     , "float", SweepAngle)
  4083. }
  4084.  
  4085. •;#####################################################################################
  4086.  
  4087. ; Function              Gdip_FillEllipse
  4088. ; Description           This function uses a brush to fill an ellipse in the Graphics of a bitmap
  4089. ;
  4090. ; pGraphics             Pointer to the Graphics of a bitmap
  4091. ; pBrush                Pointer to a brush
  4092. ; x                     x-coordinate of the top left of the ellipse
  4093. ; y                     y-coordinate of the top left of the ellipse
  4094. ; w                     width of the ellipse
  4095. ; h                     height of the ellipse
  4096. ;
  4097. ; return                status enumeration. 0 = success
  4098.  
  4099. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  4100. {
  4101.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4102.    
  4103.     return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h)
  4104. }
  4105.  
  4106. •;#####################################################################################
  4107.  
  4108. ; Function              Gdip_FillRegion
  4109. ; Description           This function uses a brush to fill a region in the Graphics of a bitmap
  4110. ;
  4111. ; pGraphics             Pointer to the Graphics of a bitmap
  4112. ; pBrush                Pointer to a brush
  4113. ; Region                Pointer to a Region
  4114. ;
  4115. ; return                status enumeration. 0 = success
  4116. ;
  4117. ; notes                 You can create a region Gdip_CreateRegion() and then add to this
  4118.  
  4119. Gdip_FillRegion(pGraphics, pBrush, Region)
  4120. {
  4121.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4122.    
  4123.     return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region)
  4124. }
  4125.  
  4126. •;#####################################################################################
  4127.  
  4128. ; Function              Gdip_FillPath
  4129. ; Description           This function uses a brush to fill a path in the Graphics of a bitmap
  4130. ;
  4131. ; pGraphics             Pointer to the Graphics of a bitmap
  4132. ; pBrush                Pointer to a brush
  4133. ; Region                Pointer to a Path
  4134. ;
  4135. ; return                status enumeration. 0 = success
  4136.  
  4137. Gdip_FillPath(pGraphics, pBrush, Path)
  4138. {
  4139.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4140.    
  4141.     return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path)
  4142. }
  4143.  
  4144. •;#####################################################################################
  4145.  
  4146. ; Function              Gdip_DrawImagePointsRect
  4147. ; Description           This function draws a bitmap into the Graphics of another bitmap and skews it
  4148. ;
  4149. ; pGraphics             Pointer to the Graphics of a bitmap
  4150. ; pBitmap               Pointer to a bitmap to be drawn
  4151. ; Points                Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  4152. ; sx                    x-coordinate of source upper-left corner
  4153. ; sy                    y-coordinate of source upper-left corner
  4154. ; sw                    width of source rectangle
  4155. ; sh                    height of source rectangle
  4156. ; Matrix                a matrix used to alter image attributes when drawing
  4157. ;
  4158. ; return                status enumeration. 0 = success
  4159. ;
  4160. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  4161. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  4162. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  4163. ;                       Matrix can be passed as a matrix with any delimiter
  4164.  
  4165. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  4166. {
  4167.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4168.    
  4169.     StringSplit, Points, Points, |
  4170.     VarSetCapacity(PointF, 8*Points0)  
  4171.     Loop, %Points0%
  4172.     {
  4173.         StringSplit, Coord, Points%A_Index%, `,
  4174.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  4175.     }
  4176.  
  4177.     if (Matrix&1 = "")
  4178.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  4179.     else if (Matrix != 1)
  4180.         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")
  4181.        
  4182.     if (sx = "" && sy = "" && sw = "" && sh = "")
  4183.     {
  4184.         sx := 0, sy := 0
  4185.         sw := Gdip_GetImageWidth(pBitmap)
  4186.         sh := Gdip_GetImageHeight(pBitmap)
  4187.     }
  4188.  
  4189.     E := DllCall("gdiplus\GdipDrawImagePointsRect"
  4190.                 , Ptr, pGraphics
  4191.                 , Ptr, pBitmap
  4192.                 , Ptr, &PointF
  4193.                 , "int", Points0
  4194.                 , "float", sx
  4195.                 , "float", sy
  4196.                 , "float", sw
  4197.                 , "float", sh
  4198.                 , "int", 2
  4199.                 , Ptr, ImageAttr
  4200.                 , Ptr, 0
  4201.                 , Ptr, 0)
  4202.     if ImageAttr
  4203.         Gdip_DisposeImageAttributes(ImageAttr)
  4204.     return E
  4205. }
  4206.  
  4207. •;#####################################################################################
  4208.  
  4209. ; Function              Gdip_DrawImage
  4210. ; Description           This function draws a bitmap into the Graphics of another bitmap
  4211. ;
  4212. ; pGraphics             Pointer to the Graphics of a bitmap
  4213. ; pBitmap               Pointer to a bitmap to be drawn
  4214. ; dx                    x-coord of destination upper-left corner
  4215. ; dy                    y-coord of destination upper-left corner
  4216. ; dw                    width of destination image
  4217. ; dh                    height of destination image
  4218. ; sx                    x-coordinate of source upper-left corner
  4219. ; sy                    y-coordinate of source upper-left corner
  4220. ; sw                    width of source image
  4221. ; sh                    height of source image
  4222. ; Matrix                a matrix used to alter image attributes when drawing
  4223. ;
  4224. ; return                status enumeration. 0 = success
  4225. ;
  4226. ; notes                 if sx,sy,sw,sh are missed then the entire source bitmap will be used
  4227. ;                       Gdip_DrawImage performs faster
  4228. ;                       Matrix can be omitted to just draw with no alteration to ARGB
  4229. ;                       Matrix may be passed as a digit from 0 - 1 to change just transparency
  4230. ;                       Matrix can be passed as a matrix with any delimiter. For example:
  4231. ;                       MatrixBright=
  4232. ;                       (
  4233. ;                       1.5     |0      |0      |0      |0
  4234. ;                       0       |1.5    |0      |0      |0
  4235. ;                       0       |0      |1.5    |0      |0
  4236. ;                       0       |0      |0      |1      |0
  4237. ;                       0.05    |0.05   |0.05   |0      |1
  4238. ;                       )
  4239. ;
  4240. ; 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
  4241. ;                       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
  4242. ;                       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
  4243.  
  4244. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  4245. {
  4246.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4247.    
  4248.     if (Matrix&1 = "")
  4249.         ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  4250.     else if (Matrix != 1)
  4251.         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")
  4252.  
  4253.     if (sx = "" && sy = "" && sw = "" && sh = "")
  4254.     {
  4255.         if (dx = "" && dy = "" && dw = "" && dh = "")
  4256.         {
  4257.             sx := dx := 0, sy := dy := 0
  4258.             sw := dw := Gdip_GetImageWidth(pBitmap)
  4259.             sh := dh := Gdip_GetImageHeight(pBitmap)
  4260.         }
  4261.         else
  4262.         {
  4263.             sx := sy := 0
  4264.             sw := Gdip_GetImageWidth(pBitmap)
  4265.             sh := Gdip_GetImageHeight(pBitmap)
  4266.         }
  4267.     }
  4268.  
  4269.     E := DllCall("gdiplus\GdipDrawImageRectRect"
  4270.                 , Ptr, pGraphics
  4271.                 , Ptr, pBitmap
  4272.                 , "float", dx
  4273.                 , "float", dy
  4274.                 , "float", dw
  4275.                 , "float", dh
  4276.                 , "float", sx
  4277.                 , "float", sy
  4278.                 , "float", sw
  4279.                 , "float", sh
  4280.                 , "int", 2
  4281.                 , Ptr, ImageAttr
  4282.                 , Ptr, 0
  4283.                 , Ptr, 0)
  4284.     if ImageAttr
  4285.         Gdip_DisposeImageAttributes(ImageAttr)
  4286.     return E
  4287. }
  4288.  
  4289. •;#####################################################################################
  4290.  
  4291. ; Function              Gdip_SetImageAttributesColorMatrix
  4292. ; Description           This function creates an image matrix ready for drawing
  4293. ;
  4294. ; Matrix                a matrix used to alter image attributes when drawing
  4295. ;                       passed with any delimeter
  4296. ;
  4297. ; return                returns an image matrix on sucess or 0 if it fails
  4298. ;
  4299. ; 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
  4300. ;                       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
  4301. ;                       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
  4302.  
  4303. Gdip_SetImageAttributesColorMatrix(Matrix)
  4304. {
  4305.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4306.    
  4307.     VarSetCapacity(ColourMatrix, 100, 0)
  4308.     Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  4309.     StringSplit, Matrix, Matrix, |
  4310.     Loop, 25
  4311.     {
  4312.         Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  4313.         NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  4314.     }
  4315.     DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr)
  4316.     DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0)
  4317.     return ImageAttr
  4318. }
  4319.  
  4320. •;#####################################################################################
  4321.  
  4322. ; Function              Gdip_GraphicsFromImage
  4323. ; Description           This function gets the graphics for a bitmap used for drawing functions
  4324. ;
  4325. ; pBitmap               Pointer to a bitmap to get the pointer to its graphics
  4326. ;
  4327. ; return                returns a pointer to the graphics of a bitmap
  4328. ;
  4329. ; notes                 a bitmap can be drawn into the graphics of another bitmap
  4330.  
  4331. Gdip_GraphicsFromImage(pBitmap)
  4332. {
  4333.     DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  4334.     return pGraphics
  4335. }
  4336.  
  4337. •;#####################################################################################
  4338.  
  4339. ; Function              Gdip_GraphicsFromHDC
  4340. ; Description           This function gets the graphics from the handle to a device context
  4341. ;
  4342. ; hdc                   This is the handle to the device context
  4343. ;
  4344. ; return                returns a pointer to the graphics of a bitmap
  4345. ;
  4346. ; notes                 You can draw a bitmap into the graphics of another bitmap
  4347.  
  4348. Gdip_GraphicsFromHDC(hdc)
  4349. {
  4350.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  4351.     return pGraphics
  4352. }
  4353.  
  4354. •;#####################################################################################
  4355.  
  4356. ; Function              Gdip_GetDC
  4357. ; Description           This function gets the device context of the passed Graphics
  4358. ;
  4359. ; hdc                   This is the handle to the device context
  4360. ;
  4361. ; return                returns the device context for the graphics of a bitmap
  4362.  
  4363. Gdip_GetDC(pGraphics)
  4364. {
  4365.     DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc)
  4366.     return hdc
  4367. }
  4368.  
  4369. •;#####################################################################################
  4370.  
  4371. ; Function              Gdip_ReleaseDC
  4372. ; Description           This function releases a device context from use for further use
  4373. ;
  4374. ; pGraphics             Pointer to the graphics of a bitmap
  4375. ; hdc                   This is the handle to the device context
  4376. ;
  4377. ; return                status enumeration. 0 = success
  4378.  
  4379. Gdip_ReleaseDC(pGraphics, hdc)
  4380. {
  4381.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4382.    
  4383.     return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc)
  4384. }
  4385.  
  4386. •;#####################################################################################
  4387.  
  4388. ; Function              Gdip_GraphicsClear
  4389. ; Description           Clears the graphics of a bitmap ready for further drawing
  4390. ;
  4391. ; pGraphics             Pointer to the graphics of a bitmap
  4392. ; ARGB                  The colour to clear the graphics to
  4393. ;
  4394. ; return                status enumeration. 0 = success
  4395. ;
  4396. ; notes                 By default this will make the background invisible
  4397. ;                       Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  4398.  
  4399. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  4400. {
  4401.     return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB)
  4402. }
  4403.  
  4404. •;#####################################################################################
  4405.  
  4406. ; Function              Gdip_BlurBitmap
  4407. ; Description           Gives a pointer to a blurred bitmap from a pointer to a bitmap
  4408. ;
  4409. ; pBitmap               Pointer to a bitmap to be blurred
  4410. ; Blur                  The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  4411. ;
  4412. ; return                If the function succeeds, the return value is a pointer to the new blurred bitmap
  4413. ;                       -1 = The blur parameter is outside the range 1-100
  4414. ;
  4415. ; notes                 This function will not dispose of the original bitmap
  4416.  
  4417. Gdip_BlurBitmap(pBitmap, Blur)
  4418. {
  4419.     if (Blur > 100) || (Blur < 1)
  4420.         return -1  
  4421.    
  4422.     sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  4423.     dWidth := sWidth//Blur, dHeight := sHeight//Blur
  4424.  
  4425.     pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  4426.     G1 := Gdip_GraphicsFromImage(pBitmap1)
  4427.     Gdip_SetInterpolationMode(G1, 7)
  4428.     Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  4429.  
  4430.     Gdip_DeleteGraphics(G1)
  4431.  
  4432.     pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  4433.     G2 := Gdip_GraphicsFromImage(pBitmap2)
  4434.     Gdip_SetInterpolationMode(G2, 7)
  4435.     Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  4436.  
  4437.     Gdip_DeleteGraphics(G2)
  4438.     Gdip_DisposeImage(pBitmap1)
  4439.     return pBitmap2
  4440. }
  4441.  
  4442. •;#####################################################################################
  4443.  
  4444. ; Function:             Gdip_SaveBitmapToFile
  4445. ; Description:          Saves a bitmap to a file in any supported format onto disk
  4446. ;  
  4447. ; pBitmap               Pointer to a bitmap
  4448. ; 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
  4449. ; Quality               If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  4450. ;
  4451. ; return                If the function succeeds, the return value is zero, otherwise:
  4452. ;                       -1 = Extension supplied is not a supported file format
  4453. ;                       -2 = Could not get a list of encoders on system
  4454. ;                       -3 = Could not find matching encoder for specified file format
  4455. ;                       -4 = Could not get WideChar name of output file
  4456. ;                       -5 = Could not save file to disk
  4457. ;
  4458. ; notes                 This function will use the extension supplied from the sOutput parameter to determine the output format
  4459.  
  4460. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75)
  4461. {
  4462.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4463.    
  4464.     SplitPath, sOutput,,, Extension
  4465.     if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  4466.         return -1
  4467.     Extension := "." Extension
  4468.  
  4469.     DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  4470.     VarSetCapacity(ci, nSize)
  4471.     DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci)
  4472.     if !(nCount && nSize)
  4473.         return -2
  4474.    
  4475.     If (A_IsUnicode){
  4476.         StrGet_Name := "StrGet"
  4477.         Loop, %nCount%
  4478.         {
  4479.             sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16")
  4480.             if !InStr(sString, "*" Extension)
  4481.                 continue
  4482.            
  4483.             pCodec := &ci+idx
  4484.             break
  4485.         }
  4486.     } else {
  4487.         Loop, %nCount%
  4488.         {
  4489.             Location := NumGet(ci, 76*(A_Index-1)+44)
  4490.             nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  4491.             VarSetCapacity(sString, nSize)
  4492.             DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  4493.             if !InStr(sString, "*" Extension)
  4494.                 continue
  4495.            
  4496.             pCodec := &ci+76*(A_Index-1)
  4497.             break
  4498.         }
  4499.     }
  4500.    
  4501.     if !pCodec
  4502.         return -3
  4503.  
  4504.     if (Quality != 75)
  4505.     {
  4506.         Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  4507.         if Extension in .JPG,.JPEG,.JPE,.JFIF
  4508.         {
  4509.             DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize)
  4510.             VarSetCapacity(EncoderParameters, nSize, 0)
  4511.             DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters)
  4512.             Loop, % NumGet(EncoderParameters, "UInt")      ;%
  4513.             {
  4514.                 elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0)
  4515.                 if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6)
  4516.                 {
  4517.                     p := elem+&EncoderParameters-pad-4
  4518.                     NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt")
  4519.                     break
  4520.                 }
  4521.             }      
  4522.         }
  4523.     }
  4524.  
  4525.     if (!A_IsUnicode)
  4526.     {
  4527.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0)
  4528.         VarSetCapacity(wOutput, nSize*2)
  4529.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize)
  4530.         VarSetCapacity(wOutput, -1)
  4531.         if !VarSetCapacity(wOutput)
  4532.             return -4
  4533.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0)
  4534.     }
  4535.     else
  4536.         E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0)
  4537.     return E ? -5 : 0
  4538. }
  4539.  
  4540. •;#####################################################################################
  4541.  
  4542. ; Function              Gdip_GetPixel
  4543. ; Description           Gets the ARGB of a pixel in a bitmap
  4544. ;
  4545. ; pBitmap               Pointer to a bitmap
  4546. ; x                     x-coordinate of the pixel
  4547. ; y                     y-coordinate of the pixel
  4548. ;
  4549. ; return                Returns the ARGB value of the pixel
  4550.  
  4551. Gdip_GetPixel(pBitmap, x, y)
  4552. {
  4553.     DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB)
  4554.     return ARGB
  4555. }
  4556.  
  4557. •;#####################################################################################
  4558.  
  4559. ; Function              Gdip_SetPixel
  4560. ; Description           Sets the ARGB of a pixel in a bitmap
  4561. ;
  4562. ; pBitmap               Pointer to a bitmap
  4563. ; x                     x-coordinate of the pixel
  4564. ; y                     y-coordinate of the pixel
  4565. ;
  4566. ; return                status enumeration. 0 = success
  4567.  
  4568. Gdip_SetPixel(pBitmap, x, y, ARGB)
  4569. {
  4570.    return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB)
  4571. }
  4572.  
  4573. •;#####################################################################################
  4574.  
  4575. ; Function              Gdip_GetImageWidth
  4576. ; Description           Gives the width of a bitmap
  4577. ;
  4578. ; pBitmap               Pointer to a bitmap
  4579. ;
  4580. ; return                Returns the width in pixels of the supplied bitmap
  4581.  
  4582. Gdip_GetImageWidth(pBitmap)
  4583. {
  4584.    DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width)
  4585.    return Width
  4586. }
  4587.  
  4588. •;#####################################################################################
  4589.  
  4590. ; Function              Gdip_GetImageHeight
  4591. ; Description           Gives the height of a bitmap
  4592. ;
  4593. ; pBitmap               Pointer to a bitmap
  4594. ;
  4595. ; return                Returns the height in pixels of the supplied bitmap
  4596.  
  4597. Gdip_GetImageHeight(pBitmap)
  4598. {
  4599.    DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height)
  4600.    return Height
  4601. }
  4602.  
  4603. •;#####################################################################################
  4604.  
  4605. ; Function              Gdip_GetDimensions
  4606. ; Description           Gives the width and height of a bitmap
  4607. ;
  4608. ; pBitmap               Pointer to a bitmap
  4609. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  4610. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  4611. ;
  4612. ; return                No return value
  4613. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  4614.  
  4615. Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height)
  4616. {
  4617.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4618.     DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width)
  4619.     DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height)
  4620. }
  4621.  
  4622. •;#####################################################################################
  4623.  
  4624. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  4625. {
  4626.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  4627. }
  4628.  
  4629. •;#####################################################################################
  4630.  
  4631. Gdip_GetImagePixelFormat(pBitmap)
  4632. {
  4633.     DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format)
  4634.     return Format
  4635. }
  4636.  
  4637. •;#####################################################################################
  4638.  
  4639. ; Function              Gdip_GetDpiX
  4640. ; Description           Gives the horizontal dots per inch of the graphics of a bitmap
  4641. ;
  4642. ; pBitmap               Pointer to a bitmap
  4643. ; Width                 ByRef variable. This variable will be set to the width of the bitmap
  4644. ; Height                ByRef variable. This variable will be set to the height of the bitmap
  4645. ;
  4646. ; return                No return value
  4647. ;                       Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  4648.  
  4649. Gdip_GetDpiX(pGraphics)
  4650. {
  4651.     DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix)
  4652.     return Round(dpix)
  4653. }
  4654.  
  4655. •;#####################################################################################
  4656.  
  4657. Gdip_GetDpiY(pGraphics)
  4658. {
  4659.     DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy)
  4660.     return Round(dpiy)
  4661. }
  4662.  
  4663. •;#####################################################################################
  4664.  
  4665. Gdip_GetImageHorizontalResolution(pBitmap)
  4666. {
  4667.     DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix)
  4668.     return Round(dpix)
  4669. }
  4670.  
  4671. •;#####################################################################################
  4672.  
  4673. Gdip_GetImageVerticalResolution(pBitmap)
  4674. {
  4675.     DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy)
  4676.     return Round(dpiy)
  4677. }
  4678.  
  4679. •;#####################################################################################
  4680.  
  4681. Gdip_BitmapSetResolution(pBitmap, dpix, dpiy)
  4682. {
  4683.     return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy)
  4684. }
  4685.  
  4686. •;#####################################################################################
  4687.  
  4688. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  4689. {
  4690.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4691.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  4692.    
  4693.     SplitPath, sFile,,, ext
  4694.     if ext in exe,dll
  4695.     {
  4696.         Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  4697.         BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4))
  4698.        
  4699.         VarSetCapacity(buf, BufSize, 0)
  4700.         Loop, Parse, Sizes, |
  4701.         {
  4702.             DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0)
  4703.            
  4704.             if !hIcon
  4705.                 continue
  4706.  
  4707.             if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf)
  4708.             {
  4709.                 DestroyIcon(hIcon)
  4710.                 continue
  4711.             }
  4712.            
  4713.             hbmMask  := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4))
  4714.             hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4))
  4715.             if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf))
  4716.             {
  4717.                 DestroyIcon(hIcon)
  4718.                 continue
  4719.             }
  4720.             break
  4721.         }
  4722.         if !hIcon
  4723.             return -1
  4724.  
  4725.         Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int")
  4726.         hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  4727.         if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3)
  4728.         {
  4729.             DestroyIcon(hIcon)
  4730.             return -2
  4731.         }
  4732.        
  4733.         VarSetCapacity(dib, 104)
  4734.         DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize
  4735.         Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding
  4736.         DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld)
  4737.         pBitmap := Gdip_CreateBitmap(Width, Height)
  4738.         G := Gdip_GraphicsFromImage(pBitmap)
  4739.         , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  4740.         SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  4741.         Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  4742.         DestroyIcon(hIcon)
  4743.     }
  4744.     else
  4745.     {
  4746.         if (!A_IsUnicode)
  4747.         {
  4748.             VarSetCapacity(wFile, 1024)
  4749.             DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512)
  4750.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap)
  4751.         }
  4752.         else
  4753.             DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap)
  4754.     }
  4755.    
  4756.     return pBitmap
  4757. }
  4758.  
  4759. •;#####################################################################################
  4760.  
  4761. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  4762. {
  4763.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4764.    
  4765.     DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  4766.     return pBitmap
  4767. }
  4768.  
  4769. •;#####################################################################################
  4770.  
  4771. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  4772. {
  4773.     DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background)
  4774.     return hbm
  4775. }
  4776.  
  4777. •;#####################################################################################
  4778.  
  4779. Gdip_CreateBitmapFromHICON(hIcon)
  4780. {
  4781.     DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  4782.     return pBitmap
  4783. }
  4784.  
  4785. •;#####################################################################################
  4786.  
  4787. Gdip_CreateHICONFromBitmap(pBitmap)
  4788. {
  4789.     DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon)
  4790.     return hIcon
  4791. }
  4792.  
  4793. •;#####################################################################################
  4794.  
  4795. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  4796. {
  4797.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap)
  4798.     Return pBitmap
  4799. }
  4800.  
  4801. •;#####################################################################################
  4802.  
  4803. Gdip_CreateBitmapFromClipboard()
  4804. {
  4805.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4806.    
  4807.     if !DllCall("OpenClipboard", Ptr, 0)
  4808.         return -1
  4809.     if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  4810.         return -2
  4811.     if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr)
  4812.         return -3
  4813.     if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  4814.         return -4
  4815.     if !DllCall("CloseClipboard")
  4816.         return -5
  4817.     DeleteObject(hBitmap)
  4818.     return pBitmap
  4819. }
  4820.  
  4821. •;#####################################################################################
  4822.  
  4823. Gdip_SetBitmapToClipboard(pBitmap)
  4824. {
  4825.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4826.     off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24
  4827.     hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  4828.     DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi)
  4829.     hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr)
  4830.     pdib := DllCall("GlobalLock", Ptr, hdib, Ptr)
  4831.     DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40)
  4832.     DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt"))
  4833.     DllCall("GlobalUnlock", Ptr, hdib)
  4834.     DllCall("DeleteObject", Ptr, hBitmap)
  4835.     DllCall("OpenClipboard", Ptr, 0)
  4836.     DllCall("EmptyClipboard")
  4837.     DllCall("SetClipboardData", "uint", 8, Ptr, hdib)
  4838.     DllCall("CloseClipboard")
  4839. }
  4840.  
  4841. •;#####################################################################################
  4842.  
  4843. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  4844. {
  4845.     DllCall("gdiplus\GdipCloneBitmapArea"
  4846.                     , "float", x
  4847.                     , "float", y
  4848.                     , "float", w
  4849.                     , "float", h
  4850.                     , "int", Format
  4851.                     , A_PtrSize ? "UPtr" : "UInt", pBitmap
  4852.                     , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest)
  4853.     return pBitmapDest
  4854. }
  4855.  
  4856. •;#####################################################################################
  4857.  
  4858. Gdip_CreatePen(ARGB, w)
  4859. {
  4860.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  4861.    return pPen
  4862. }
  4863.  
  4864. •;#####################################################################################
  4865.  
  4866. Gdip_CreatePenFromBrush(pBrush, w)
  4867. {
  4868.     DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  4869.     return pPen
  4870. }
  4871.  
  4872. •;#####################################################################################
  4873.  
  4874. Gdip_BrushCreateSolid(ARGB=0xff000000)
  4875. {
  4876.     DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  4877.     return pBrush
  4878. }
  4879.  
  4880. •;#####################################################################################
  4881.  
  4882. ; HatchStyleHorizontal = 0
  4883. ; HatchStyleVertical = 1
  4884. ; HatchStyleForwardDiagonal = 2
  4885. ; HatchStyleBackwardDiagonal = 3
  4886. ; HatchStyleCross = 4
  4887. ; HatchStyleDiagonalCross = 5
  4888. ; HatchStyle05Percent = 6
  4889. ; HatchStyle10Percent = 7
  4890. ; HatchStyle20Percent = 8
  4891. ; HatchStyle25Percent = 9
  4892. ; HatchStyle30Percent = 10
  4893. ; HatchStyle40Percent = 11
  4894. ; HatchStyle50Percent = 12
  4895. ; HatchStyle60Percent = 13
  4896. ; HatchStyle70Percent = 14
  4897. ; HatchStyle75Percent = 15
  4898. ; HatchStyle80Percent = 16
  4899. ; HatchStyle90Percent = 17
  4900. ; HatchStyleLightDownwardDiagonal = 18
  4901. ; HatchStyleLightUpwardDiagonal = 19
  4902. ; HatchStyleDarkDownwardDiagonal = 20
  4903. ; HatchStyleDarkUpwardDiagonal = 21
  4904. ; HatchStyleWideDownwardDiagonal = 22
  4905. ; HatchStyleWideUpwardDiagonal = 23
  4906. ; HatchStyleLightVertical = 24
  4907. ; HatchStyleLightHorizontal = 25
  4908. ; HatchStyleNarrowVertical = 26
  4909. ; HatchStyleNarrowHorizontal = 27
  4910. ; HatchStyleDarkVertical = 28
  4911. ; HatchStyleDarkHorizontal = 29
  4912. ; HatchStyleDashedDownwardDiagonal = 30
  4913. ; HatchStyleDashedUpwardDiagonal = 31
  4914. ; HatchStyleDashedHorizontal = 32
  4915. ; HatchStyleDashedVertical = 33
  4916. ; HatchStyleSmallConfetti = 34
  4917. ; HatchStyleLargeConfetti = 35
  4918. ; HatchStyleZigZag = 36
  4919. ; HatchStyleWave = 37
  4920. ; HatchStyleDiagonalBrick = 38
  4921. ; HatchStyleHorizontalBrick = 39
  4922. ; HatchStyleWeave = 40
  4923. ; HatchStylePlaid = 41
  4924. ; HatchStyleDivot = 42
  4925. ; HatchStyleDottedGrid = 43
  4926. ; HatchStyleDottedDiamond = 44
  4927. ; HatchStyleShingle = 45
  4928. ; HatchStyleTrellis = 46
  4929. ; HatchStyleSphere = 47
  4930. ; HatchStyleSmallGrid = 48
  4931. ; HatchStyleSmallCheckerBoard = 49
  4932. ; HatchStyleLargeCheckerBoard = 50
  4933. ; HatchStyleOutlinedDiamond = 51
  4934. ; HatchStyleSolidDiamond = 52
  4935. ; HatchStyleTotal = 53
  4936. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  4937. {
  4938.     DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush)
  4939.     return pBrush
  4940. }
  4941.  
  4942. •;#####################################################################################
  4943.  
  4944. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  4945. {
  4946.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4947.     , PtrA := A_PtrSize ? "UPtr*" : "UInt*"
  4948.    
  4949.     if !(w && h)
  4950.         DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush)
  4951.     else
  4952.         DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush)
  4953.     return pBrush
  4954. }
  4955.  
  4956. •;#####################################################################################
  4957.  
  4958. ; WrapModeTile = 0
  4959. ; WrapModeTileFlipX = 1
  4960. ; WrapModeTileFlipY = 2
  4961. ; WrapModeTileFlipXY = 3
  4962. ; WrapModeClamp = 4
  4963. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  4964. {
  4965.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  4966.    
  4967.     CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  4968.     DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  4969.     return LGpBrush
  4970. }
  4971.  
  4972. •;#####################################################################################
  4973.  
  4974. ; LinearGradientModeHorizontal = 0
  4975. ; LinearGradientModeVertical = 1
  4976. ; LinearGradientModeForwardDiagonal = 2
  4977. ; LinearGradientModeBackwardDiagonal = 3
  4978. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  4979. {
  4980.     CreateRectF(RectF, x, y, w, h)
  4981.     DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush)
  4982.     return LGpBrush
  4983. }
  4984.  
  4985. •;#####################################################################################
  4986.  
  4987. Gdip_CloneBrush(pBrush)
  4988. {
  4989.     DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone)
  4990.     return pBrushClone
  4991. }
  4992.  
  4993. •;#####################################################################################
  4994.  
  4995. Gdip_DeletePen(pPen)
  4996. {
  4997.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  4998. }
  4999.  
  5000. •;#####################################################################################
  5001.  
  5002. Gdip_DeleteBrush(pBrush)
  5003. {
  5004.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  5005. }
  5006.  
  5007. •;#####################################################################################
  5008.  
  5009. Gdip_DisposeImage(pBitmap)
  5010. {
  5011.    return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap)
  5012. }
  5013.  
  5014. •;#####################################################################################
  5015.  
  5016. Gdip_DeleteGraphics(pGraphics)
  5017. {
  5018.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  5019. }
  5020.  
  5021. •;#####################################################################################
  5022.  
  5023. Gdip_DisposeImageAttributes(ImageAttr)
  5024. {
  5025.     return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr)
  5026. }
  5027.  
  5028. •;#####################################################################################
  5029.  
  5030. Gdip_DeleteFont(hFont)
  5031. {
  5032.    return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont)
  5033. }
  5034.  
  5035. •;#####################################################################################
  5036.  
  5037. Gdip_DeleteStringFormat(hFormat)
  5038. {
  5039.    return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat)
  5040. }
  5041.  
  5042. •;#####################################################################################
  5043.  
  5044. Gdip_DeleteFontFamily(hFamily)
  5045. {
  5046.    return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily)
  5047. }
  5048.  
  5049. •;#####################################################################################
  5050.  
  5051. Gdip_DeleteMatrix(Matrix)
  5052. {
  5053.    return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix)
  5054. }
  5055.  
  5056. •;#####################################################################################
  5057.  
  5058. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  5059. {
  5060.     IWidth := Width, IHeight:= Height
  5061.    
  5062.     RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  5063.     RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  5064.     RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  5065.     RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  5066.     RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  5067.     RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  5068.     RegExMatch(Options, "i)NoWrap", NoWrap)
  5069.     RegExMatch(Options, "i)R(\d)", Rendering)
  5070.     RegExMatch(Options, "i)S(\d+)(p*)", Size)
  5071.  
  5072.     if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  5073.         PassBrush := 1, pBrush := Colour2
  5074.    
  5075.     if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  5076.         return -1
  5077.  
  5078.     Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  5079.     Loop, Parse, Styles, |
  5080.     {
  5081.         if RegExMatch(Options, "\b" A_loopField)
  5082.         Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  5083.     }
  5084.  
  5085.     Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  5086.     Loop, Parse, Alignments, |
  5087.     {
  5088.         if RegExMatch(Options, "\b" A_loopField)
  5089.             Align |= A_Index//2.1      ; 0|0|1|1|2|2
  5090.     }
  5091.  
  5092.     xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  5093.     ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  5094.     Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  5095.     Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  5096.     if !PassBrush
  5097.         Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  5098.     Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  5099.     Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  5100.  
  5101.     hFamily := Gdip_FontFamilyCreate(Font)
  5102.     hFont := Gdip_FontCreate(hFamily, Size, Style)
  5103.     FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000
  5104.     hFormat := Gdip_StringFormatCreate(FormatStyle)
  5105.     pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  5106.     if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  5107.         return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  5108.    
  5109.     CreateRectF(RC, xpos, ypos, Width, Height)
  5110.     Gdip_SetStringFormatAlign(hFormat, Align)
  5111.     Gdip_SetTextRenderingHint(pGraphics, Rendering)
  5112.     ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  5113.  
  5114.     if vPos
  5115.     {
  5116.         StringSplit, ReturnRC, ReturnRC, |
  5117.        
  5118.         if (vPos = "vCentre") || (vPos = "vCenter")
  5119.             ypos += (Height-ReturnRC4)//2
  5120.         else if (vPos = "Top") || (vPos = "Up")
  5121.             ypos := 0
  5122.         else if (vPos = "Bottom") || (vPos = "Down")
  5123.             ypos := Height-ReturnRC4
  5124.        
  5125.         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  5126.         ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  5127.     }
  5128.  
  5129.     if !Measure
  5130.         E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  5131.  
  5132.     if !PassBrush
  5133.         Gdip_DeleteBrush(pBrush)
  5134.     Gdip_DeleteStringFormat(hFormat)  
  5135.     Gdip_DeleteFont(hFont)
  5136.     Gdip_DeleteFontFamily(hFamily)
  5137.     return E ? E : ReturnRC
  5138. }
  5139.  
  5140. •;#####################################################################################
  5141.  
  5142. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  5143. {
  5144.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5145.    
  5146.     if (!A_IsUnicode)
  5147.     {
  5148.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0)
  5149.         VarSetCapacity(wString, nSize*2)
  5150.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  5151.     }
  5152.    
  5153.     return DllCall("gdiplus\GdipDrawString"
  5154.                     , Ptr, pGraphics
  5155.                     , Ptr, A_IsUnicode ? &sString : &wString
  5156.                     , "int", -1
  5157.                     , Ptr, hFont
  5158.                     , Ptr, &RectF
  5159.                     , Ptr, hFormat
  5160.                     , Ptr, pBrush)
  5161. }
  5162.  
  5163. •;#####################################################################################
  5164.  
  5165. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  5166. {
  5167.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5168.    
  5169.     VarSetCapacity(RC, 16)
  5170.     if !A_IsUnicode
  5171.     {
  5172.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0)
  5173.         VarSetCapacity(wString, nSize*2)  
  5174.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize)
  5175.     }
  5176.    
  5177.     DllCall("gdiplus\GdipMeasureString"
  5178.                     , Ptr, pGraphics
  5179.                     , Ptr, A_IsUnicode ? &sString : &wString
  5180.                     , "int", -1
  5181.                     , Ptr, hFont
  5182.                     , Ptr, &RectF
  5183.                     , Ptr, hFormat
  5184.                     , Ptr, &RC
  5185.                     , "uint*", Chars
  5186.                     , "uint*", Lines)
  5187.    
  5188.     return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  5189. }
  5190. •;#####################################################################################
  5191. ; Near = 0
  5192. ; Center = 1
  5193. ; Far = 2
  5194. Gdip_SetStringFormatAlign(hFormat, Align)
  5195. {
  5196.    return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align)
  5197. }
  5198. •;#####################################################################################
  5199. ; StringFormatFlagsDirectionRightToLeft    = 0x00000001
  5200. ; StringFormatFlagsDirectionVertical       = 0x00000002
  5201. ; StringFormatFlagsNoFitBlackBox           = 0x00000004
  5202. ; StringFormatFlagsDisplayFormatControl    = 0x00000020
  5203. ; StringFormatFlagsNoFontFallback          = 0x00000400
  5204. ; StringFormatFlagsMeasureTrailingSpaces   = 0x00000800
  5205. ; StringFormatFlagsNoWrap                  = 0x00001000
  5206. ; StringFormatFlagsLineLimit               = 0x00002000
  5207. ; StringFormatFlagsNoClip                  = 0x00004000
  5208. Gdip_StringFormatCreate(Format=0, Lang=0)
  5209. {
  5210.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat)
  5211.    return hFormat
  5212. }
  5213. •;#####################################################################################
  5214. ; Regular = 0
  5215. ; Bold = 1
  5216. ; Italic = 2
  5217. ; BoldItalic = 3
  5218. ; Underline = 4
  5219. ; Strikeout = 8
  5220. Gdip_FontCreate(hFamily, Size, Style=0)
  5221. {
  5222.    DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont)
  5223.    return hFont
  5224. }
  5225. •;#####################################################################################
  5226. Gdip_FontFamilyCreate(Font)
  5227. {
  5228.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5229.    
  5230.     if (!A_IsUnicode)
  5231.     {
  5232.         nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0)
  5233.         VarSetCapacity(wFont, nSize*2)
  5234.         DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize)
  5235.     }
  5236.    
  5237.     DllCall("gdiplus\GdipCreateFontFamilyFromName"
  5238.                     , Ptr, A_IsUnicode ? &Font : &wFont
  5239.                     , "uint", 0
  5240.                     , A_PtrSize ? "UPtr*" : "UInt*", hFamily)
  5241.    
  5242.     return hFamily
  5243. }
  5244.  
  5245. •;#####################################################################################
  5246.  
  5247. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  5248. {
  5249.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  5250.    return Matrix
  5251. }
  5252. •;#####################################################################################
  5253. Gdip_CreateMatrix()
  5254. {
  5255.    DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix)
  5256.    return Matrix
  5257. }
  5258.  
  5259. •;#####################################################################################
  5260.  
  5261. ; Alternate = 0
  5262. ; Winding = 1
  5263. Gdip_CreatePath(BrushMode=0)
  5264. {
  5265.     DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path)
  5266.     return Path
  5267. }
  5268. •;#####################################################################################
  5269. Gdip_AddPathEllipse(Path, x, y, w, h)
  5270. {
  5271.     return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h)
  5272. }
  5273. •;#####################################################################################
  5274. Gdip_AddPathPolygon(Path, Points)
  5275. {
  5276.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5277.    
  5278.     StringSplit, Points, Points, |
  5279.     VarSetCapacity(PointF, 8*Points0)  
  5280.     Loop, %Points0%
  5281.     {
  5282.         StringSplit, Coord, Points%A_Index%, `,
  5283.         NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  5284.     }  
  5285.  
  5286.     return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0)
  5287. }
  5288. •;#####################################################################################
  5289. Gdip_DeletePath(Path)
  5290. {
  5291.     return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path)
  5292. }
  5293.  
  5294. •;#####################################################################################
  5295.  
  5296. ; SystemDefault = 0
  5297. ; SingleBitPerPixelGridFit = 1
  5298. ; SingleBitPerPixel = 2
  5299. ; AntiAliasGridFit = 3
  5300. ; AntiAlias = 4
  5301. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  5302. {
  5303.     return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint)
  5304. }
  5305. •;#####################################################################################
  5306. ; Default = 0
  5307. ; LowQuality = 1
  5308. ; HighQuality = 2
  5309. ; Bilinear = 3
  5310. ; Bicubic = 4
  5311. ; NearestNeighbor = 5
  5312. ; HighQualityBilinear = 6
  5313. ; HighQualityBicubic = 7
  5314. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  5315. {
  5316.    return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode)
  5317. }
  5318. •;#####################################################################################
  5319. ; Default = 0
  5320. ; HighSpeed = 1
  5321. ; HighQuality = 2
  5322. ; None = 3
  5323. ; AntiAlias = 4
  5324. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  5325. {
  5326.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  5327. }
  5328. •;#####################################################################################
  5329. ; CompositingModeSourceOver = 0 (blended)
  5330. ; CompositingModeSourceCopy = 1 (overwrite)
  5331. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  5332. {
  5333.    return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode)
  5334. }
  5335.  
  5336. •;#####################################################################################
  5337.  
  5338. Gdip_Startup()
  5339. {
  5340.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5341.    
  5342.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  5343.         DllCall("LoadLibrary", "str", "gdiplus")
  5344.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  5345.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  5346.     return pToken
  5347. }
  5348. •;#####################################################################################
  5349. Gdip_Shutdown(pToken)
  5350. {
  5351.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5352.    
  5353.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  5354.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  5355.         DllCall("FreeLibrary", Ptr, hModule)
  5356.     return 0
  5357. }
  5358. •;#####################################################################################
  5359. ; Prepend = 0; The new operation is applied before the old operation.
  5360. ; Append = 1; The new operation is applied after the old operation.
  5361. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  5362. {
  5363.     return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder)
  5364. }
  5365. •;#####################################################################################
  5366. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  5367. {
  5368.     return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  5369. }
  5370. •;#####################################################################################
  5371. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  5372. {
  5373.     return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  5374. }
  5375. •;#####################################################################################
  5376. Gdip_ResetWorldTransform(pGraphics)
  5377. {
  5378.     return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  5379. }
  5380. •;#####################################################################################
  5381. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  5382. {
  5383.     pi := 3.14159, TAngle := Angle*(pi/180)
  5384.  
  5385.     Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  5386.     if ((Bound >= 0) && (Bound <= 90))
  5387.         xTranslation := Height*Sin(TAngle), yTranslation := 0
  5388.     else if ((Bound > 90) && (Bound <= 180))
  5389.         xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  5390.     else if ((Bound > 180) && (Bound <= 270))
  5391.         xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  5392.     else if ((Bound > 270) && (Bound <= 360))
  5393.         xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  5394. }
  5395. •;#####################################################################################
  5396. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  5397. {
  5398.     pi := 3.14159, TAngle := Angle*(pi/180)
  5399.     if !(Width && Height)
  5400.         return -1
  5401.     RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  5402.     RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  5403. }
  5404. •;#####################################################################################
  5405. ; RotateNoneFlipNone   = 0
  5406. ; Rotate90FlipNone     = 1
  5407. ; Rotate180FlipNone    = 2
  5408. ; Rotate270FlipNone    = 3
  5409. ; RotateNoneFlipX      = 4
  5410. ; Rotate90FlipX        = 5
  5411. ; Rotate180FlipX       = 6
  5412. ; Rotate270FlipX       = 7
  5413. ; RotateNoneFlipY      = Rotate180FlipX
  5414. ; Rotate90FlipY        = Rotate270FlipX
  5415. ; Rotate180FlipY       = RotateNoneFlipX
  5416. ; Rotate270FlipY       = Rotate90FlipX
  5417. ; RotateNoneFlipXY     = Rotate180FlipNone
  5418. ; Rotate90FlipXY       = Rotate270FlipNone
  5419. ; Rotate180FlipXY      = RotateNoneFlipNone
  5420. ; Rotate270FlipXY      = Rotate90FlipNone
  5421.  
  5422. Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1)
  5423. {
  5424.     return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType)
  5425. }
  5426. •;#####################################################################################
  5427. ; Replace = 0
  5428. ; Intersect = 1
  5429. ; Union = 2
  5430. ; Xor = 3
  5431. ; Exclude = 4
  5432. ; Complement = 5
  5433. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  5434. {
  5435.    return DllCall("gdiplus\GdipSetClipRect",  A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  5436. }
  5437. •;#####################################################################################
  5438. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  5439. {
  5440.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5441.     return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode)
  5442. }
  5443. •;#####################################################################################
  5444. Gdip_ResetClip(pGraphics)
  5445. {
  5446.    return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  5447. }
  5448. •;#####################################################################################
  5449. Gdip_GetClipRegion(pGraphics)
  5450. {
  5451.     Region := Gdip_CreateRegion()
  5452.     DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region)
  5453.     return Region
  5454. }
  5455. •;#####################################################################################
  5456. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  5457. {
  5458.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5459.    
  5460.     return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode)
  5461. }
  5462. •;#####################################################################################
  5463. Gdip_CreateRegion()
  5464. {
  5465.     DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
  5466.     return Region
  5467. }
  5468. •;#####################################################################################
  5469. Gdip_DeleteRegion(Region)
  5470. {
  5471.     return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region)
  5472. }
  5473.  
  5474. •;#####################################################################################
  5475.  
  5476. Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a)
  5477. {
  5478.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5479.    
  5480.     CreateRect(Rect, x, y, w, h)
  5481.     VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0)
  5482.     E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData)
  5483.     Stride := NumGet(BitmapData, 8, "Int")
  5484.     Scan0 := NumGet(BitmapData, 16, Ptr)
  5485.     return E
  5486. }
  5487.  
  5488. •;#####################################################################################
  5489.  
  5490. Gdip_UnlockBits(pBitmap, ByRef BitmapData)
  5491. {
  5492.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5493.    
  5494.     return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData)
  5495. }
  5496.  
  5497. •;#####################################################################################
  5498.  
  5499. Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride)
  5500. {
  5501.     Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt")
  5502. }
  5503.  
  5504. •;#####################################################################################
  5505.  
  5506. Gdip_GetLockBitPixel(Scan0, x, y, Stride)
  5507. {
  5508.     return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt")
  5509. }
  5510.  
  5511. •;#####################################################################################
  5512.  
  5513. Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize)
  5514. {
  5515.     static PixelateBitmap
  5516.    
  5517.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  5518.    
  5519.     if (!PixelateBitmap)
  5520.     {
  5521.         if A_PtrSize != 8 ; x86 machine code
  5522.         MCode_PixelateBitmap =
  5523.         (LTrim Join
  5524.         558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4
  5525.         397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4
  5526.         8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF
  5527.         4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D
  5528.         C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8
  5529.         8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945
  5530.         148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F
  5531.         B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7
  5532.         F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB
  5533.         038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55
  5534.         1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7
  5535.         FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D
  5536.         D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B
  5537.         45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9
  5538.         89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C
  5539.         0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8
  5540.         75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8
  5541.         8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F
  5542.         B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B
  5543.         451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639
  5544.         75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811
  5545.         8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800
  5546.         )
  5547.         else ; x64 machine code
  5548.         MCode_PixelateBitmap =
  5549.         (LTrim Join
  5550.         4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C
  5551.         448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05
  5552.         4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF
  5553.         C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C
  5554.         24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000
  5555.         004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800
  5556.         0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533
  5557.         DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6
  5558.         024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3
  5559.         99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841
  5560.         8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD
  5561.         4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480
  5562.         000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33
  5563.         ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602
  5564.         4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3
  5565.         99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541
  5566.         8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C
  5567.         2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585
  5568.         FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248
  5569.         83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399
  5570.         F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541
  5571.         0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2
  5572.         413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3
  5573.         )
  5574.        
  5575.         VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2)
  5576.         Loop % StrLen(MCode_PixelateBitmap)//2      ;%
  5577.             NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar")
  5578.         DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0)
  5579.     }
  5580.  
  5581.     Gdip_GetImageDimensions(pBitmap, Width, Height)
  5582.    
  5583.     if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
  5584.         return -1
  5585.     if (BlockSize > Width || BlockSize > Height)
  5586.         return -2
  5587.  
  5588.     E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
  5589.     E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
  5590.     if (E1 || E2)
  5591.         return -3
  5592.  
  5593.     E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize)
  5594.    
  5595.     Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
  5596.     return 0
  5597. }
  5598.  
  5599. •;#####################################################################################
  5600.  
  5601. Gdip_ToARGB(A, R, G, B)
  5602. {
  5603.     return (A << 24) | (R << 16) | (G << 8) | B
  5604. }
  5605.  
  5606. •;#####################################################################################
  5607.  
  5608. Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B)
  5609. {
  5610.     A := (0xff000000 & ARGB) >> 24
  5611.     R := (0x00ff0000 & ARGB) >> 16
  5612.     G := (0x0000ff00 & ARGB) >> 8
  5613.     B := 0x000000ff & ARGB
  5614. }
  5615.  
  5616. •;#####################################################################################
  5617.  
  5618. Gdip_AFromARGB(ARGB)
  5619. {
  5620.     return (0xff000000 & ARGB) >> 24
  5621. }
  5622.  
  5623. •;#####################################################################################
  5624.  
  5625. Gdip_RFromARGB(ARGB)
  5626. {
  5627.     return (0x00ff0000 & ARGB) >> 16
  5628. }
  5629.  
  5630. •;#####################################################################################
  5631.  
  5632. Gdip_GFromARGB(ARGB)
  5633. {
  5634.     return (0x0000ff00 & ARGB) >> 8
  5635. }
  5636.  
  5637. •;#####################################################################################
  5638.  
  5639. Gdip_BFromARGB(ARGB)
  5640. {
  5641.     return 0x000000ff & ARGB
  5642. }
  5643.  
  5644. •;#####################################################################################
  5645.  
  5646. StrGetB(Address, Length=-1, Encoding=0)
  5647. {
  5648.     ; Flexible parameter handling:
  5649.     if Length is not integer
  5650.     Encoding := Length,  Length := -1
  5651.  
  5652.     ; Check for obvious errors.
  5653.     if (Address+0 < 1024)
  5654.         return
  5655.  
  5656.     ; Ensure 'Encoding' contains a numeric identifier.
  5657.     if Encoding = UTF-16
  5658.         Encoding = 1200
  5659.     else if Encoding = UTF-8
  5660.         Encoding = 65001
  5661.     else if SubStr(Encoding,1,2)="CP"
  5662.         Encoding := SubStr(Encoding,3)
  5663.  
  5664.     if !Encoding ; "" or 0
  5665.     {
  5666.         ; No conversion necessary, but we might not want the whole string.
  5667.         if (Length == -1)
  5668.             Length := DllCall("lstrlen", "uint", Address)
  5669.         VarSetCapacity(String, Length)
  5670.         DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1)
  5671.     }
  5672.     else if Encoding = 1200 ; UTF-16
  5673.     {
  5674.         char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0)
  5675.         VarSetCapacity(String, char_count)
  5676.         DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0)
  5677.     }
  5678.     else if Encoding is integer
  5679.     {
  5680.         ; Convert from target encoding to UTF-16 then to the active code page.
  5681.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0)
  5682.         VarSetCapacity(String, char_count * 2)
  5683.         char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2)
  5684.         String := StrGetB(&String, char_count, 1200)
  5685.     }
  5686.    
  5687.     return String
  5688. }
  5689. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement