Advertisement
pastamaker

havoc v1.5

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