Advertisement
CivReborn

Draw On Screen

Nov 22nd, 2017
4,405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2. Coordmode,Mouse,Screen
  3. #NoEnv
  4. Gdip_Startup()
  5. OnExit, Exit
  6. Width :=A_ScreenWidth, Height :=A_ScreenHeight
  7. Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  8. Gui, 1: Show, NA
  9. hwnd1 := WinExist(),hbm := CreateDIBSection(Width, Height),hdc := CreateCompatibleDC(),obm := SelectObject(hdc, hbm),G := Gdip_GraphicsFromHDC(hdc)
  10. Gdip_SetSmoothingMode(G, 4)
  11. UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
  12. color1:="0xff000000",i:=0,j:=0
  13. Return
  14. Timer:
  15.     If(GetKeyState("Ctrl")){
  16.         MouseGetPos,x1,y1
  17.         pPen := Gdip_CreatePen(color1, 3)
  18.         Gdip_DrawLine(G, pPen,xStart,yStart, x1, y1)
  19.         Gdip_DeleteBrush(pPen)
  20.         pPen := Gdip_CreatePen(color1, 3)
  21.         Gdip_DrawLine(G, pPen,xStart-1,yStart-1, x1-1, y1-1)
  22.         Gdip_DeleteBrush(pPen)
  23.         pPen := Gdip_CreatePen(color1, 3)
  24.         Gdip_DrawLine(G, pPen,xStart+1,yStart+1, x1+1, y1+1)
  25.         Gdip_DeleteBrush(pPen)
  26.         UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
  27.         xStart:=x1,yStart:=y1
  28.     }else
  29.         SetTimer,Timer,Off
  30.     return
  31. *^LButton::
  32.     MouseGetPos,xStart,yStart
  33.     SetTimer,Timer,10
  34.     return
  35. *^RButton::
  36.     Gui,1:Destroy
  37.     Width :=A_ScreenWidth, Height :=A_ScreenHeight
  38.     Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  39.     Gui, 1: Show, NA
  40.     hwnd1 := WinExist()
  41.     SelectObject(hdc, obm)
  42.     DeleteObject(hbm)
  43.     DeleteDC(hdc)
  44.     Gdip_DeleteGraphics(G)
  45.     hbm := CreateDIBSection(Width, Height),hdc := CreateCompatibleDC(),obm := SelectObject(hdc, hbm),G := Gdip_GraphicsFromHDC(hdc)
  46.     Gdip_SetSmoothingMode(G, 4)
  47.     return
  48. Update_Color:
  49.     Gui,2:Submit
  50.     tlist:=["0xff000000","0xffff0000","0xff0000ff","0xff00ff00","0xff00ffff","0xffffff00","0xffff00ff"],Color1:=tList[tColor1-1]
  51.     Gui,2:Destroy
  52.     return
  53. ^WheelUp::
  54. ^WheelDown::
  55.     Gui,2:Destroy
  56.     Gui,2:+AlwaysOnTop -Caption
  57.     Gui,2:Add,ListBox,x0 y0 w200 r10 AltSubmit vtColor1 gUpdate_Color,|Black||Red|Blue|Green|Aqua|Yellow|Purple
  58.     Gui,2:Show
  59.     return
  60. Exit:
  61. *^NumPad7::
  62. Gdip_Shutdown(pToken)
  63. ExitApp
  64. UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
  65. {
  66.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  67.    
  68.     if ((x != "") && (y != ""))
  69.         VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt")
  70.  
  71.     if (w = "") ||(h = "")
  72.         WinGetPos,,, w, h, ahk_id %hwnd%
  73.    
  74.     return DllCall("UpdateLayeredWindow"
  75.                     , Ptr, hwnd
  76.                     , Ptr, 0
  77.                     , Ptr, ((x = "") && (y = "")) ? 0 : &pt
  78.                     , "int64*", w|h<<32
  79.                     , Ptr, hdc
  80.                     , "int64*", 0
  81.                     , "uint", 0
  82.                     , "UInt*", Alpha<<16|1<<24
  83.                     , "uint", 2)
  84. }
  85. CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
  86. {
  87.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  88.     hdc2 := hdc ? hdc : GetDC()
  89.     VarSetCapacity(bi, 40, 0)
  90.     NumPut(w, bi, 4, "uint")
  91.     , NumPut(h, bi, 8, "uint")
  92.     , NumPut(40, bi, 0, "uint")
  93.     , NumPut(1, bi, 12, "ushort")
  94.     , NumPut(0, bi, 16, "uInt")
  95.     , NumPut(bpp, bi, 14, "ushort")
  96.     hbm := DllCall("CreateDIBSection"
  97.                     , Ptr, hdc2
  98.                     , Ptr, &bi
  99.                     , "uint", 0
  100.                     , A_PtrSize ? "UPtr*" : "uint*", ppvBits
  101.                     , Ptr, 0
  102.                     , "uint", 0, Ptr)
  103.  
  104.     if !hdc
  105.         ReleaseDC(hdc2)
  106.     return hbm
  107. }
  108. CreateCompatibleDC(hdc=0)
  109. {
  110.    return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  111. }
  112. SelectObject(hdc, hgdiobj)
  113. {
  114.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  115.    
  116.     return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj)
  117. }
  118. DeleteObject(hObject)
  119. {
  120.    return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject)
  121. }
  122. GetDC(hwnd=0)
  123. {
  124.     return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd)
  125. }
  126. ReleaseDC(hdc, hwnd=0)
  127. {
  128.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  129.    
  130.     return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc)
  131. }
  132. DeleteDC(hdc)
  133. {
  134.    return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc)
  135. }
  136. Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
  137. {
  138.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  139.    
  140.     return DllCall("gdiplus\GdipDrawLine"
  141.                     , Ptr, pGraphics
  142.                     , Ptr, pPen
  143.                     , "float", x1
  144.                     , "float", y1
  145.                     , "float", x2
  146.                     , "float", y2)
  147. }
  148.  
  149. Gdip_GraphicsFromHDC(hdc)
  150. {
  151.     DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics)
  152.     return pGraphics
  153. }
  154. Gdip_CreatePen(ARGB, w)
  155. {
  156.    DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen)
  157.    return pPen
  158. }
  159.  
  160. Gdip_DeletePen(pPen)
  161. {
  162.    return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen)
  163. }
  164. Gdip_DeleteBrush(pBrush)
  165. {
  166.    return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush)
  167. }
  168.  
  169. Gdip_DeleteGraphics(pGraphics)
  170. {
  171.    return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics)
  172. }
  173. Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
  174. {
  175.    return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode)
  176. }
  177. Gdip_Startup()
  178. {
  179.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  180.    
  181.     if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  182.         DllCall("LoadLibrary", "str", "gdiplus")
  183.     VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
  184.     DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0)
  185.     return pToken
  186. }
  187. Gdip_Shutdown(pToken)
  188. {
  189.     Ptr := A_PtrSize ? "UPtr" : "UInt"
  190.    
  191.     DllCall("gdiplus\GdiplusShutdown", Ptr, pToken)
  192.     if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr)
  193.         DllCall("FreeLibrary", Ptr, hModule)
  194.     return 0
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement