Advertisement
Najeebsk

INSTANOTE.ahk

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