Advertisement
Guest User

Untitled

a guest
Sep 10th, 2019
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 6.10 KB | None | 0 0
  1. #include <WindowsConstants.au3>
  2. #include <WinAPI.au3>
  3. #include <GDIPlus.au3>
  4.  
  5.  
  6. Global $g_hGfxCtxt, $hDC, $hHBitmap, $buffer
  7.  
  8. If not WinExists("[CLASS:Notepad]") Then Run("notepad.exe")
  9.  
  10. $hwnd_target = WinWait("[CLASS:Notepad]")
  11. $hwnd_overlay = CreateWindowOverlay($hwnd_target)
  12.  
  13. If @error And MsgBox(16, "", "Lแป—i") Then Exit
  14.  
  15.  
  16. _WinAPI_ShowWindow($hwnd_overlay, @SW_SHOW)
  17. _WinAPI_UpdateWindow($hwnd_overlay)
  18.  
  19. _Graphic_StartUp($hwnd_overlay)
  20.  
  21. $hPen = _GDIPlus_PenCreate(0xFFFF0000, 5)
  22.  
  23. Local $fpstime
  24. While 1
  25.  
  26.     $rc = UpdateOverlay($hwnd_overlay, $hwnd_target)
  27.  
  28. ;~  // target hwnd closed
  29.     If @error Then Exit
  30.  
  31.     _GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000)
  32.     _GDIPlus_GraphicsDrawLine($g_hGfxCtxt, 0, 0, $rc.right, $rc.bottom, $hPen)
  33.  
  34.     _GDIPlus_GraphicsDrawString($g_hGfxCtxt, StringFormat("FPS: %0.f", 1000 / TimerDiff($fpstime)), 150, 15)
  35.     _GDIPlus_GraphicsDrawString($g_hGfxCtxt, "try to move and resize the window", 150, 45)
  36.     $fpstime = TimerInit()
  37.     _WinAPI_BitBlt($hDC, 0, 0, $rc.right, $rc.bottom, $buffer, 0, 0, $SRCCOPY)
  38.  
  39. WEnd
  40.  
  41.  
  42. Func UpdateOverlay($hwnd_overlay, $hwnd_target)
  43.  
  44.     If WinExists($hwnd_target) = False Then Return SetError(1, 0, False)
  45.  
  46.     Static $old_rc = _WindowGetClientRect($hwnd_target)
  47.  
  48.     Local $hwnd_active = _WinAPI_GetForegroundWindow()
  49.     If ($hwnd_active = $hwnd_target) Then
  50.         Local $hwnd_highestZIndexlol = _WinAPI_GetWindow($hwnd_target, $GW_HWNDPREV)
  51.         _WinAPI_SetWindowPos($hwnd_overlay, $hwnd_highestZIndexlol, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))
  52.     EndIf
  53.  
  54.     $rc = _WindowGetClientRect($hwnd_target)
  55.     If $rc.left <> $old_rc.left Or $rc.top <> $old_rc.top Or $rc.right <> $old_rc.right Or $rc.bottom <> $old_rc.bottom Then
  56.  
  57.         If $rc.right <> $old_rc.right Or $rc.bottom <> $old_rc.bottom Then
  58.  
  59.             Local $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $rc.right, $rc.bottom)
  60.  
  61.     _GDIPlus_GraphicsSetClipRegion($g_hGfxCtxt, $hRegion)
  62.             _GDIPlus_RegionDispose($hRegion)
  63.         EndIf
  64.  
  65.         $old_rc = $rc
  66.         _WinAPI_SetWindowPos($hwnd_overlay, $hwnd_target, $rc.left, $rc.top, $rc.right, $rc.bottom, $SWP_NOREDRAW)
  67.     EndIf
  68.  
  69.     ; return window rect
  70.     Return $rc
  71. EndFunc
  72.  
  73.  
  74. Func CreateWindowOverlay($hwnd_target)
  75.     OnAutoItExitRegister("__OverlayExit")
  76.     ; Create a class cursor
  77.  
  78.     If WinExists($hwnd_target) = False Then Return SetError(1, 0, False)
  79.  
  80.     Local $rc = _WindowGetClientRect($hwnd_target)
  81.  
  82.     Local Const $sClass = 'OverlayWindow'
  83.     Local $hCursor = _WinAPI_LoadCursor(0, 32512) ; IDC_ARROW
  84.  
  85.     ; Create a class icons (large and small)
  86.     Local $tIcons = DllStructCreate('ptr;ptr')
  87.     _WinAPI_ExtractIconEx(@SystemDir & '\shell32.dll', 130, DllStructGetPtr($tIcons, 1), DllStructGetPtr($tIcons, 2), 1)
  88.     Local $hIcon = DllStructGetData($tIcons, 1)
  89.     Local $hIconSm = DllStructGetData($tIcons, 2)
  90.  
  91.     ; Create DLL callback function (window procedure)
  92.     Local $hProc = DllCallbackRegister('WndProcOverlay', 'lresult', 'hwnd;uint;wparam;lparam')
  93.  
  94.     ; Create and fill $tagWNDCLASSEX structure
  95.     Local $tWCEX = DllStructCreate($tagWNDCLASSEX & ';wchar szClassName[' & (StringLen($sClass) + 1) & ']')
  96.     DllStructSetData($tWCEX, 'Size', DllStructGetPtr($tWCEX, 'szClassName') - DllStructGetPtr($tWCEX))
  97.     DllStructSetData($tWCEX, 'Style', 0)
  98.     DllStructSetData($tWCEX, 'hWndProc', DllCallbackGetPtr(DllCallbackRegister('WndProcOverlay', 'lresult', 'hwnd;uint;wparam;lparam')))
  99.     DllStructSetData($tWCEX, 'ClsExtra', 0)
  100.     DllStructSetData($tWCEX, 'WndExtra', 0)
  101.     DllStructSetData($tWCEX, 'hInstance', Null)
  102.     DllStructSetData($tWCEX, 'hIcon', $hIcon)
  103.     DllStructSetData($tWCEX, 'hCursor', $hCursor)
  104.     DllStructSetData($tWCEX, 'hBackground', Null)
  105.     DllStructSetData($tWCEX, 'MenuName', Null)
  106.     DllStructSetData($tWCEX, 'szClassName', $sClass)
  107.     DllStructSetData($tWCEX, 'ClassName', DllStructGetPtr($tWCEX, 'szClassName'))
  108.     DllStructSetData($tWCEX, 'hIconSm', $hIconSm)
  109.  
  110.     If _WinAPI_RegisterClassEx($tWCEX) = 0 Then Return SetError(2, 0, False)
  111.     Local $hwnd = _WinAPI_CreateWindowEx(Null, $sClass, "codedbythedemons", BitOR($WS_POPUP, $WS_VISIBLE), $rc.left, $rc.top, $rc.right, $rc.bottom, Null, Null, $tWCEX.hInstance, Null)
  112.  
  113.     If $hwnd = 0 Then Return SetError(2, 0, False)
  114.     Local $margin = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;")
  115.         $margin.cxLeftWidth = -1
  116.         $margin.cxRightWidth = -1
  117.         $margin.cyTopHeight = -1
  118.         $margin.cyBottomHeight = -1
  119.  
  120.     Local $result = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "uint", $hwnd, "ptr", DllStructGetPtr($margin))
  121.     If @error Then Return SetError(3, 0, False)
  122.  
  123.  
  124.     _WinAPI_SetWindowLong($hwnd, $GWL_EXSTYLE, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_TOOLWINDOW))
  125.     If @error Then Return SetError(4, 0, False)
  126.  
  127.     Return $hwnd
  128. EndFunc
  129.  
  130. Func _WindowGetClientRect($hwnd)
  131.     Local $p = DllStructCreate("int x;int y")
  132.     _WinAPI_ClientToScreen($hwnd, $p)
  133.  
  134.     Local $rc = _WinAPI_GetClientRect($hwnd)
  135.     $rc.left = $p.x
  136.     $rc.top = $p.y
  137.     Return $rc
  138. EndFunc
  139.  
  140.  
  141. Func __OverlayExit()
  142.     Local $hwnd = WinGetHandle("[CLASS:OverlayWindow]")
  143.     While $hwnd <> 0
  144.         _WinAPI_DestroyWindow($hwnd)
  145.         $hwnd = WinGetHandle("[CLASS:OverlayWindow]")
  146.     WEnd
  147.     _WinAPI_UnregisterClass("OverlayWindow", Null);
  148. EndFunc
  149.  
  150. Func WndProcOverlay($hWnd, $iMsg, $wParam, $lParam)
  151.     Switch $iMsg
  152.         Case $WM_CLOSE
  153.             $g_bExit = True
  154.     EndSwitch
  155.     Return _WinAPI_DefWindowProcW($hWnd, $iMsg, $wParam, $lParam)
  156. EndFunc   ;==>_WndProc
  157.  
  158. Func _Graphic_StartUp($GUI)
  159.  
  160.     If WinExists($GUI) = False Then Return False
  161.     _GDIPlus_Startup()
  162.  
  163.     ; install gdi
  164.     Local $rc = _WindowGetClientRect($GUI)
  165.     $hDC = _WinAPI_GetDC($GUI)
  166.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, @DesktopWidth, @DesktopHeight)
  167.  
  168.     $buffer = _WinAPI_CreateCompatibleDC($hDC)
  169.     _WinAPI_SelectObject($buffer, $hHBitmap)
  170.  
  171.     $g_hGfxCtxt = _GDIPlus_GraphicsCreateFromHDC($buffer)
  172.     _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
  173.     _GDIPlus_GraphicsSetPixelOffsetMode($g_hGfxCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
  174.  
  175.     Local $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $rc.right, $rc.bottom)
  176.     _GDIPlus_GraphicsSetClipRegion($g_hGfxCtxt, $hRegion)
  177.     _GDIPlus_RegionDispose($hRegion)
  178.  
  179. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement