Advertisement
Guest User

Untitled

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