#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinApi.au3>
; Выделите область, чтобы просмотреть её координаты и размеры
; ESC для выхода
Global $iX1, $iY1, $iX2, $iY2
While 1
ToolTip(_Rect())
Sleep(1000)
WEnd
Func _Rect()
Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
Local $UserDLL = DllOpen("user32.dll")
$hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCross_GUI, "", 8)
GUISetState(@SW_SHOW, $hCross_GUI)
GUISetCursor(3, 1, $hCross_GUI)
Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0xFF0000)
While Not _IsPressed("01", $UserDLL)
If _IsPressed("1B", $UserDLL) Then Exit
ToolTip("Выделите область" & @CRLF & "ESC - выход")
Sleep(50)
WEnd
$aMouse_Pos = MouseGetPos()
$iX1 = $aMouse_Pos[0] - 1
$iY1 = $aMouse_Pos[1] - 1
Local $iX, $iY, $iW, $iH
While _IsPressed("01", $UserDLL)
$aMouse_Pos = MouseGetPos()
$aMouse_Pos[0] -=1
$aMouse_Pos[1] -=1
$hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
$hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1)
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1])
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1)
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
$hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1])
_WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
_WinAPI_DeleteObject($hMask)
_WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)
$iX2 = $aMouse_Pos[0]
$iY2 = $aMouse_Pos[1]
If $iX2 < $iX1 Then
$iX = $iX2 + 1
$iW = $iX1 - $iX2 - 1
Else
$iX = $iX1 + 1
$iW = $iX2 - $iX1 - 1
EndIf
If $iY2 < $iY1 Then
$iY = $iY2 + 1
$iH = $iY1 - $iY2 - 1
Else
$iY = $iY1 + 1
$iH = $iY2 - $iY1 - 1
EndIf
$iW = $iW > 0 ? $iW : 0
$iH = $iH > 0 ? $iH : 0
ToolTip("X: " & $iX & @CRLF & "Y: " & $iY & @CRLF & "W: " & $iW & @CRLF & "H: " & $iH)
If WinGetState($hRectangle_GUI) < 15 Then GUISetState()
Sleep(10)
WEnd
$sCopy = "[" & $iX & ", " & $iY & ", " & $iW & ", " & $iH & "]"
ClipPut($sCopy)
Local $sMsg = "Скопировано в буфер обмена [X,Y,W,H]: " & $sCopy
ConsoleWrite($sMsg & @CRLF)
ToolTip($sMsg)
GUIDelete($hRectangle_GUI)
GUIDelete($hCross_GUI)
DllClose($UserDLL)
Return $sMsg
EndFunc