Advertisement
Guest User

tut 6

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