Advertisement
Najeebsk

SCREEN-CLIP.ahk

May 31st, 2023
1,845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if((A_PtrSize=8&&A_IsCompiled="")||!A_IsUnicode){ ;32 bit=4  ;64 bit=8
  2.     SplitPath,A_AhkPath,,dir
  3.     if(!FileExist(correct:=dir "\AutoHotkeyU32.exe")){
  4.         MsgBox error
  5.         ExitApp
  6.     }
  7.     Run,"%correct%" "%A_ScriptName%",%A_ScriptDir%
  8.     ExitApp
  9.     return
  10. }
  11. ;#NoTrayIcon
  12. ;Menu, tray, icon, AutoRun\camera.ico , 1
  13. #SingleInstance, Force
  14. #^Lbutton::SCW_ScreenClip2Win(clip:=0,email:=0)  ;Win+Control+Left click- no copy to clipboard
  15. #!Lbutton::SCW_ScreenClip2Win(clip:=0,email:=1) ; Wind+Alt+left click =saves images and attach to email (path of jpg on clipboard)
  16. #Lbutton::SCW_ScreenClip2Win(clip:=1,email:=0) ; Win+left click mouse=auto copy to clipboard
  17.  
  18. #IfWinActive, ScreenClippingWindow ahk_class AutoHotkeyGUI
  19. ^c::SCW_Win2Clipboard(0)      ; copy selected win to clipboard  Change to (1) if want border
  20. ^s:: SCW_Win2File(0)  ;save selected clipping on desktop as timestamp named .png  ; this was submited by tervon
  21. Esc:: winclose, A ;contribued by tervon
  22. Rbutton:: winclose, A ;contributed by tervon
  23. #IfWinActive
  24.  
  25.  
  26. ;===Description========================================================================
  27. /*
  28. [module/script] ScreenClip2Win
  29. Author:      Learning one
  30. Thanks:      Tic, HotKeyIt
  31.  
  32. Creates always on top layered windows from screen clippings. Click in upper right corner to close win. Click and drag to move it.
  33. Uses Gdip.ahk by Tic.
  34.  
  35. #Include ScreenClip2Win.ahk      ; by Learning one
  36. ;=== Short documentation ===
  37. SCW_ScreenClip2Win()          ; creates always on top window from screen clipping. Click and drag to select area.
  38. SCW_DestroyAllClipWins()       ; destroys all screen clipping windows.
  39. SCW_Win2Clipboard()            ; copies window to clipboard. By default, removes borders. To keep borders, specify "SCW_Win2Clipboard(1)"
  40. SCW_SetUp(Options="")         ; you can change some default options in Auto-execute part of script. Syntax: "<option>.<value>"
  41.    StartAfter - module will start to consume GUIs for screen clipping windows after specified GUI number. Default: 80
  42.    MaxGuis - maximum number of screen clipping windows. Default: 6
  43.    BorderAColor - Default: ff6666ff (ARGB format)
  44.    BorderBColor - Default: ffffffff (ARGB format)
  45.    DrawCloseButton - on/off draw "Close Button" on screen clipping windows. Default: 0 (off)
  46.    AutoMonitorWM_LBUTTONDOWN - on/off automatic monitoring of WM_LBUTTONDOWN message. Default: 1 (on)
  47.    SelColor - selection color. Default: Yellow
  48.    SelTrans - selection transparency. Default: 80
  49.    
  50.    Example:   SCW_SetUp("MaxGuis.30 StartAfter.50 BorderAColor.ff000000 BorderBColor.ffffff00")
  51.    
  52.  
  53.  
  54. ;=== Avoid OnMessage(0x201, "WM_LBUTTONDOWN") collision example===
  55. Gui, Show, w200 h200
  56. SCW_SetUp("AutoMonitorWM_LBUTTONDOWN.0")   ; turn off auto monitoring WM_LBUTTONDOWN
  57. OnMessage(0x201, "WM_LBUTTONDOWN")   ; manualy monitor WM_LBUTTONDOWN
  58. Return
  59.  
  60. ^Lbutton::SCW_ScreenClip2Win()   ; click & drag
  61. Esc::ExitApp
  62.  
  63. #Include Gdip.ahk      ; by Tic
  64. #Include ScreenClip2Win.ahk      ; by Learning one
  65. WM_LBUTTONDOWN() {
  66.    if SCW_LBUTTONDOWN()   ; LBUTTONDOWN on module's screen clipping windows - isolate - it's module's buissines
  67.    return
  68.    else   ; LBUTTONDOWN on other windows created by script
  69.    MsgBox,,, You clicked on script's window not created by this module,1
  70. }
  71. */
  72.  
  73.  
  74. ;===Functions==========================================================================
  75. SCW_Version() {
  76.    return 1.02
  77. }
  78.  
  79. SCW_DestroyAllClipWins() {
  80.    MaxGuis := SCW_Reg("MaxGuis"), StartAfter := SCW_Reg("StartAfter")
  81.    Loop, %MaxGuis%
  82.    {
  83.       StartAfter++
  84.       Gui %StartAfter%: Destroy
  85.    }
  86. }
  87.  
  88. SCW_SetUp(Options="") {
  89.    if !(Options = "")
  90.    {
  91.       Loop, Parse, Options, %A_Space%
  92.       {
  93.          Field := A_LoopField
  94.          DotPos := InStr(Field, ".")
  95.          if (DotPos = 0)  
  96.          Continue
  97.          var := SubStr(Field, 1, DotPos-1)
  98.          val := SubStr(Field, DotPos+1)
  99.          if var in StartAfter,MaxGuis,AutoMonitorWM_LBUTTONDOWN,DrawCloseButton,BorderAColor,BorderBColor,SelColor,SelTrans
  100.          %var% := val
  101.       }
  102.    }
  103.    
  104.    SCW_Default(StartAfter,80), SCW_Default(MaxGuis,6)
  105.    SCW_Default(AutoMonitorWM_LBUTTONDOWN,1), SCW_Default(DrawCloseButton,0)
  106.    SCW_Default(BorderAColor,"ff6666ff"), SCW_Default(BorderBColor,"ffffffff")
  107.    SCW_Default(SelColor,"Yellow"), SCW_Default(SelTrans,80)
  108.    
  109.    SCW_Reg("MaxGuis", MaxGuis), SCW_Reg("StartAfter", StartAfter), SCW_Reg("DrawCloseButton", DrawCloseButton)
  110.    SCW_Reg("BorderAColor", BorderAColor), SCW_Reg("BorderBColor", BorderBColor)
  111.    SCW_Reg("SelColor", SelColor), SCW_Reg("SelTrans",SelTrans)
  112.    SCW_Reg("WasSetUp", 1)
  113.    if AutoMonitorWM_LBUTTONDOWN
  114.    OnMessage(0x201, "SCW_LBUTTONDOWN")
  115. }
  116.  
  117. SCW_ScreenClip2Win(clip=0,email=0) {
  118.    static c
  119.    if !(SCW_Reg("WasSetUp"))
  120.    SCW_SetUp()
  121.  
  122.    StartAfter := SCW_Reg("StartAfter"), MaxGuis := SCW_Reg("MaxGuis"), SelColor := SCW_Reg("SelColor"), SelTrans := SCW_Reg("SelTrans")
  123.    c++
  124.    if (c > MaxGuis)
  125.    c := 1
  126.  
  127.    GuiNum := StartAfter + c
  128.    Area := SCW_SelectAreaMod("g" GuiNum " c" SelColor " t" SelTrans)
  129.    StringSplit, v, Area, |
  130.    if (v3 < 10 and v4 < 10)   ; too small area
  131.    return
  132.    
  133.    pToken := Gdip_Startup()
  134.    if pToken =
  135.    {
  136.       MsgBox, 64, GDI+ error, GDI+ failed to start. Please ensure you have GDI+ on your system.
  137.       return
  138.    }
  139.    
  140.    Sleep, 100
  141.    pBitmap := Gdip_BitmapFromScreen(Area)
  142.  
  143. if (email=1){
  144. ;**********************Added to automatically save to bmp*********************************
  145. File1:=A_ScriptDir . "\example.BMP" ;path to file to save (make sure uppercase extenstion.  see below for options
  146. Gdip_SaveBitmapToFile(pBitmap, File1) ;Exports automatcially to file
  147.  
  148. File2:=A_ScriptDir . "\example.JPG" ;path to file to save (make sure uppercase extenstion.  see below for options
  149. Gdip_SaveBitmapToFile(pBitmap, File2) ;Exports automatcially to file
  150. Clipboard:=File2
  151.  
  152.  
  153. olFormatHTML := 2
  154. MailItem.BodyFormat := olFormatHTML
  155. ;~ MailItem.TO := (MailTo)
  156. ;~ MailItem.CC :="glines@ti.com"
  157. ;~ TodayDate := A_DDDD . ", " . A_MMM . " " . A_DD . ", " . A_YYYY
  158. FormatTime, TodayDate , YYYYMMDDHH24MISS, dddd MMMM d, yyyy h:mm:ss tt
  159. MailItem.Subject :="Screen shot taken : " (TodayDate) ;Subject line of email
  160.  
  161. MailItem.HTMLBody := "
  162. <H2 style='BACKGROUND-COLOR: red'><br></H2>
  163. <HTML>Attached you will find the screenshot taken on "(TodayDate)" <br><br>
  164. <span style='color:black'>Please let me know if you have any questions.<br><br><a href='mailto:Glines@TI.com'>Joe Glines</a> <br>214.567.3623
  165. </HTML>"
  166. MailItem.Attachments.Add(File1)
  167. MailItem.Attachments.Add(File2)
  168. MailItem.Display ;
  169. Reload
  170. }
  171. ;*******************************************************
  172.    SCW_CreateLayeredWinMod(GuiNum,pBitmap,v1,v2, SCW_Reg("DrawCloseButton"))
  173.    Gdip_Shutdown("pToken")
  174. if clip=1
  175. {
  176.  ;********************** added to copy to clipboard by default*********************************
  177.    WinActivate, ScreenClippingWindow ahk_class AutoHotkeyGUI ;activates lat clipped window
  178.    SCW_Win2Clipboard(0)  ;copies to clipboard by default w/o border
  179. ;~ MsgBox on clipboard
  180. ;*******************************************************
  181. }
  182. }
  183.  
  184. SCW_SelectAreaMod(Options="") {
  185.    CoordMode, Mouse, Screen
  186.    MouseGetPos, MX, MY
  187.       loop, parse, Options, %A_Space%
  188.    {
  189.       Field := A_LoopField
  190.       FirstChar := SubStr(Field,1,1)
  191.       if FirstChar contains c,t,g,m
  192.       {
  193.          StringTrimLeft, Field, Field, 1
  194.          %FirstChar% := Field
  195.       }
  196.    }
  197.    c := (c = "") ? "Blue" : c, t := (t = "") ? "50" : t, g := (g = "") ? "99" : g
  198.    Gui %g%: Destroy
  199. ;   Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound
  200.    Gui %g%: +AlwaysOnTop -caption +Border +ToolWindow +LastFound -DPIScale ;provided from rommmcek 10/23/16
  201.  
  202.    WinSet, Transparent, %t%
  203.    Gui %g%: Color, %c%
  204.    Hotkey := RegExReplace(A_ThisHotkey,"^(\w* & |\W*)")
  205.    While, (GetKeyState(Hotkey, "p"))
  206.    {
  207.       Sleep, 10
  208.       MouseGetPos, MXend, MYend
  209.       w := abs(MX - MXend), h := abs(MY - MYend)
  210.       X := (MX < MXend) ? MX : MXend
  211.       Y := (MY < MYend) ? MY : MYend
  212.       Gui %g%: Show, x%X% y%Y% w%w% h%h% NA
  213.    }
  214.    Gui %g%: Destroy
  215.    MouseGetPos, MXend, MYend
  216.    If ( MX > MXend )
  217.    temp := MX, MX := MXend, MXend := temp
  218.    If ( MY > MYend )
  219.    temp := MY, MY := MYend, MYend := temp
  220.    Return MX "|" MY "|" w "|" h
  221. }
  222.  
  223. SCW_CreateLayeredWinMod(GuiNum,pBitmap,x,y,DrawCloseButton=0) {
  224.    static CloseButton := 16
  225.    BorderAColor := SCW_Reg("BorderAColor"), BorderBColor := SCW_Reg("BorderBColor")
  226.    
  227.    Gui %GuiNum%: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs
  228.    Gui %GuiNum%: Show, Na, ScreenClippingWindow
  229.    hwnd := WinExist()
  230.  
  231.    Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
  232.    hbm := CreateDIBSection(Width+6, Height+6), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  233.    G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7)
  234.  
  235.    Gdip_DrawImage(G, pBitmap, 3, 3, Width, Height)
  236.    Gdip_DisposeImage(pBitmap)
  237.  
  238.    pPen1 := Gdip_CreatePen("0x" BorderAColor, 3), pPen2 := Gdip_CreatePen("0x" BorderBColor, 1)
  239.    if DrawCloseButton
  240.    {
  241.       Gdip_DrawRectangle(G, pPen1, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
  242.       Gdip_DrawRectangle(G, pPen2, 1+Width-CloseButton+3, 1, CloseButton, CloseButton)
  243.    }
  244.    Gdip_DrawRectangle(G, pPen1, 1, 1, Width+3, Height+3)
  245.    Gdip_DrawRectangle(G, pPen2, 1, 1, Width+3, Height+3)
  246.    Gdip_DeletePen(pPen1), Gdip_DeletePen(pPen2)
  247.    
  248.    UpdateLayeredWindow(hwnd, hdc, x-3, y-3, Width+6, Height+6)
  249.    SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
  250.    SCW_Reg("G" GuiNum "#HWND", hwnd)
  251.    SCW_Reg("G" GuiNum "#XClose", Width+6-CloseButton)
  252.    SCW_Reg("G" GuiNum "#YClose", CloseButton)
  253.    Return hwnd
  254. }
  255.  
  256. SCW_LBUTTONDOWN() {
  257.    MouseGetPos,,, WinUMID
  258.     WinGetTitle, Title, ahk_id %WinUMID%
  259.    if Title = ScreenClippingWindow
  260.    {
  261.       PostMessage, 0xA1, 2,,, ahk_id %WinUMID%
  262.       KeyWait, Lbutton
  263.       CoordMode, mouse, Relative
  264.       MouseGetPos, x,y
  265.      XClose := SCW_Reg("G" A_Gui "#XClose"), YClose := SCW_Reg("G" A_Gui "#YClose")
  266.       if (x > XClose and y < YClose)
  267.       Gui %A_Gui%: Destroy
  268.       return 1   ; confirm that click was on module's screen clipping windows
  269.    }
  270. }
  271.  
  272. SCW_Reg(variable, value="") {
  273.    static
  274.    if (value = "") {
  275.       yaqxswcdevfr := kxucfp%variable%pqzmdk
  276.       Return yaqxswcdevfr
  277.    }
  278.    Else
  279.    kxucfp%variable%pqzmdk = %value%
  280. }
  281.  
  282. SCW_Default(ByRef Variable,DefaultValue) {
  283.    if (Variable="")
  284.    Variable := DefaultValue
  285. }
  286.  
  287. SCW_Win2Clipboard(KeepBorders=0) {
  288.    /*   ;   does not work for layered windows
  289.    ActiveWinID := WinExist("A")
  290.    pBitmap := Gdip_BitmapFromHWND(ActiveWinID)
  291.    Gdip_SetBitmapToClipboard(pBitmap)
  292.    */
  293.    Send, !{PrintScreen} ; Active Win's client area to Clipboard
  294.    if !KeepBorders
  295.    {
  296.       pToken := Gdip_Startup()
  297.       pBitmap := Gdip_CreateBitmapFromClipboard()
  298.       Gdip_GetDimensions(pBitmap, w, h)
  299.       pBitmap2 := SCW_CropImage(pBitmap, 3, 3, w-6, h-6)
  300.       Gdip_SetBitmapToClipboard(pBitmap2)
  301.       Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap2)
  302.       Gdip_Shutdown("pToken")
  303.    }
  304. }
  305.  
  306. SCW_CropImage(pBitmap, x, y, w, h) {
  307.    pBitmap2 := Gdip_CreateBitmap(w, h), G2 := Gdip_GraphicsFromImage(pBitmap2)
  308.    Gdip_DrawImage(G2, pBitmap, 0, 0, w, h, x, y, w, h)
  309.    Gdip_DeleteGraphics(G2)
  310.    return pBitmap2
  311. }
  312.  
  313.  
  314. ; Gdip standard library v1.38 by tic (Tariq Porter) 28/08/10
  315. ;
  316. ;#####################################################################################
  317. ;#####################################################################################
  318. ; STATUS ENUMERATION
  319. ; Return values for functions specified to have status enumerated return type
  320. ;#####################################################################################
  321. ;
  322. ; Ok =      = 0
  323. ; GenericError    = 1
  324. ; InvalidParameter   = 2
  325. ; OutOfMemory    = 3
  326. ; ObjectBusy    = 4
  327. ; InsufficientBuffer  = 5
  328. ; NotImplemented   = 6
  329. ; Win32Error    = 7
  330. ; WrongState    = 8
  331. ; Aborted     = 9
  332. ; FileNotFound    = 10
  333. ; ValueOverflow    = 11
  334. ; AccessDenied    = 12
  335. ; UnknownImageFormat  = 13
  336. ; FontFamilyNotFound  = 14
  337. ; FontStyleNotFound   = 15
  338. ; NotTrueTypeFont   = 16
  339. ; UnsupportedGdiplusVersion = 17
  340. ; GdiplusNotInitialized  = 18
  341. ; PropertyNotFound   = 19
  342. ; PropertyNotSupported  = 20
  343. ; ProfileNotFound   = 21
  344. ;
  345. ;#####################################################################################
  346. ;#####################################################################################
  347. ; FUNCTIONS
  348. ;#####################################################################################
  349. ;
  350. ; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  351. ; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  352. ; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
  353. ; SetImage(hwnd, hBitmap)
  354. ; Gdip_BitmapFromScreen(Screen=0, Raster="")
  355. ; CreateRectF(ByRef RectF, x, y, w, h)
  356. ; CreateSizeF(ByRef SizeF, w, h)
  357. ; CreateDIBSection
  358. ;
  359. ;#####################################################################################
  360.  
  361. ; Function:        UpdateLayeredWindow
  362. ; Description:     Updates a layered window with the handle to the DC of a gdi bitmap
  363. ;
  364. ; hwnd            Handle of the layered window to update
  365. ; hdc              Handle to the DC of the GDI bitmap to update the window with
  366. ; Layeredx         x position to place the window
  367. ; Layeredy         y position to place the window
  368. ; Layeredw         Width of the window
  369. ; Layeredh         Height of the window
  370. ; Alpha            Default = 255 : The transparency (0-255) to set the window transparency
  371. ;
  372. ; return          If the function succeeds, the return value is nonzero
  373. ;
  374. ; notes      If x or y omitted, then layered window will use its current coordinates
  375. ;       If w or h omitted then current width and height will be used
  376.  
  377. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  378. {
  379.  if ((x != "") && (y != ""))
  380.   VarSetCapacity(pt, 8), NumPut(x, pt, 0), NumPut(y, pt, 4)
  381.  
  382.  if (w = "") ||(h = "")
  383.   WinGetPos,,, w, h, ahk_id %hwnd%
  384.    
  385.  return DllCall("UpdateLayeredWindow", "uint", hwnd, "uint", 0, "uint", ((x = "") && (y = "")) ? 0 : &pt
  386.  , "int64*", w|h<<32, "uint", hdc, "int64*", 0, "uint", 0, "uint*", Alpha<<16|1<<24, "uint", 2)
  387. }
  388.  
  389. ;#####################################################################################
  390.  
  391. ; Function    BitBlt
  392. ; Description   The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle
  393. ;      of pixels from the specified source device context into a destination device context.
  394. ;
  395. ; dDC     handle to destination DC
  396. ; dx     x-coord of destination upper-left corner
  397. ; dy     y-coord of destination upper-left corner
  398. ; dw     width of the area to copy
  399. ; dh     height of the area to copy
  400. ; sDC     handle to source DC
  401. ; sx     x-coordinate of source upper-left corner
  402. ; sy     y-coordinate of source upper-left corner
  403. ; Raster    raster operation code
  404. ;
  405. ; return    If the function succeeds, the return value is nonzero
  406. ;
  407. ; notes     If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle
  408. ;
  409. ; BLACKNESS    = 0x00000042
  410. ; NOTSRCERASE   = 0x001100A6
  411. ; NOTSRCCOPY   = 0x00330008
  412. ; SRCERASE    = 0x00440328
  413. ; DSTINVERT    = 0x00550009
  414. ; PATINVERT    = 0x005A0049
  415. ; SRCINVERT    = 0x00660046
  416. ; SRCAND    = 0x008800C6
  417. ; MERGEPAINT   = 0x00BB0226
  418. ; MERGECOPY    = 0x00C000CA
  419. ; SRCCOPY    = 0x00CC0020
  420. ; SRCPAINT    = 0x00EE0086
  421. ; PATCOPY    = 0x00F00021
  422. ; PATPAINT    = 0x00FB0A09
  423. ; WHITENESS    = 0x00FF0062
  424. ; CAPTUREBLT   = 0x40000000
  425. ; NOMIRRORBITMAP  = 0x80000000
  426.  
  427. BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="")
  428. {
  429.  return DllCall("gdi32\BitBlt", "uint", dDC, "int", dx, "int", dy, "int", dw, "int", dh
  430.  , "uint", sDC, "int", sx, "int", sy, "uint", Raster ? Raster : 0x00CC0020)
  431. }
  432.  
  433. ;#####################################################################################
  434.  
  435. ; Function    StretchBlt
  436. ; Description   The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle,
  437. ;      stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary.
  438. ;      The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.
  439. ;
  440. ; ddc     handle to destination DC
  441. ; dx     x-coord of destination upper-left corner
  442. ; dy     y-coord of destination upper-left corner
  443. ; dw     width of destination rectangle
  444. ; dh     height of destination rectangle
  445. ; sdc     handle to source DC
  446. ; sx     x-coordinate of source upper-left corner
  447. ; sy     y-coordinate of source upper-left corner
  448. ; sw     width of source rectangle
  449. ; sh     height of source rectangle
  450. ; Raster    raster operation code
  451. ;
  452. ; return    If the function succeeds, the return value is nonzero
  453. ;
  454. ; notes     If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt  
  455.  
  456. StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="")
  457. {
  458.  return DllCall("gdi32\StretchBlt", "uint", ddc, "int", dx, "int", dy, "int", dw, "int", dh
  459.  , "uint", sdc, "int", sx, "int", sy, "int", sw, "int", sh, "uint", Raster ? Raster : 0x00CC0020)
  460. }
  461.  
  462. ;#####################################################################################
  463.  
  464. ; Function    SetStretchBltMode
  465. ; Description   The SetStretchBltMode function sets the bitmap stretching mode in the specified device context
  466. ;
  467. ; hdc     handle to the DC
  468. ; iStretchMode   The stretching mode, describing how the target will be stretched
  469. ;
  470. ; return    If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0
  471. ;
  472. ; STRETCH_ANDSCANS   = 0x01
  473. ; STRETCH_ORSCANS   = 0x02
  474. ; STRETCH_DELETESCANS  = 0x03
  475. ; STRETCH_HALFTONE   = 0x04
  476.  
  477. SetStretchBltMode(hdc, iStretchMode=4)
  478. {
  479.  return DllCall("gdi32\SetStretchBltMode", "uint", hdc, "int", iStretchMode)
  480. }
  481.  
  482. ;#####################################################################################
  483.  
  484. ; Function    SetImage
  485. ; Description   Associates a new image with a static control
  486. ;
  487. ; hwnd     handle of the control to update
  488. ; hBitmap    a gdi bitmap to associate the static control with
  489. ;
  490. ; return    If the function succeeds, the return value is nonzero
  491.  
  492. SetImage(hwnd, hBitmap)
  493. {
  494.  SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
  495.  E := ErrorLevel
  496.  DeleteObject(E)
  497.  return E
  498. }
  499.  
  500. ;#####################################################################################
  501.  
  502. ; Function    SetSysColorToControl
  503. ; Description   Sets a solid colour to a control
  504. ;
  505. ; hwnd     handle of the control to update
  506. ; SysColor    A system colour to set to the control
  507. ;
  508. ; return    If the function succeeds, the return value is zero
  509. ;
  510. ; notes     A control must have the 0xE style set to it so it is recognised as a bitmap
  511. ;      By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control
  512. ;
  513. ; COLOR_3DDKSHADOW    = 21
  514. ; COLOR_3DFACE     = 15
  515. ; COLOR_3DHIGHLIGHT    = 20
  516. ; COLOR_3DHILIGHT    = 20
  517. ; COLOR_3DLIGHT     = 22
  518. ; COLOR_3DSHADOW    = 16
  519. ; COLOR_ACTIVEBORDER   = 10
  520. ; COLOR_ACTIVECAPTION   = 2
  521. ; COLOR_APPWORKSPACE   = 12
  522. ; COLOR_BACKGROUND    = 1
  523. ; COLOR_BTNFACE     = 15
  524. ; COLOR_BTNHIGHLIGHT   = 20
  525. ; COLOR_BTNHILIGHT    = 20
  526. ; COLOR_BTNSHADOW    = 16
  527. ; COLOR_BTNTEXT     = 18
  528. ; COLOR_CAPTIONTEXT    = 9
  529. ; COLOR_DESKTOP     = 1
  530. ; COLOR_GRADIENTACTIVECAPTION = 27
  531. ; COLOR_GRADIENTINACTIVECAPTION = 28
  532. ; COLOR_GRAYTEXT    = 17
  533. ; COLOR_HIGHLIGHT    = 13
  534. ; COLOR_HIGHLIGHTTEXT   = 14
  535. ; COLOR_HOTLIGHT    = 26
  536. ; COLOR_INACTIVEBORDER   = 11
  537. ; COLOR_INACTIVECAPTION   = 3
  538. ; COLOR_INACTIVECAPTIONTEXT  = 19
  539. ; COLOR_INFOBK     = 24
  540. ; COLOR_INFOTEXT    = 23
  541. ; COLOR_MENU     = 4
  542. ; COLOR_MENUHILIGHT    = 29
  543. ; COLOR_MENUBAR     = 30
  544. ; COLOR_MENUTEXT    = 7
  545. ; COLOR_SCROLLBAR    = 0
  546. ; COLOR_WINDOW     = 5
  547. ; COLOR_WINDOWFRAME    = 6
  548. ; COLOR_WINDOWTEXT    = 8
  549.  
  550. SetSysColorToControl(hwnd, SysColor=15)
  551. {
  552.    WinGetPos,,, w, h, ahk_id %hwnd%
  553.    bc := DllCall("GetSysColor", "Int", SysColor)
  554.    pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16))
  555.    pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap)
  556.    Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h)
  557.    hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  558.    SetImage(hwnd, hBitmap)
  559.    Gdip_DeleteBrush(pBrushClear)
  560.    Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
  561.    return 0
  562. }
  563.  
  564. ;#####################################################################################
  565.  
  566. ; Function    Gdip_BitmapFromScreen
  567. ; Description   Gets a gdi+ bitmap from the screen
  568. ;
  569. ; Screen    0 = All screens
  570. ;      Any numerical value = Just that screen
  571. ;      x|y|w|h = Take specific coordinates with a width and height
  572. ; Raster    raster operation code
  573. ;
  574. ; return         If the function succeeds, the return value is a pointer to a gdi+ bitmap
  575. ;      -1:  one or more of x,y,w,h not passed properly
  576. ;
  577. ; notes     If no raster operation is specified, then SRCCOPY is used to the returned bitmap
  578.  
  579. Gdip_BitmapFromScreen(Screen=0, Raster="")
  580. {
  581.  if (Screen = 0)
  582.  {
  583.   Sysget, x, 76
  584.   Sysget, y, 77
  585.   Sysget, w, 78
  586.   Sysget, h, 79
  587.  }
  588.  else if (Screen&1 != "")
  589.  {
  590.   Sysget, M, Monitor, %Screen%
  591.   x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
  592.  }
  593.  else
  594.  {
  595.   StringSplit, S, Screen, |
  596.   x := S1, y := S2, w := S3, h := S4
  597.  }
  598.  
  599.  if (x = "") || (y = "") || (w = "") || (h = "")
  600.   return -1
  601.  
  602.  chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := GetDC()
  603.  BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster)
  604.  ReleaseDC(hhdc)
  605.  
  606.  pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  607.  SelectObject(hhdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
  608.  return pBitmap
  609. }
  610.  
  611. ;#####################################################################################
  612.  
  613. ; Function    Gdip_BitmapFromHWND
  614. ; Description   Uses PrintWindow to get a handle to the specified window and return a bitmap from it
  615. ;
  616. ; hwnd     handle to the window to get a bitmap from
  617. ;
  618. ; return    If the function succeeds, the return value is a pointer to a gdi+ bitmap
  619. ;
  620. ; notes     Window must not be not minimised in order to get a handle to it's client area
  621.  
  622. Gdip_BitmapFromHWND(hwnd)
  623. {
  624.  WinGetPos,,, Width, Height, ahk_id %hwnd%
  625.  hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  626.  PrintWindow(hwnd, hdc)
  627.  pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
  628.  SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  629.  return pBitmap
  630. }
  631. ;#####################################################################################
  632.  
  633. ; Function       CreateRectF
  634. ; Description   Creates a RectF object, containing a the coordinates and dimensions of a rectangle
  635. ;
  636. ; RectF          Name to call the RectF object
  637. ; x               x-coordinate of the upper left corner of the rectangle
  638. ; y               y-coordinate of the upper left corner of the rectangle
  639. ; w               Width of the rectangle
  640. ; h               Height of the rectangle
  641. ;
  642. ; return         No return value
  643.  
  644. CreateRectF(ByRef RectF, x, y, w, h)
  645. {
  646.    VarSetCapacity(RectF, 16)
  647.    NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float")
  648. }
  649. ;#####################################################################################
  650.  
  651. ; Function       CreateSizeF
  652. ; Description   Creates a SizeF object, containing an 2 values
  653. ;
  654. ; SizeF           Name to call the SizeF object
  655. ; w               w-value for the SizeF object
  656. ; h               h-value for the SizeF object
  657. ;
  658. ; return         No Return value
  659.  
  660. CreateSizeF(ByRef SizeF, w, h)
  661. {
  662.    VarSetCapacity(SizeF, 8)
  663.    NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float")    
  664. }
  665. ;#####################################################################################
  666.  
  667. ; Function       CreatePointF
  668. ; Description   Creates a SizeF object, containing an 2 values
  669. ;
  670. ; SizeF           Name to call the SizeF object
  671. ; w               w-value for the SizeF object
  672. ; h               h-value for the SizeF object
  673. ;
  674. ; return         No Return value
  675.  
  676. CreatePointF(ByRef PointF, x, y)
  677. {
  678.    VarSetCapacity(PointF, 8)
  679.    NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float")    
  680. }
  681. ;#####################################################################################
  682.  
  683. ; Function    CreateDIBSection
  684. ; Description   The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly
  685. ;
  686. ; w      width of the bitmap to create
  687. ; h      height of the bitmap to create
  688. ; hdc     a handle to the device context to use the palette from
  689. ; bpp     bits per pixel (32 = ARGB)
  690. ; ppvBits    A pointer to a variable that receives a pointer to the location of the DIB bit values
  691. ;
  692. ; return    returns a DIB. A gdi bitmap
  693. ;
  694. ; notes     ppvBits will receive the location of the pixels in the DIB
  695.  
  696. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  697. {
  698.  hdc2 := hdc ? hdc : GetDC()
  699.  VarSetCapacity(bi, 40, 0)
  700.  NumPut(w, bi, 4), NumPut(h, bi, 8), NumPut(40, bi, 0), NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16), NumPut(bpp, bi, 14, "ushort")
  701.  hbm := DllCall("CreateDIBSection", "uint" , hdc2, "uint" , &bi, "uint" , 0, "uint*", ppvBits, "uint" , 0, "uint" , 0)
  702.  
  703.  If !hdc
  704.   ReleaseDC(hdc2)
  705.  return hbm
  706. }
  707.  
  708. ;#####################################################################################
  709.  
  710. ; Function    PrintWindow
  711. ; Description   The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC
  712. ;
  713. ; hwnd     A handle to the window that will be copied
  714. ; hdc     A handle to the device context
  715. ; Flags     Drawing options
  716. ;
  717. ; return    If the function succeeds, it returns a nonzero value
  718. ;
  719. ; PW_CLIENTONLY   = 1
  720.  
  721. PrintWindow(hwnd, hdc, Flags=0)
  722. {
  723.  return DllCall("PrintWindow", "uint", hwnd, "uint", hdc, "uint", Flags)
  724. }
  725.  
  726. ;#####################################################################################
  727.  
  728. ; Function    DestroyIcon
  729. ; Description   Destroys an icon and frees any memory the icon occupied
  730. ;
  731. ; hIcon     Handle to the icon to be destroyed. The icon must not be in use
  732. ;
  733. ; return    If the function succeeds, the return value is nonzero
  734.  
  735. DestroyIcon(hIcon)
  736. {
  737.    return DllCall("DestroyIcon", "uint", hIcon)
  738. }
  739.  
  740. ;#####################################################################################
  741.  
  742. PaintDesktop(hdc)
  743. {
  744.  return DllCall("PaintDesktop", "uint", hdc)
  745. }
  746.  
  747. ;#####################################################################################
  748.  
  749. CreateCompatibleBitmap(hdc, w, h)
  750. {
  751.  return DllCall("gdi32\CreateCompatibleBitmap", "uint", hdc, "int", w, "int", h)
  752. }
  753.  
  754. ;#####################################################################################
  755.  
  756. ; Function    CreateCompatibleDC
  757. ; Description   This function creates a memory device context (DC) compatible with the specified device
  758. ;
  759. ; hdc     Handle to an existing device context    
  760. ;
  761. ; return    returns the handle to a device context or 0 on failure
  762. ;
  763. ; notes     If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen
  764.  
  765. CreateCompatibleDC(hdc=0)
  766. {
  767.    return DllCall("CreateCompatibleDC", "uint", hdc)
  768. }
  769.  
  770. ;#####################################################################################
  771.  
  772. ; Function    SelectObject
  773. ; Description   The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type
  774. ;
  775. ; hdc     Handle to a DC
  776. ; hgdiobj    A handle to the object to be selected into the DC
  777. ;
  778. ; return    If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced
  779. ;
  780. ; notes     The specified object must have been created by using one of the following functions
  781. ;      Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time)
  782. ;      Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush
  783. ;      Font - CreateFont, CreateFontIndirect
  784. ;      Pen - CreatePen, CreatePenIndirect
  785. ;      Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect
  786. ;
  787. ; notes     If the selected object is a region and the function succeeds, the return value is one of the following value
  788. ;
  789. ; SIMPLEREGION   = 2 Region consists of a single rectangle
  790. ; COMPLEXREGION   = 3 Region consists of more than one rectangle
  791. ; NULLREGION   = 1 Region is empty
  792.  
  793. SelectObject(hdc, hgdiobj)
  794. {
  795.    return DllCall("SelectObject", "uint", hdc, "uint", hgdiobj)
  796. }
  797.  
  798. ;#####################################################################################
  799.  
  800. ; Function    DeleteObject
  801. ; Description   This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object
  802. ;      After the object is deleted, the specified handle is no longer valid
  803. ;
  804. ; hObject    Handle to a logical pen, brush, font, bitmap, region, or palette to delete
  805. ;
  806. ; return    Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context
  807.  
  808. DeleteObject(hObject)
  809. {
  810.    return DllCall("DeleteObject", "uint", hObject)
  811. }
  812.  
  813. ;#####################################################################################
  814.  
  815. ; Function    GetDC
  816. ; Description   This function retrieves a handle to a display device context (DC) for the client area of the specified window.
  817. ;      The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window.
  818. ;
  819. ; 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    
  820. ;
  821. ; return    The handle the device context for the specified window's client area indicates success. NULL indicates failure
  822.  
  823. GetDC(hwnd=0)
  824. {
  825.  return DllCall("GetDC", "uint", hwnd)
  826. }
  827.  
  828. ;#####################################################################################
  829.  
  830. ; Function    ReleaseDC
  831. ; 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
  832. ;
  833. ; hdc     Handle to the device context to be released
  834. ; hwnd     Handle to the window whose device context is to be released
  835. ;
  836. ; return    1 = released
  837. ;      0 = not released
  838. ;
  839. ; 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
  840. ;      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.
  841.  
  842. ReleaseDC(hdc, hwnd=0)
  843. {
  844.    return DllCall("ReleaseDC", "uint", hwnd, "uint", hdc)
  845. }
  846.  
  847. ;#####################################################################################
  848.  
  849. ; Function    DeleteDC
  850. ; Description   The DeleteDC function deletes the specified device context (DC)
  851. ;
  852. ; hdc     A handle to the device context
  853. ;
  854. ; return    If the function succeeds, the return value is nonzero
  855. ;
  856. ; 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
  857.  
  858. DeleteDC(hdc)
  859. {
  860.    return DllCall("DeleteDC", "uint", hdc)
  861. }
  862. ;#####################################################################################
  863.  
  864. ; Function    Gdip_LibraryVersion
  865. ; Description   Get the current library version
  866. ;
  867. ; return    the library version
  868. ;
  869. ; notes     This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts
  870.  
  871. Gdip_LibraryVersion()
  872. {
  873.  return 1.38
  874. }
  875.  
  876. ;#####################################################################################
  877.  
  878. ; Function:       Gdip_BitmapFromBRA
  879. ; Description:    Gets a pointer to a gdi+ bitmap from a BRA file
  880. ;
  881. ; BRAFromMemIn   The variable for a BRA file read to memory
  882. ; File     The name of the file, or its number that you would like (This depends on alternate parameter)
  883. ; Alternate    Changes whether the File parameter is the file name or its number
  884. ;
  885. ; return         If the function succeeds, the return value is a pointer to a gdi+ bitmap
  886. ;      -1 = The BRA variable is empty
  887. ;      -2 = The BRA has an incorrect header
  888. ;      -3 = The BRA has information missing
  889. ;      -4 = Could not find file inside the BRA
  890.  
  891. Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0)
  892. {
  893.  if !BRAFromMemIn
  894.   return -1
  895.  Loop, Parse, BRAFromMemIn, `n
  896.  {
  897.   if (A_Index = 1)
  898.   {
  899.    StringSplit, Header, A_LoopField, |
  900.    if (Header0 != 4 || Header2 != "BRA!")
  901.     return -2
  902.   }
  903.   else if (A_Index = 2)
  904.   {
  905.    StringSplit, Info, A_LoopField, |
  906.    if (Info0 != 3)
  907.     return -3
  908.   }
  909.   else
  910.    break
  911.  }
  912.  if !Alternate
  913.   StringReplace, File, File, \, \\, All
  914.  RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo)
  915.  if !FileInfo
  916.   return -4
  917.  
  918.  hData := DllCall("GlobalAlloc", "uint", 2, "uint", FileInfo2)
  919.  pData := DllCall("GlobalLock", "uint", hData)
  920.  DllCall("RtlMoveMemory", "uint", pData, "uint", &BRAFromMemIn+Info2+FileInfo1, "uint", FileInfo2)
  921.  DllCall("GlobalUnlock", "uint", hData)
  922.  DllCall("ole32\CreateStreamOnHGlobal", "uint", hData, "int", 1, "uint*", pStream)
  923.  DllCall("gdiplus\GdipCreateBitmapFromStream", "uint", pStream, "uint*", pBitmap)
  924.  DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream)
  925.  return pBitmap
  926. }
  927.  
  928. ;#####################################################################################
  929.  
  930. ; Function    Gdip_DrawRectangle
  931. ; Description   This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap
  932. ;
  933. ; pGraphics    Pointer to the Graphics of a bitmap
  934. ; pPen     Pointer to a pen
  935. ; x      x-coordinate of the top left of the rectangle
  936. ; y      y-coordinate of the top left of the rectangle
  937. ; w      width of the rectanlge
  938. ; h      height of the rectangle
  939. ;
  940. ; return    status enumeration. 0 = success
  941. ;
  942. ; 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
  943.  
  944. Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  945. {
  946.    return DllCall("gdiplus\GdipDrawRectangle", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
  947. }
  948.  
  949. ;#####################################################################################
  950.  
  951. ; Function    Gdip_DrawRoundedRectangle
  952. ; Description   This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap
  953. ;
  954. ; pGraphics    Pointer to the Graphics of a bitmap
  955. ; pPen     Pointer to a pen
  956. ; x      x-coordinate of the top left of the rounded rectangle
  957. ; y      y-coordinate of the top left of the rounded rectangle
  958. ; w      width of the rectanlge
  959. ; h      height of the rectangle
  960. ; r      radius of the rounded corners
  961. ;
  962. ; return    status enumeration. 0 = success
  963. ;
  964. ; 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
  965.  
  966. Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
  967. {
  968.  Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  969.  Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  970.  Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  971.  Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  972.  E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
  973.  Gdip_ResetClip(pGraphics)
  974.  Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  975.  Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  976.  Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
  977.  Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
  978.  Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
  979.  Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  980.  Gdip_ResetClip(pGraphics)
  981.  return E
  982. }
  983.  
  984. ;#####################################################################################
  985.  
  986. ; Function    Gdip_DrawEllipse
  987. ; Description   This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap
  988. ;
  989. ; pGraphics    Pointer to the Graphics of a bitmap
  990. ; pPen     Pointer to a pen
  991. ; x      x-coordinate of the top left of the rectangle the ellipse will be drawn into
  992. ; y      y-coordinate of the top left of the rectangle the ellipse will be drawn into
  993. ; w      width of the ellipse
  994. ; h      height of the ellipse
  995. ;
  996. ; return    status enumeration. 0 = success
  997. ;
  998. ; notes     as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width
  999.  
  1000. Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
  1001. {
  1002.    return DllCall("gdiplus\GdipDrawEllipse", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h)
  1003. }
  1004.  
  1005. ;#####################################################################################
  1006.  
  1007. ; Function    Gdip_DrawBezier
  1008. ; Description   This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap
  1009. ;
  1010. ; pGraphics    Pointer to the Graphics of a bitmap
  1011. ; pPen     Pointer to a pen
  1012. ; x1     x-coordinate of the start of the bezier
  1013. ; y1     y-coordinate of the start of the bezier
  1014. ; x2     x-coordinate of the first arc of the bezier
  1015. ; y2     y-coordinate of the first arc of the bezier
  1016. ; x3     x-coordinate of the second arc of the bezier
  1017. ; y3     y-coordinate of the second arc of the bezier
  1018. ; x4     x-coordinate of the end of the bezier
  1019. ; y4     y-coordinate of the end of the bezier
  1020. ;
  1021. ; return    status enumeration. 0 = success
  1022. ;
  1023. ; 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
  1024.  
  1025. Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
  1026. {
  1027.    return DllCall("gdiplus\GdipDrawBezier", "uint", pgraphics, "uint", pPen
  1028.    , "float", x1, "float", y1, "float", x2, "float", y2
  1029.    , "float", x3, "float", y3, "float", x4, "float", y4)
  1030. }
  1031.  
  1032. ;#####################################################################################
  1033.  
  1034. ; Function    Gdip_DrawArc
  1035. ; Description   This function uses a pen to draw the outline of an arc into the Graphics of a bitmap
  1036. ;
  1037. ; pGraphics    Pointer to the Graphics of a bitmap
  1038. ; pPen     Pointer to a pen
  1039. ; x      x-coordinate of the start of the arc
  1040. ; y      y-coordinate of the start of the arc
  1041. ; w      width of the arc
  1042. ; h      height of the arc
  1043. ; StartAngle   specifies the angle between the x-axis and the starting point of the arc
  1044. ; SweepAngle   specifies the angle between the starting and ending points of the arc
  1045. ;
  1046. ; return    status enumeration. 0 = success
  1047. ;
  1048. ; 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
  1049.  
  1050. Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1051. {
  1052.    return DllCall("gdiplus\GdipDrawArc", "uint", pGraphics, "uint", pPen, "float", x
  1053.    , "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1054. }
  1055.  
  1056. ;#####################################################################################
  1057.  
  1058. ; Function    Gdip_DrawPie
  1059. ; Description   This function uses a pen to draw the outline of a pie into the Graphics of a bitmap
  1060. ;
  1061. ; pGraphics    Pointer to the Graphics of a bitmap
  1062. ; pPen     Pointer to a pen
  1063. ; x      x-coordinate of the start of the pie
  1064. ; y      y-coordinate of the start of the pie
  1065. ; w      width of the pie
  1066. ; h      height of the pie
  1067. ; StartAngle   specifies the angle between the x-axis and the starting point of the pie
  1068. ; SweepAngle   specifies the angle between the starting and ending points of the pie
  1069. ;
  1070. ; return    status enumeration. 0 = success
  1071. ;
  1072. ; 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
  1073.  
  1074. Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
  1075. {
  1076.    return DllCall("gdiplus\GdipDrawPie", "uint", pGraphics, "uint", pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1077. }
  1078.  
  1079. ;#####################################################################################
  1080.  
  1081. ; Function    Gdip_DrawLine
  1082. ; Description   This function uses a pen to draw a line into the Graphics of a bitmap
  1083. ;
  1084. ; pGraphics    Pointer to the Graphics of a bitmap
  1085. ; pPen     Pointer to a pen
  1086. ; x1     x-coordinate of the start of the line
  1087. ; y1     y-coordinate of the start of the line
  1088. ; x2     x-coordinate of the end of the line
  1089. ; y2     y-coordinate of the end of the line
  1090. ;
  1091. ; return    status enumeration. 0 = success  
  1092.  
  1093. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  1094. {
  1095.    return DllCall("gdiplus\GdipDrawLine", "uint", pGraphics, "uint", pPen
  1096.    , "float", x1, "float", y1, "float", x2, "float", y2)
  1097. }
  1098.  
  1099. ;#####################################################################################
  1100.  
  1101. ; Function    Gdip_DrawLines
  1102. ; Description   This function uses a pen to draw a series of joined lines into the Graphics of a bitmap
  1103. ;
  1104. ; pGraphics    Pointer to the Graphics of a bitmap
  1105. ; pPen     Pointer to a pen
  1106. ; Points    the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1107. ;
  1108. ; return    status enumeration. 0 = success    
  1109.  
  1110. Gdip_DrawLines(pGraphics, pPen, Points)
  1111. {
  1112.    StringSplit, Points, Points, |
  1113.    VarSetCapacity(PointF, 8*Points0)  
  1114.    Loop, %Points0%
  1115.    {
  1116.       StringSplit, Coord, Points%A_Index%, `,
  1117.       NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1118.    }
  1119.    return DllCall("gdiplus\GdipDrawLines", "uint", pGraphics, "uint", pPen, "uint", &PointF, "int", Points0)
  1120. }
  1121.  
  1122. ;#####################################################################################
  1123.  
  1124. ; Function    Gdip_FillRectangle
  1125. ; Description   This function uses a brush to fill a rectangle in the Graphics of a bitmap
  1126. ;
  1127. ; pGraphics    Pointer to the Graphics of a bitmap
  1128. ; pBrush    Pointer to a brush
  1129. ; x      x-coordinate of the top left of the rectangle
  1130. ; y      y-coordinate of the top left of the rectangle
  1131. ; w      width of the rectanlge
  1132. ; h      height of the rectangle
  1133. ;
  1134. ; return    status enumeration. 0 = success
  1135.  
  1136. Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1137. {
  1138.    return DllCall("gdiplus\GdipFillRectangle", "uint", pGraphics, "int", pBrush
  1139.    , "float", x, "float", y, "float", w, "float", h)
  1140. }
  1141.  
  1142. ;#####################################################################################
  1143.  
  1144. ; Function    Gdip_FillRoundedRectangle
  1145. ; Description   This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap
  1146. ;
  1147. ; pGraphics    Pointer to the Graphics of a bitmap
  1148. ; pBrush    Pointer to a brush
  1149. ; x      x-coordinate of the top left of the rounded rectangle
  1150. ; y      y-coordinate of the top left of the rounded rectangle
  1151. ; w      width of the rectanlge
  1152. ; h      height of the rectangle
  1153. ; r      radius of the rounded corners
  1154. ;
  1155. ; return    status enumeration. 0 = success
  1156.  
  1157. Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
  1158. {
  1159.  Region := Gdip_GetClipRegion(pGraphics)
  1160.  Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
  1161.  Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
  1162.  Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
  1163.  Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
  1164.  E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
  1165.  Gdip_SetClipRegion(pGraphics, Region, 0)
  1166.  Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
  1167.  Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
  1168.  Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
  1169.  Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
  1170.  Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
  1171.  Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
  1172.  Gdip_SetClipRegion(pGraphics, Region, 0)
  1173.  Gdip_DeleteRegion(Region)
  1174.  return E
  1175. }
  1176.  
  1177. ;#####################################################################################
  1178.  
  1179. ; Function    Gdip_FillPolygon
  1180. ; Description   This function uses a brush to fill a polygon in the Graphics of a bitmap
  1181. ;
  1182. ; pGraphics    Pointer to the Graphics of a bitmap
  1183. ; pBrush    Pointer to a brush
  1184. ; Points    the coordinates of all the points passed as x1,y1|x2,y2|x3,y3.....
  1185. ;
  1186. ; return    status enumeration. 0 = success
  1187. ;
  1188. ; notes     Alternate will fill the polygon as a whole, wheras winding will fill each new "segment"
  1189. ; Alternate    = 0
  1190. ; Winding     = 1
  1191.  
  1192. Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
  1193. {
  1194.    StringSplit, Points, Points, |
  1195.    VarSetCapacity(PointF, 8*Points0)  
  1196.    Loop, %Points0%
  1197.    {
  1198.       StringSplit, Coord, Points%A_Index%, `,
  1199.       NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1200.    }  
  1201.    return DllCall("gdiplus\GdipFillPolygon", "uint", pGraphics, "uint", pBrush, "uint", &PointF, "int", Points0, "int", FillMode)
  1202. }
  1203.  
  1204. ;#####################################################################################
  1205.  
  1206. ; Function    Gdip_FillPie
  1207. ; Description   This function uses a brush to fill a pie in the Graphics of a bitmap
  1208. ;
  1209. ; pGraphics    Pointer to the Graphics of a bitmap
  1210. ; pBrush    Pointer to a brush
  1211. ; x      x-coordinate of the top left of the pie
  1212. ; y      y-coordinate of the top left of the pie
  1213. ; w      width of the pie
  1214. ; h      height of the pie
  1215. ; StartAngle   specifies the angle between the x-axis and the starting point of the pie
  1216. ; SweepAngle   specifies the angle between the starting and ending points of the pie
  1217. ;
  1218. ; return    status enumeration. 0 = success
  1219.  
  1220. Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
  1221. {
  1222.    return DllCall("gdiplus\GdipFillPie", "uint", pGraphics, "uint", pBrush
  1223.    , "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle)
  1224. }
  1225.  
  1226. ;#####################################################################################
  1227.  
  1228. ; Function    Gdip_FillEllipse
  1229. ; Description   This function uses a brush to fill an ellipse in the Graphics of a bitmap
  1230. ;
  1231. ; pGraphics    Pointer to the Graphics of a bitmap
  1232. ; pBrush    Pointer to a brush
  1233. ; x      x-coordinate of the top left of the ellipse
  1234. ; y      y-coordinate of the top left of the ellipse
  1235. ; w      width of the ellipse
  1236. ; h      height of the ellipse
  1237. ;
  1238. ; return    status enumeration. 0 = success
  1239.  
  1240. Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
  1241. {
  1242.  return DllCall("gdiplus\GdipFillEllipse", "uint", pGraphics, "uint", pBrush, "float", x, "float", y, "float", w, "float", h)
  1243. }
  1244.  
  1245. ;#####################################################################################
  1246.  
  1247. ; Function    Gdip_FillRegion
  1248. ; Description   This function uses a brush to fill a region in the Graphics of a bitmap
  1249. ;
  1250. ; pGraphics    Pointer to the Graphics of a bitmap
  1251. ; pBrush    Pointer to a brush
  1252. ; Region    Pointer to a Region
  1253. ;
  1254. ; return    status enumeration. 0 = success
  1255. ;
  1256. ; notes     You can create a region Gdip_CreateRegion() and then add to this
  1257.  
  1258. Gdip_FillRegion(pGraphics, pBrush, Region)
  1259. {
  1260.  return DllCall("gdiplus\GdipFillRegion", "uint", pGraphics, "uint", pBrush, "uint", Region)
  1261. }
  1262.  
  1263. ;#####################################################################################
  1264.  
  1265. ; Function    Gdip_FillPath
  1266. ; Description   This function uses a brush to fill a path in the Graphics of a bitmap
  1267. ;
  1268. ; pGraphics    Pointer to the Graphics of a bitmap
  1269. ; pBrush    Pointer to a brush
  1270. ; Region    Pointer to a Path
  1271. ;
  1272. ; return    status enumeration. 0 = success
  1273.  
  1274. Gdip_FillPath(pGraphics, pBrush, Path)
  1275. {
  1276.  return DllCall("gdiplus\GdipFillPath", "uint", pGraphics, "uint", pBrush, "uint", Path)
  1277. }
  1278.  
  1279. ;#####################################################################################
  1280.  
  1281. ; Function    Gdip_DrawImagePointsRect
  1282. ; Description   This function draws a bitmap into the Graphics of another bitmap and skews it
  1283. ;
  1284. ; pGraphics    Pointer to the Graphics of a bitmap
  1285. ; pBitmap    Pointer to a bitmap to be drawn
  1286. ; Points    Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap
  1287. ; sx     x-coordinate of source upper-left corner
  1288. ; sy     y-coordinate of source upper-left corner
  1289. ; sw     width of source rectangle
  1290. ; sh     height of source rectangle
  1291. ; Matrix    a matrix used to alter image attributes when drawing
  1292. ;
  1293. ; return    status enumeration. 0 = success
  1294. ;
  1295. ; notes     if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1296. ;      Matrix can be omitted to just draw with no alteration to ARGB
  1297. ;      Matrix may be passed as a digit from 0 - 1 to change just transparency
  1298. ;      Matrix can be passed as a matrix with any delimiter
  1299.  
  1300. Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1)
  1301. {
  1302.  StringSplit, Points, Points, |
  1303.  VarSetCapacity(PointF, 8*Points0)  
  1304.  Loop, %Points0%
  1305.  {
  1306.   StringSplit, Coord, Points%A_Index%, `,
  1307.   NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  1308.  }
  1309.  
  1310.  if (Matrix&1 = "")
  1311.   ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1312.  else if (Matrix != 1)
  1313.   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")
  1314.  
  1315.  if (sx = "" && sy = "" && sw = "" && sh = "")
  1316.  {
  1317.   sx := 0, sy := 0
  1318.   sw := Gdip_GetImageWidth(pBitmap)
  1319.   sh := Gdip_GetImageHeight(pBitmap)
  1320.  }
  1321.  
  1322.  E := DllCall("gdiplus\GdipDrawImagePointsRect", "uint", pGraphics, "uint", pBitmap
  1323.  , "uint", &PointF, "int", Points0, "float", sx, "float", sy, "float", sw, "float", sh
  1324.  , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0)
  1325.  if ImageAttr
  1326.   Gdip_DisposeImageAttributes(ImageAttr)
  1327.  return E
  1328. }
  1329.  
  1330. ;#####################################################################################
  1331.  
  1332. ; Function    Gdip_DrawImage
  1333. ; Description   This function draws a bitmap into the Graphics of another bitmap
  1334. ;
  1335. ; pGraphics    Pointer to the Graphics of a bitmap
  1336. ; pBitmap    Pointer to a bitmap to be drawn
  1337. ; dx     x-coord of destination upper-left corner
  1338. ; dy     y-coord of destination upper-left corner
  1339. ; dw     width of destination image
  1340. ; dh     height of destination image
  1341. ; sx     x-coordinate of source upper-left corner
  1342. ; sy     y-coordinate of source upper-left corner
  1343. ; sw     width of source image
  1344. ; sh     height of source image
  1345. ; Matrix    a matrix used to alter image attributes when drawing
  1346. ;
  1347. ; return    status enumeration. 0 = success
  1348. ;
  1349. ; notes     if sx,sy,sw,sh are missed then the entire source bitmap will be used
  1350. ;      Gdip_DrawImage performs faster
  1351. ;      Matrix can be omitted to just draw with no alteration to ARGB
  1352. ;      Matrix may be passed as a digit from 0 - 1 to change just transparency
  1353. ;      Matrix can be passed as a matrix with any delimiter. For example:
  1354. ;      MatrixBright=
  1355. ;      (
  1356. ;      1.5  |0  |0  |0  |0
  1357. ;      0  |1.5 |0  |0  |0
  1358. ;      0  |0  |1.5 |0  |0
  1359. ;      0  |0  |0  |1  |0
  1360. ;      0.05 |0.05 |0.05 |0  |1
  1361. ;      )
  1362. ;
  1363. ; 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
  1364. ;      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
  1365. ;      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
  1366.  
  1367. Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1)
  1368. {
  1369.  if (Matrix&1 = "")
  1370.   ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
  1371.  else if (Matrix != 1)
  1372.   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")
  1373.  
  1374.  if (sx = "" && sy = "" && sw = "" && sh = "")
  1375.  {
  1376.   if (dx = "" && dy = "" && dw = "" && dh = "")
  1377.   {
  1378.    sx := dx := 0, sy := dy := 0
  1379.    sw := dw := Gdip_GetImageWidth(pBitmap)
  1380.    sh := dh := Gdip_GetImageHeight(pBitmap)
  1381.   }
  1382.   else
  1383.   {
  1384.    sx := sy := 0
  1385.    sw := Gdip_GetImageWidth(pBitmap)
  1386.    sh := Gdip_GetImageHeight(pBitmap)
  1387.   }
  1388.  }
  1389.  
  1390.  E := DllCall("gdiplus\GdipDrawImageRectRect", "uint", pGraphics, "uint", pBitmap
  1391.  , "float", dx, "float", dy, "float", dw, "float", dh
  1392.  , "float", sx, "float", sy, "float", sw, "float", sh
  1393.  , "int", 2, "uint", ImageAttr, "uint", 0, "uint", 0)
  1394.  if ImageAttr
  1395.   Gdip_DisposeImageAttributes(ImageAttr)
  1396.  return E
  1397. }
  1398.  
  1399. ;#####################################################################################
  1400.  
  1401. ; Function    Gdip_SetImageAttributesColorMatrix
  1402. ; Description   This function creates an image matrix ready for drawing
  1403. ;
  1404. ; Matrix    a matrix used to alter image attributes when drawing
  1405. ;      passed with any delimeter
  1406. ;
  1407. ; return    returns an image matrix on sucess or 0 if it fails
  1408. ;
  1409. ; 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
  1410. ;      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
  1411. ;      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
  1412.  
  1413. Gdip_SetImageAttributesColorMatrix(Matrix)
  1414. {
  1415.  VarSetCapacity(ColourMatrix, 100, 0)
  1416.  Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|")
  1417.  StringSplit, Matrix, Matrix, |
  1418.  Loop, 25
  1419.  {
  1420.   Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
  1421.   NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float")
  1422.  }
  1423.  DllCall("gdiplus\GdipCreateImageAttributes", "uint*", ImageAttr)
  1424.  DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "uint", ImageAttr, "int", 1, "int", 1, "uint", &ColourMatrix, "int", 0, "int", 0)
  1425.  return ImageAttr
  1426. }
  1427.  
  1428. ;#####################################################################################
  1429.  
  1430. ; Function    Gdip_GraphicsFromImage
  1431. ; Description   This function gets the graphics for a bitmap used for drawing functions
  1432. ;
  1433. ; pBitmap    Pointer to a bitmap to get the pointer to its graphics
  1434. ;
  1435. ; return    returns a pointer to the graphics of a bitmap
  1436. ;
  1437. ; notes     a bitmap can be drawn into the graphics of another bitmap
  1438.  
  1439. Gdip_GraphicsFromImage(pBitmap)
  1440. {
  1441.     DllCall("gdiplus\GdipGetImageGraphicsContext", "uint", pBitmap, "uint*", pGraphics)
  1442.     return pGraphics
  1443. }
  1444.  
  1445. ;#####################################################################################
  1446.  
  1447. ; Function    Gdip_GraphicsFromHDC
  1448. ; Description   This function gets the graphics from the handle to a device context
  1449. ;
  1450. ; hdc     This is the handle to the device context
  1451. ;
  1452. ; return    returns a pointer to the graphics of a bitmap
  1453. ;
  1454. ; notes     You can draw a bitmap into the graphics of another bitmap
  1455.  
  1456. Gdip_GraphicsFromHDC(hdc)
  1457. {
  1458.     DllCall("gdiplus\GdipCreateFromHDC", "uint", hdc, "uint*", pGraphics)
  1459.     return pGraphics
  1460. }
  1461.  
  1462. ;#####################################################################################
  1463.  
  1464. ; Function    Gdip_GetDC
  1465. ; Description   This function gets the device context of the passed Graphics
  1466. ;
  1467. ; hdc     This is the handle to the device context
  1468. ;
  1469. ; return    returns the device context for the graphics of a bitmap
  1470.  
  1471. Gdip_GetDC(pGraphics)
  1472. {
  1473.  DllCall("gdiplus\GdipGetDC", "uint", pGraphics, "uint*", hdc)
  1474.  return hdc
  1475. }
  1476.  
  1477. ;#####################################################################################
  1478.  
  1479. ; Function    Gdip_ReleaseDC
  1480. ; Description   This function releases a device context from use for further use
  1481. ;
  1482. ; pGraphics    Pointer to the graphics of a bitmap
  1483. ; hdc     This is the handle to the device context
  1484. ;
  1485. ; return    status enumeration. 0 = success
  1486.  
  1487. Gdip_ReleaseDC(pGraphics, hdc)
  1488. {
  1489.  return DllCall("gdiplus\GdipReleaseDC", "uint", pGraphics, "uint", hdc)
  1490. }
  1491.  
  1492. ;#####################################################################################
  1493.  
  1494. ; Function    Gdip_GraphicsClear
  1495. ; Description   Clears the graphics of a bitmap ready for further drawing
  1496. ;
  1497. ; pGraphics    Pointer to the graphics of a bitmap
  1498. ; ARGB     The colour to clear the graphics to
  1499. ;
  1500. ; return    status enumeration. 0 = success
  1501. ;
  1502. ; notes     By default this will make the background invisible
  1503. ;      Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics
  1504.  
  1505. Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff)
  1506. {
  1507.     return DllCall("gdiplus\GdipGraphicsClear", "uint", pGraphics, "int", ARGB)
  1508. }
  1509.  
  1510. ;#####################################################################################
  1511.  
  1512. ; Function    Gdip_BlurBitmap
  1513. ; Description   Gives a pointer to a blurred bitmap from a pointer to a bitmap
  1514. ;
  1515. ; pBitmap    Pointer to a bitmap to be blurred
  1516. ; Blur     The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur)
  1517. ;
  1518. ; return    If the function succeeds, the return value is a pointer to the new blurred bitmap
  1519. ;      -1 = The blur parameter is outside the range 1-100
  1520. ;
  1521. ; notes     This function will not dispose of the original bitmap
  1522.  
  1523. Gdip_BlurBitmap(pBitmap, Blur)
  1524. {
  1525.  if (Blur > 100) || (Blur < 1)
  1526.   return -1
  1527.  
  1528.  sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
  1529.  dWidth := sWidth//Blur, dHeight := sHeight//Blur
  1530.  
  1531.  pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
  1532.  G1 := Gdip_GraphicsFromImage(pBitmap1)
  1533.  Gdip_SetInterpolationMode(G1, 7)
  1534.  Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)
  1535.  
  1536.  Gdip_DeleteGraphics(G1)
  1537.  
  1538.  pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
  1539.  G2 := Gdip_GraphicsFromImage(pBitmap2)
  1540.  Gdip_SetInterpolationMode(G2, 7)
  1541.  Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)
  1542.  
  1543.  Gdip_DeleteGraphics(G2)
  1544.  Gdip_DisposeImage(pBitmap1)
  1545.  return pBitmap2
  1546. }
  1547.  
  1548. ;#####################################################################################
  1549.  
  1550. ; Function:       Gdip_SaveBitmapToFile
  1551. ; Description:    Saves a bitmap to a file in any supported format onto disk
  1552. ;  
  1553. ; pBitmap    Pointer to a bitmap
  1554. ; 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
  1555. ; Quality         If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
  1556. ;
  1557. ; return         If the function succeeds, the return value is zero, otherwise:
  1558. ;      -1 = Extension supplied is not a supported file format
  1559. ;      -2 = Could not get a list of encoders on system
  1560. ;      -3 = Could not find matching encoder for specified file format
  1561. ;      -4 = Could not get WideChar name of output file
  1562. ;      -5 = Could not save file to disk
  1563. ;
  1564. ; notes     This function will use the extension supplied from the sOutput parameter to determine the output format
  1565.  
  1566. Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=100)
  1567. {
  1568.  SplitPath, sOutput,,, Extension
  1569.  if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG
  1570.   return -1
  1571.  Extension := "." Extension
  1572.  
  1573.  DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize)
  1574.  VarSetCapacity(ci, nSize)
  1575.  DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, "uint", &ci)
  1576.  if !(nCount && nSize)
  1577.   return -2
  1578.    
  1579.  Loop, %nCount%
  1580.  {
  1581.   Location := NumGet(ci, 76*(A_Index-1)+44)
  1582.   if !A_IsUnicode
  1583.   {
  1584.    nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1585.    VarSetCapacity(sString, nSize)
  1586.    DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0)
  1587.    if !InStr(sString, "*" Extension)
  1588.     continue
  1589.   }
  1590.   else
  1591.   {
  1592.    nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int",  0, "uint", 0, "uint", 0)
  1593.    sString := ""
  1594.    Loop, %nSize%
  1595.     sString .= Chr(NumGet(Location+0, 2*(A_Index-1), "char"))
  1596.    if !InStr(sString, "*" Extension)
  1597.     continue
  1598.   }
  1599.   pCodec := &ci+76*(A_Index-1)
  1600.   break
  1601.  }
  1602.  if !pCodec
  1603.   return -3
  1604.  
  1605.  if (Quality != 75)
  1606.  {
  1607.   Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality
  1608.   if Extension in .JPG,.JPEG,.JPE,.JFIF
  1609.   {
  1610.    DllCall("gdiplus\GdipGetEncoderParameterListSize", "uint", pBitmap, "uint", pCodec, "uint*", nSize)
  1611.    VarSetCapacity(EncoderParameters, nSize, 0)
  1612.    DllCall("gdiplus\GdipGetEncoderParameterList", "uint", pBitmap, "uint", pCodec, "uint", nSize, "uint", &EncoderParameters)
  1613.    Loop, % NumGet(EncoderParameters)      ;%
  1614.    {
  1615.     if (NumGet(EncoderParameters, (28*(A_Index-1))+20) = 1) && (NumGet(EncoderParameters, (28*(A_Index-1))+24) = 6)
  1616.     {
  1617.        p := (28*(A_Index-1))+&EncoderParameters
  1618.        NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20)))
  1619.        break
  1620.     }
  1621.    }      
  1622.    }
  1623.  }
  1624.  
  1625.  if !A_IsUnicode
  1626.  {
  1627.   nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", 0, "int", 0)
  1628.   VarSetCapacity(wOutput, nSize*2)
  1629.   DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sOutput, "int", -1, "uint", &wOutput, "int", nSize)
  1630.   VarSetCapacity(wOutput, -1)
  1631.   if !VarSetCapacity(wOutput)
  1632.    return -4
  1633.   E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &wOutput, "uint", pCodec, "uint", p ? p : 0)
  1634.  }
  1635.  else
  1636.   E := DllCall("gdiplus\GdipSaveImageToFile", "uint", pBitmap, "uint", &sOutput, "uint", pCodec, "uint", p ? p : 0)
  1637.  return E ? -5 : 0
  1638. }
  1639.  
  1640. ;#####################################################################################
  1641.  
  1642. ; Function    Gdip_GetPixel
  1643. ; Description   Gets the ARGB of a pixel in a bitmap
  1644. ;
  1645. ; pBitmap    Pointer to a bitmap
  1646. ; x      x-coordinate of the pixel
  1647. ; y      y-coordinate of the pixel
  1648. ;
  1649. ; return    Returns the ARGB value of the pixel
  1650.  
  1651. Gdip_GetPixel(pBitmap, x, y)
  1652. {
  1653.  DllCall("gdiplus\GdipBitmapGetPixel", "uint", pBitmap, "int", x, "int", y, "uint*", ARGB)
  1654.  return ARGB
  1655. }
  1656.  
  1657. ;#####################################################################################
  1658.  
  1659. ; Function    Gdip_SetPixel
  1660. ; Description   Sets the ARGB of a pixel in a bitmap
  1661. ;
  1662. ; pBitmap    Pointer to a bitmap
  1663. ; x      x-coordinate of the pixel
  1664. ; y      y-coordinate of the pixel
  1665. ;
  1666. ; return    status enumeration. 0 = success
  1667.  
  1668. Gdip_SetPixel(pBitmap, x, y, ARGB)
  1669. {
  1670.    return DllCall("gdiplus\GdipBitmapSetPixel", "uint", pBitmap, "int", x, "int", y, "int", ARGB)
  1671. }
  1672.  
  1673. ;#####################################################################################
  1674.  
  1675. ; Function    Gdip_GetImageWidth
  1676. ; Description   Gives the width of a bitmap
  1677. ;
  1678. ; pBitmap    Pointer to a bitmap
  1679. ;
  1680. ; return    Returns the width in pixels of the supplied bitmap
  1681.  
  1682. Gdip_GetImageWidth(pBitmap)
  1683. {
  1684.    DllCall("gdiplus\GdipGetImageWidth", "uint", pBitmap, "uint*", Width)
  1685.    return Width
  1686. }
  1687.  
  1688. ;#####################################################################################
  1689.  
  1690. ; Function    Gdip_GetImageHeight
  1691. ; Description   Gives the height of a bitmap
  1692. ;
  1693. ; pBitmap    Pointer to a bitmap
  1694. ;
  1695. ; return    Returns the height in pixels of the supplied bitmap
  1696.  
  1697. Gdip_GetImageHeight(pBitmap)
  1698. {
  1699.    DllCall("gdiplus\GdipGetImageHeight", "uint", pBitmap, "uint*", Height)
  1700.    return Height
  1701. }
  1702.  
  1703. ;#####################################################################################
  1704.  
  1705. ; Function    Gdip_GetDimensions
  1706. ; Description   Gives the width and height of a bitmap
  1707. ;
  1708. ; pBitmap    Pointer to a bitmap
  1709. ; Width     ByRef variable. This variable will be set to the width of the bitmap
  1710. ; Height    ByRef variable. This variable will be set to the height of the bitmap
  1711. ;
  1712. ; return    No return value
  1713. ;      Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1714.  
  1715. Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height)
  1716. {
  1717.  Width := Gdip_GetImageWidth(pBitmap)
  1718.  Height := Gdip_GetImageHeight(pBitmap)
  1719. }
  1720.  
  1721. ;#####################################################################################
  1722.  
  1723. Gdip_GetImagePixelFormat(pBitmap)
  1724. {
  1725.  DllCall("gdiplus\GdipGetImagePixelFormat", "uint", pBitmap, "uint*", Format)
  1726.  return Format
  1727. }
  1728.  
  1729. ;#####################################################################################
  1730.  
  1731. ; Function    Gdip_GetDpiX
  1732. ; Description   Gives the horizontal dots per inch of the graphics of a bitmap
  1733. ;
  1734. ; pBitmap    Pointer to a bitmap
  1735. ; Width     ByRef variable. This variable will be set to the width of the bitmap
  1736. ; Height    ByRef variable. This variable will be set to the height of the bitmap
  1737. ;
  1738. ; return    No return value
  1739. ;      Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height
  1740.  
  1741. Gdip_GetDpiX(pGraphics)
  1742. {
  1743.  DllCall("gdiplus\GdipGetDpiX", "uint", pGraphics, "float*", dpix)
  1744.  return Round(dpix)
  1745. }
  1746.  
  1747. Gdip_GetDpiY(pGraphics)
  1748. {
  1749.  DllCall("gdiplus\GdipGetDpiY", "uint", pGraphics, "float*", dpiy)
  1750.  return Round(dpiy)
  1751. }
  1752.  
  1753. Gdip_GetImageHorizontalResolution(pBitmap)
  1754. {
  1755.  DllCall("gdiplus\GdipGetImageHorizontalResolution", "uint", pBitmap, "float*", dpix)
  1756.  return Round(dpix)
  1757. }
  1758.  
  1759. Gdip_GetImageVerticalResolution(pBitmap)
  1760. {
  1761.  DllCall("gdiplus\GdipGetImageVerticalResolution", "uint", pBitmap, "float*", dpiy)
  1762.  return Round(dpiy)
  1763. }
  1764.  
  1765. Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="")
  1766. {
  1767.  SplitPath, sFile,,, ext
  1768.  if ext in exe,dll
  1769.  {
  1770.   Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16
  1771.   VarSetCapacity(buf, 40)
  1772.   Loop, Parse, Sizes, |
  1773.   {
  1774.    DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, "uint*", hIcon, "uint*", 0, "uint", 1, "uint", 0)
  1775.    if !hIcon
  1776.     continue
  1777.  
  1778.    if !DllCall("GetIconInfo", "uint", hIcon, "uint", &buf)
  1779.    {
  1780.     DestroyIcon(hIcon)
  1781.     continue
  1782.    }
  1783.    hbmColor := NumGet(buf, 16)
  1784.    hbmMask  := NumGet(buf, 12)
  1785.  
  1786.    if !(hbmColor && DllCall("GetObject", "uint", hbmColor, "int", 24, "uint", &buf))
  1787.    {
  1788.     DestroyIcon(hIcon)
  1789.     continue
  1790.    }
  1791.    break
  1792.   }
  1793.   if !hIcon
  1794.    return -1
  1795.  
  1796.   Width := NumGet(buf, 4, "int"),  Height := NumGet(buf, 8, "int")
  1797.   hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
  1798.  
  1799.   if !DllCall("DrawIconEx", "uint", hdc, "int", 0, "int", 0, "uint", hIcon, "uint", Width, "uint", Height, "uint", 0, "uint", 0, "uint", 3)
  1800.   {
  1801.    DestroyIcon(hIcon)
  1802.    return -2
  1803.   }
  1804.  
  1805.   VarSetCapacity(dib, 84)
  1806.   DllCall("GetObject", "uint", hbm, "int", 84, "uint", &dib)
  1807.   Stride := NumGet(dib, 12), Bits := NumGet(dib, 20)
  1808.  
  1809.   DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, "uint", Bits, "uint*", pBitmapOld)
  1810.   pBitmap := Gdip_CreateBitmap(Width, Height), G := Gdip_GraphicsFromImage(pBitmap)
  1811.   Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height)
  1812.   SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
  1813.   Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld)
  1814.   DestroyIcon(hIcon)
  1815.  }
  1816.  else
  1817.  {
  1818.   if !A_IsUnicode
  1819.   {
  1820.    VarSetCapacity(wFile, 1023)
  1821.    DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sFile, "int", -1, "uint", &wFile, "int", 512)
  1822.    DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &wFile, "uint*", pBitmap)
  1823.   }
  1824.   else
  1825.    DllCall("gdiplus\GdipCreateBitmapFromFile", "uint", &sFile, "uint*", pBitmap)
  1826.  }
  1827.  return pBitmap
  1828. }
  1829.  
  1830. Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
  1831. {
  1832.  DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "uint", hBitmap, "uint", Palette, "uint*", pBitmap)
  1833.  return pBitmap
  1834. }
  1835.  
  1836. Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
  1837. {
  1838.  DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "uint", pBitmap, "uint*", hbm, "int", Background)
  1839.  return hbm
  1840. }
  1841.  
  1842. Gdip_CreateBitmapFromHICON(hIcon)
  1843. {
  1844.  DllCall("gdiplus\GdipCreateBitmapFromHICON", "uint", hIcon, "uint*", pBitmap)
  1845.  return pBitmap
  1846. }
  1847.  
  1848. Gdip_CreateHICONFromBitmap(pBitmap)
  1849. {
  1850.  DllCall("gdiplus\GdipCreateHICONFromBitmap", "uint", pBitmap, "uint*", hIcon)
  1851.  return hIcon
  1852. }
  1853.  
  1854. Gdip_CreateBitmap(Width, Height, Format=0x26200A)
  1855. {
  1856.     DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, "uint", 0, "uint*", pBitmap)
  1857.     Return pBitmap
  1858. }
  1859.  
  1860. Gdip_CreateBitmapFromClipboard()
  1861. {
  1862.  if !DllCall("OpenClipboard", "uint", 0)
  1863.   return -1
  1864.  if !DllCall("IsClipboardFormatAvailable", "uint", 8)
  1865.   return -2
  1866.  if !hBitmap := DllCall("GetClipboardData", "uint", 2)
  1867.   return -3
  1868.  if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
  1869.   return -4
  1870.  if !DllCall("CloseClipboard")
  1871.   return -5
  1872.  DeleteObject(hBitmap)
  1873.  return pBitmap
  1874. }
  1875.  
  1876. Gdip_SetBitmapToClipboard(pBitmap)
  1877. {
  1878.  hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
  1879.  DllCall("GetObject", "uint", hBitmap, "int", VarSetCapacity(oi, 84, 0), "uint", &oi)
  1880.  hdib := DllCall("GlobalAlloc", "uint", 2, "uint", 40+NumGet(oi, 44))
  1881.  pdib := DllCall("GlobalLock", "uint", hdib)
  1882.  DllCall("RtlMoveMemory", "uint", pdib, "uint", &oi+24, "uint", 40)
  1883.  DllCall("RtlMoveMemory", "Uint", pdib+40, "Uint", NumGet(oi, 20), "uint", NumGet(oi, 44))
  1884.  DllCall("GlobalUnlock", "uint", hdib)
  1885.  DllCall("DeleteObject", "uint", hBitmap)
  1886.  DllCall("OpenClipboard", "uint", 0)
  1887.  DllCall("EmptyClipboard")
  1888.  DllCall("SetClipboardData", "uint", 8, "uint", hdib)
  1889.  DllCall("CloseClipboard")
  1890. }
  1891.  
  1892. Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
  1893. {
  1894.  DllCall("gdiplus\GdipCloneBitmapArea", "float", x, "float", y, "float", w, "float", h
  1895.  , "int", Format, "uint", pBitmap, "uint*", pBitmapDest)
  1896.  return pBitmapDest
  1897. }
  1898.  
  1899. ;#####################################################################################
  1900. ; Create resources
  1901. ;#####################################################################################
  1902.  
  1903. Gdip_CreatePen(ARGB, w)
  1904. {
  1905.    DllCall("gdiplus\GdipCreatePen1", "int", ARGB, "float", w, "int", 2, "uint*", pPen)
  1906.    return pPen
  1907. }
  1908.  
  1909. Gdip_CreatePenFromBrush(pBrush, w)
  1910. {
  1911.  DllCall("gdiplus\GdipCreatePen2", "uint", pBrush, "float", w, "int", 2, "uint*", pPen)
  1912.  return pPen
  1913. }
  1914.  
  1915. Gdip_BrushCreateSolid(ARGB=0xff000000)
  1916. {
  1917.  DllCall("gdiplus\GdipCreateSolidFill", "int", ARGB, "uint*", pBrush)
  1918.  return pBrush
  1919. }
  1920.  
  1921. ; HatchStyleHorizontal = 0
  1922. ; HatchStyleVertical = 1
  1923. ; HatchStyleForwardDiagonal = 2
  1924. ; HatchStyleBackwardDiagonal = 3
  1925. ; HatchStyleCross = 4
  1926. ; HatchStyleDiagonalCross = 5
  1927. ; HatchStyle05Percent = 6
  1928. ; HatchStyle10Percent = 7
  1929. ; HatchStyle20Percent = 8
  1930. ; HatchStyle25Percent = 9
  1931. ; HatchStyle30Percent = 10
  1932. ; HatchStyle40Percent = 11
  1933. ; HatchStyle50Percent = 12
  1934. ; HatchStyle60Percent = 13
  1935. ; HatchStyle70Percent = 14
  1936. ; HatchStyle75Percent = 15
  1937. ; HatchStyle80Percent = 16
  1938. ; HatchStyle90Percent = 17
  1939. ; HatchStyleLightDownwardDiagonal = 18
  1940. ; HatchStyleLightUpwardDiagonal = 19
  1941. ; HatchStyleDarkDownwardDiagonal = 20
  1942. ; HatchStyleDarkUpwardDiagonal = 21
  1943. ; HatchStyleWideDownwardDiagonal = 22
  1944. ; HatchStyleWideUpwardDiagonal = 23
  1945. ; HatchStyleLightVertical = 24
  1946. ; HatchStyleLightHorizontal = 25
  1947. ; HatchStyleNarrowVertical = 26
  1948. ; HatchStyleNarrowHorizontal = 27
  1949. ; HatchStyleDarkVertical = 28
  1950. ; HatchStyleDarkHorizontal = 29
  1951. ; HatchStyleDashedDownwardDiagonal = 30
  1952. ; HatchStyleDashedUpwardDiagonal = 31
  1953. ; HatchStyleDashedHorizontal = 32
  1954. ; HatchStyleDashedVertical = 33
  1955. ; HatchStyleSmallConfetti = 34
  1956. ; HatchStyleLargeConfetti = 35
  1957. ; HatchStyleZigZag = 36
  1958. ; HatchStyleWave = 37
  1959. ; HatchStyleDiagonalBrick = 38
  1960. ; HatchStyleHorizontalBrick = 39
  1961. ; HatchStyleWeave = 40
  1962. ; HatchStylePlaid = 41
  1963. ; HatchStyleDivot = 42
  1964. ; HatchStyleDottedGrid = 43
  1965. ; HatchStyleDottedDiamond = 44
  1966. ; HatchStyleShingle = 45
  1967. ; HatchStyleTrellis = 46
  1968. ; HatchStyleSphere = 47
  1969. ; HatchStyleSmallGrid = 48
  1970. ; HatchStyleSmallCheckerBoard = 49
  1971. ; HatchStyleLargeCheckerBoard = 50
  1972. ; HatchStyleOutlinedDiamond = 51
  1973. ; HatchStyleSolidDiamond = 52
  1974. ; HatchStyleTotal = 53
  1975. Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
  1976. {
  1977.  DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "int", ARGBfront, "int", ARGBback, "uint*", pBrush)
  1978.  return pBrush
  1979. }
  1980.  
  1981. ;GpStatus WINGDIPAPI GdipCreateTexture2I(GpImage *image, GpWrapMode wrapmode, INT x, INT y, INT width, INT height, GpTexture **texture)
  1982. ;GpStatus WINGDIPAPI GdipCreateTexture2(GpImage *image, GpWrapMode wrapmode, REAL x, REAL y, REAL width, REAL height, GpTexture **texture)
  1983. ;GpStatus WINGDIPAPI GdipCreateTexture(GpImage *image, GpWrapMode wrapmode, GpTexture **texture)
  1984.  
  1985. Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="")
  1986. {
  1987.  if !(w && h)
  1988.   DllCall("gdiplus\GdipCreateTexture", "uint", pBitmap, "int", WrapMode, "uint*", pBrush)
  1989.  else
  1990.   DllCall("gdiplus\GdipCreateTexture2", "uint", pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, "uint*", pBrush)
  1991.  return pBrush
  1992. }
  1993.  
  1994. ; WrapModeTile = 0
  1995. ; WrapModeTileFlipX = 1
  1996. ; WrapModeTileFlipY = 2
  1997. ; WrapModeTileFlipXY = 3
  1998. ; WrapModeClamp = 4
  1999. Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1)
  2000. {
  2001.  CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2)
  2002.  DllCall("gdiplus\GdipCreateLineBrush", "uint", &PointF1, "uint", &PointF2, "int", ARGB1, "int", ARGB2, "int", WrapMode, "uint*", LGpBrush)
  2003.  return LGpBrush
  2004. }
  2005.  
  2006. ; LinearGradientModeHorizontal = 0
  2007. ; LinearGradientModeVertical = 1
  2008. ; LinearGradientModeForwardDiagonal = 2
  2009. ; LinearGradientModeBackwardDiagonal = 3
  2010. Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1)
  2011. {
  2012.  CreateRectF(RectF, x, y, w, h)
  2013.  DllCall("gdiplus\GdipCreateLineBrushFromRect", "uint", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, "uint*", LGpBrush)
  2014.  return LGpBrush
  2015. }
  2016.  
  2017. Gdip_CloneBrush(pBrush)
  2018. {
  2019.  static pNewBrush
  2020.  VarSetCapacity(pNewBrush, 288, 0)
  2021.  DllCall("RtlMoveMemory", "uint", &pNewBrush, "uint", pBrush, "uint", 288)
  2022.  VarSetCapacity(pNewBrush, -1)
  2023.  return &pNewBrush
  2024. }
  2025.  
  2026. ;#####################################################################################
  2027. ; Delete resources
  2028. ;#####################################################################################
  2029.  
  2030. Gdip_DeletePen(pPen)
  2031. {
  2032.    return DllCall("gdiplus\GdipDeletePen", "uint", pPen)
  2033. }
  2034.  
  2035. Gdip_DeleteBrush(pBrush)
  2036. {
  2037.    return DllCall("gdiplus\GdipDeleteBrush", "uint", pBrush)
  2038. }
  2039.  
  2040. Gdip_DisposeImage(pBitmap)
  2041. {
  2042.    return DllCall("gdiplus\GdipDisposeImage", "uint", pBitmap)
  2043. }
  2044.  
  2045. Gdip_DeleteGraphics(pGraphics)
  2046. {
  2047.    return DllCall("gdiplus\GdipDeleteGraphics", "uint", pGraphics)
  2048. }
  2049.  
  2050. Gdip_DisposeImageAttributes(ImageAttr)
  2051. {
  2052.  return DllCall("gdiplus\GdipDisposeImageAttributes", "uint", ImageAttr)
  2053. }
  2054.  
  2055. Gdip_DeleteFont(hFont)
  2056. {
  2057.    return DllCall("gdiplus\GdipDeleteFont", "uint", hFont)
  2058. }
  2059.  
  2060. Gdip_DeleteStringFormat(hFormat)
  2061. {
  2062.    return DllCall("gdiplus\GdipDeleteStringFormat", "uint", hFormat)
  2063. }
  2064.  
  2065. Gdip_DeleteFontFamily(hFamily)
  2066. {
  2067.    return DllCall("gdiplus\GdipDeleteFontFamily", "uint", hFamily)
  2068. }
  2069.  
  2070. Gdip_DeleteMatrix(Matrix)
  2071. {
  2072.    return DllCall("gdiplus\GdipDeleteMatrix", "uint", Matrix)
  2073. }
  2074.  
  2075. ;#####################################################################################
  2076. ; Text functions
  2077. ;#####################################################################################
  2078.  
  2079. Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0)
  2080. {
  2081.  IWidth := Width, IHeight:= Height
  2082.  
  2083.  RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos)
  2084.  RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos)
  2085.  RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width)
  2086.  RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height)
  2087.  RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour)
  2088.  RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
  2089.  RegExMatch(Options, "i)R(\d)", Rendering)
  2090.  RegExMatch(Options, "i)S(\d+)(p*)", Size)
  2091.  
  2092.  if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2))
  2093.   PassBrush := 1, pBrush := Colour2
  2094.  
  2095.  if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
  2096.   return -1
  2097.  
  2098.  Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
  2099.  Loop, Parse, Styles, |
  2100.  {
  2101.   if RegExMatch(Options, "\b" A_loopField)
  2102.   Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
  2103.  }
  2104.  
  2105.  Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
  2106.  Loop, Parse, Alignments, |
  2107.  {
  2108.   if RegExMatch(Options, "\b" A_loopField)
  2109.    Align |= A_Index//2.1      ; 0|0|1|1|2|2
  2110.  }
  2111.  
  2112.  xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
  2113.  ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
  2114.  Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
  2115.  Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
  2116.  if !PassBrush
  2117.   Colour := "0x" (Colour2 ? Colour2 : "ff000000")
  2118.  Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4
  2119.  Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12
  2120.  
  2121.  hFamily := Gdip_FontFamilyCreate(Font)
  2122.  hFont := Gdip_FontCreate(hFamily, Size, Style)
  2123.  hFormat := Gdip_StringFormatCreate(0x4000)
  2124.  pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
  2125.  if !(hFamily && hFont && hFormat && pBrush && pGraphics)
  2126.   return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
  2127.    
  2128.  CreateRectF(RC, xpos, ypos, Width, Height)
  2129.  Gdip_SetStringFormatAlign(hFormat, Align)
  2130.  Gdip_SetTextRenderingHint(pGraphics, Rendering)
  2131.  ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2132.  
  2133.  if vPos
  2134.  {
  2135.   StringSplit, ReturnRC, ReturnRC, |
  2136.  
  2137.   if (vPos = "vCentre") || (vPos = "vCenter")
  2138.    ypos += (Height-ReturnRC4)//2
  2139.   else if (vPos = "Top") || (vPos = "Up")
  2140.    ypos := 0
  2141.   else if (vPos = "Bottom") || (vPos = "Down")
  2142.    ypos := Height-ReturnRC4
  2143.  
  2144.   CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
  2145.   ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
  2146.  }
  2147.  
  2148.  if !Measure
  2149.   E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
  2150.  
  2151.  if !PassBrush
  2152.   Gdip_DeleteBrush(pBrush)
  2153.  Gdip_DeleteStringFormat(hFormat)  
  2154.  Gdip_DeleteFont(hFont)
  2155.  Gdip_DeleteFontFamily(hFamily)
  2156.  return E ? E : ReturnRC
  2157. }
  2158.  
  2159. Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
  2160. {
  2161.  if !A_IsUnicode
  2162.  {
  2163.   nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0)
  2164.   VarSetCapacity(wString, nSize*2)
  2165.   DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize)
  2166.   return DllCall("gdiplus\GdipDrawString", "uint", pGraphics
  2167.   , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush)
  2168.  }
  2169.  else
  2170.  {
  2171.   return DllCall("gdiplus\GdipDrawString", "uint", pGraphics
  2172.   , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", pBrush)
  2173.  }
  2174. }
  2175.  
  2176. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
  2177. {
  2178.  VarSetCapacity(RC, 16)
  2179.  if !A_IsUnicode
  2180.  {
  2181.   nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", 0, "int", 0)
  2182.   VarSetCapacity(wString, nSize*2)  
  2183.   DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &sString, "int", -1, "uint", &wString, "int", nSize)
  2184.   DllCall("gdiplus\GdipMeasureString", "uint", pGraphics
  2185.   , "uint", &wString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines)
  2186.  }
  2187.  else
  2188.  {
  2189.   DllCall("gdiplus\GdipMeasureString", "uint", pGraphics
  2190.   , "uint", &sString, "int", -1, "uint", hFont, "uint", &RectF, "uint", hFormat, "uint", &RC, "uint*", Chars, "uint*", Lines)
  2191.  }
  2192.  return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0
  2193. }
  2194.  
  2195. ; Near = 0
  2196. ; Center = 1
  2197. ; Far = 2
  2198. Gdip_SetStringFormatAlign(hFormat, Align)
  2199. {
  2200.    return DllCall("gdiplus\GdipSetStringFormatAlign", "uint", hFormat, "int", Align)
  2201. }
  2202.  
  2203. Gdip_StringFormatCreate(Format=0, Lang=0)
  2204. {
  2205.    DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, "uint*", hFormat)
  2206.    return hFormat
  2207. }
  2208.  
  2209. ; Regular = 0
  2210. ; Bold = 1
  2211. ; Italic = 2
  2212. ; BoldItalic = 3
  2213. ; Underline = 4
  2214. ; Strikeout = 8
  2215. Gdip_FontCreate(hFamily, Size, Style=0)
  2216. {
  2217.    DllCall("gdiplus\GdipCreateFont", "uint", hFamily, "float", Size, "int", Style, "int", 0, "uint*", hFont)
  2218.    return hFont
  2219. }
  2220.  
  2221. Gdip_FontFamilyCreate(Font)
  2222. {
  2223.  if !A_IsUnicode
  2224.  {
  2225.   nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", 0, "int", 0)
  2226.   VarSetCapacity(wFont, nSize*2)
  2227.   DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, "uint", &Font, "int", -1, "uint", &wFont, "int", nSize)
  2228.   DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &wFont, "uint", 0, "uint*", hFamily)
  2229.  }
  2230.  else
  2231.   DllCall("gdiplus\GdipCreateFontFamilyFromName", "uint", &Font, "uint", 0, "uint*", hFamily)
  2232.  return hFamily
  2233. }
  2234.  
  2235. ;#####################################################################################
  2236. ; Matrix functions
  2237. ;#####################################################################################
  2238.  
  2239. Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
  2240. {
  2241.    DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, "uint*", Matrix)
  2242.    return Matrix
  2243. }
  2244.  
  2245. Gdip_CreateMatrix()
  2246. {
  2247.    DllCall("gdiplus\GdipCreateMatrix", "uint*", Matrix)
  2248.    return Matrix
  2249. }
  2250.  
  2251. ;#####################################################################################
  2252. ; GraphicsPath functions
  2253. ;#####################################################################################
  2254.  
  2255. ; Alternate = 0
  2256. ; Winding = 1
  2257. Gdip_CreatePath(BrushMode=0)
  2258. {
  2259.  DllCall("gdiplus\GdipCreatePath", "int", BrushMode, "uint*", Path)
  2260.  return Path
  2261. }
  2262.  
  2263. Gdip_AddPathEllipse(Path, x, y, w, h)
  2264. {
  2265.  return DllCall("gdiplus\GdipAddPathEllipse", "uint", Path, "float", x, "float", y, "float", w, "float", h)
  2266. }
  2267.  
  2268. Gdip_AddPathPolygon(Path, Points)
  2269. {
  2270.  StringSplit, Points, Points, |
  2271.  VarSetCapacity(PointF, 8*Points0)  
  2272.  Loop, %Points0%
  2273.  {
  2274.   StringSplit, Coord, Points%A_Index%, `,
  2275.   NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float")
  2276.  }  
  2277.  
  2278.  return DllCall("gdiplus\GdipAddPathPolygon", "uint", Path, "uint", &PointF, "int", Points0)
  2279. }
  2280.  
  2281. Gdip_DeletePath(Path)
  2282. {
  2283.  return DllCall("gdiplus\GdipDeletePath", "uint", Path)
  2284. }
  2285.  
  2286. ;#####################################################################################
  2287. ; Quality functions
  2288. ;#####################################################################################
  2289.  
  2290. ; SystemDefault = 0
  2291. ; SingleBitPerPixelGridFit = 1
  2292. ; SingleBitPerPixel = 2
  2293. ; AntiAliasGridFit = 3
  2294. ; AntiAlias = 4
  2295. Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
  2296. {
  2297.  return DllCall("gdiplus\GdipSetTextRenderingHint", "uint", pGraphics, "int", RenderingHint)
  2298. }
  2299.  
  2300. ; Default = 0
  2301. ; LowQuality = 1
  2302. ; HighQuality = 2
  2303. ; Bilinear = 3
  2304. ; Bicubic = 4
  2305. ; NearestNeighbor = 5
  2306. ; HighQualityBilinear = 6
  2307. ; HighQualityBicubic = 7
  2308. Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
  2309. {
  2310.    return DllCall("gdiplus\GdipSetInterpolationMode", "uint", pGraphics, "int", InterpolationMode)
  2311. }
  2312.  
  2313. ; Default = 0
  2314. ; HighSpeed = 1
  2315. ; HighQuality = 2
  2316. ; None = 3
  2317. ; AntiAlias = 4
  2318. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  2319. {
  2320.    return DllCall("gdiplus\GdipSetSmoothingMode", "uint", pGraphics, "int", SmoothingMode)
  2321. }
  2322.  
  2323. ; CompositingModeSourceOver = 0 (blended)
  2324. ; CompositingModeSourceCopy = 1 (overwrite)
  2325. Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
  2326. {
  2327.    return DllCall("gdiplus\GdipSetCompositingMode", "uint", pGraphics, "int", CompositingMode)
  2328. }
  2329.  
  2330. ;#####################################################################################
  2331. ; Extra functions
  2332. ;#####################################################################################
  2333.  
  2334. Gdip_Startup()
  2335. {
  2336.  if !DllCall("GetModuleHandle", "str", "gdiplus")
  2337.   DllCall("LoadLibrary", "str", "gdiplus")
  2338.  VarSetCapacity(si, 16, 0), si := Chr(1)
  2339.  DllCall("gdiplus\GdiplusStartup", "uint*", pToken, "uint", &si, "uint", 0)
  2340.  return pToken
  2341. }
  2342.  
  2343. Gdip_Shutdown(pToken)
  2344. {
  2345.  DllCall("gdiplus\GdiplusShutdown", "uint", pToken)
  2346.  if hModule := DllCall("GetModuleHandle", "str", "gdiplus")
  2347.   DllCall("FreeLibrary", "uint", hModule)
  2348.  return 0
  2349. }
  2350.  
  2351. ; Prepend = 0; The new operation is applied before the old operation.
  2352. ; Append = 1; The new operation is applied after the old operation.
  2353. Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
  2354. {
  2355.  return DllCall("gdiplus\GdipRotateWorldTransform", "uint", pGraphics, "float", Angle, "int", MatrixOrder)
  2356. }
  2357.  
  2358. Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2359. {
  2360.  return DllCall("gdiplus\GdipScaleWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2361. }
  2362.  
  2363. Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
  2364. {
  2365.  return DllCall("gdiplus\GdipTranslateWorldTransform", "uint", pGraphics, "float", x, "float", y, "int", MatrixOrder)
  2366. }
  2367.  
  2368. Gdip_ResetWorldTransform(pGraphics)
  2369. {
  2370.  return DllCall("gdiplus\GdipResetWorldTransform", "uint", pGraphics)
  2371. }
  2372.  
  2373. Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
  2374. {
  2375.  pi := 3.14159, TAngle := Angle*(pi/180)
  2376.  
  2377.  Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
  2378.  if ((Bound >= 0) && (Bound <= 90))
  2379.   xTranslation := Height*Sin(TAngle), yTranslation := 0
  2380.  else if ((Bound > 90) && (Bound <= 180))
  2381.   xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
  2382.  else if ((Bound > 180) && (Bound <= 270))
  2383.   xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
  2384.  else if ((Bound > 270) && (Bound <= 360))
  2385.   xTranslation := 0, yTranslation := -Width*Sin(TAngle)
  2386. }
  2387.  
  2388. Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
  2389. {
  2390.  pi := 3.14159, TAngle := Angle*(pi/180)
  2391.  if !(Width && Height)
  2392.   return -1
  2393.  RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
  2394.  RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
  2395. }
  2396.  
  2397. ; Replace = 0
  2398. ; Intersect = 1
  2399. ; Union = 2
  2400. ; Xor = 3
  2401. ; Exclude = 4
  2402. ; Complement = 5
  2403. Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
  2404. {
  2405.    return DllCall("gdiplus\GdipSetClipRect", "uint", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode)
  2406. }
  2407.  
  2408. Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
  2409. {
  2410.    return DllCall("gdiplus\GdipSetClipPath", "uint", pGraphics, "uint", Path, "int", CombineMode)
  2411. }
  2412.  
  2413. Gdip_ResetClip(pGraphics)
  2414. {
  2415.    return DllCall("gdiplus\GdipResetClip", "uint", pGraphics)
  2416. }
  2417.  
  2418. Gdip_GetClipRegion(pGraphics)
  2419. {
  2420.  Region := Gdip_CreateRegion()
  2421.  DllCall("gdiplus\GdipGetClip", "uint" pGraphics, "uint*", Region)
  2422.  return Region
  2423. }
  2424.  
  2425. Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
  2426. {
  2427.  return DllCall("gdiplus\GdipSetClipRegion", "uint", pGraphics, "uint", Region, "int", CombineMode)
  2428. }
  2429.  
  2430. Gdip_CreateRegion()
  2431. {
  2432.  DllCall("gdiplus\GdipCreateRegion", "uint*", Region)
  2433.  return Region
  2434. }
  2435.  
  2436. Gdip_DeleteRegion(Region)
  2437. {
  2438.  return DllCall("gdiplus\GdipDeleteRegion", "uint", Region)
  2439. }
  2440.  
  2441. ;***********Function by Tervon*******************
  2442. SCW_Win2File(KeepBorders=0) {
  2443.    Send, !{PrintScreen} ; Active Win's client area to Clipboard
  2444.    sleep 50
  2445.    if !KeepBorders
  2446.    {
  2447.       pToken := Gdip_Startup()
  2448.       pBitmap := Gdip_CreateBitmapFromClipboard()
  2449.       Gdip_GetDimensions(pBitmap, w, h)
  2450.       pBitmap2 := SCW_CropImage(pBitmap, 3, 3, w-6, h-6)
  2451.       ;~ File2:=A_Desktop . "\" . A_Now . ".PNG" ; tervon  time /path to file to save
  2452.       FormatTime, TodayDate , YYYYMMDDHH24MISS, MM_dd_yy @h_mm_ss ;This is Joe's time format
  2453.       File2:=A_Desktop . "\" . TodayDate . ".PNG" ;path to file to save
  2454.       Gdip_SaveBitmapToFile(pBitmap2, File2) ;Exports automatcially to file
  2455.       Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap2)
  2456.       Gdip_Shutdown("pToken")
  2457.    }
  2458. }
  2459.  
  2460.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement