#include <Misc.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <ScreenCapture.au3>
#include <BorderConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
_GDIPlus_Startup()
Global $i_X, $i_Y, $iX, $iY, $hGraphics
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, 0, WinGetHandle(""))
GUISetBkColor(0, $hGUI)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_StartCapture")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
WinSetOnTop($hGUI, "", 1)
WinSetTrans($hGUI, "", 100)
GUISetState()
$hChild = GUICreate("4", 400, 300, -1, -1, $WS_SIZEBOX + $WS_POPUP, 0x200, $hGUI)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_MoveRect")
GUISetOnEvent($GUI_EVENT_CLOSE, "_HideChild")
Func _HideChild()
GUISetState(@SW_HIDE, $hChild)
_WinAPI_SetWindowRgn($hGUI, 0, 0)
EndFunc ;==>_HideChild
WinSetTrans($hChild, "", 5)
GUIRegisterMsg($WM_SIZING, "_WM_SIZING")
GUIRegisterMsg($WM_LBUTTONDBLCLK, "_SaveCapture")
Func _WM_SIZING($hWnd, $iMsg, $iwParam, $ilParam)
If $hWnd = $hChild Then
Local $tRect = DllStructCreate($tagRECT, $ilParam)
Local $hRgn1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, @DesktopHeight)
Local $hRgn = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3), DllStructGetData($tRect, 4))
_WinAPI_CombineRgn($hRgn, $hRgn1, $hRgn, $RGN_XOR)
_WinAPI_SetWindowRgn($hGUI, $hRgn, True)
EndIf
EndFunc ;==>_WM_SIZING
Func _SaveCapture($hWnd, $iMsg, $iwParam, $ilParam)
If $hWnd = $hChild Then
Local $aPos = WinGetPos($hChild)
_ScreenCapture_Capture("A.JPG", $aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3], 0)
_Quit()
; _HideChild()
EndIf
EndFunc ;==>_SaveCapture
Func _MoveRect()
Local $aXY, $hRgn, $hRgn1, $aPosDiff[2], $aWindowPos
$aXY = MouseGetPos()
$aWindowPos = WinGetPos($hChild)
$aPosDiff[0] = $aXY[0] - $aWindowPos[0]
$aPosDiff[1] = $aXY[1] - $aWindowPos[1]
$hRgn1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, @DeskTopHeight)
While _IsPressed("01")
$aXY = MouseGetPos()
WinMove($hChild, "", $aXY[0] - $aPosDiff[0], $aXY[1] - $aPosDiff[1])
$hRgn = _WinAPI_CreateRectRgn($aXY[0] - $aPosDiff[0], $aXY[1] - $aPosDiff[1], $aXY[0] - $aPosDiff[0] + $aWindowPos[2], $aXY[1] - $aPosDiff[1] + $aWindowPos[3])
_WinAPI_CombineRgn($hRgn, $hRgn1, $hRgn, $RGN_XOR)
_WinAPI_SetWindowRgn($hGUI, $hRgn, True)
WEnd
EndFunc
While 1
Sleep(1000)
WEnd
Func _Quit()
Exit
EndFunc
Func _StartCapture()
Local $aXY, $hRgn, $hRgn1
$aXY = MouseGetPos()
$i_X = $aXY[0]
$i_Y = $aXY[1]
$hRgn1 = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, @DesktopHeight)
While _IsPressed("01")
$aXY = MouseGetPos()
$iX = $aXY[0]
$iY = $aXY[1]
$hRgn = _WinAPI_CreateRectRgn($i_X, $i_Y, $iX, $iY)
_WinAPI_CombineRgn($hRgn, $hRgn1, $hRgn, $RGN_XOR)
_WinAPI_SetWindowRgn($hGUI, $hRgn, True)
WEnd
WinMove($hChild, "", $i_X, $i_Y, $iX - $i_X, $iY - $i_Y)
GUISetState(@SW_SHOW, $hChild)
ConsoleWrite($i_X & " " & $iX & " " & $i_Y & " " & $iY & @CRLF)
EndFunc
刚写的,有些混乱,希望可以帮助到你。