Advertisement
Najeebsk

SREEN-CAP.ahk

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