Advertisement
Guest User

Untitled

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