Advertisement
Guest User

Drawing a rectangle on your screen using your cursor

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