Advertisement
pastamaker

tower v1.0

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