daily pastebin goal
51%
SHARE
TWEET

Untitled

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