Advertisement
pastamaker

gdip 3

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