Advertisement
Guest User

HB Bitmap And Button Class Tut

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