#Include <WinAPIEx.au3>
TCPStartup()
$Socket = TCPConnect("192.168.100.2", 33891)
If @error Then
Exit
EndIf
While 1
TCPSend($Socket, _GetScreenshot(0, 0, 1280, 1024))
If @error Then
ExitLoop
EndIf
; Sleep(1000)
WEnd
TCPShutdown()
Func _GetScreenshot($iX = 0, $iY = 0, $iWidth = -1, $iHeight = -1)
Local $tBD, $tData, $tOut, $hBitmap, $hDesktop, $hSrcDC, $hDstDC, $hDstSv, $pBits, $Lenght
If $iWidth = -1 Then
$iWidth = @DesktopWidth
EndIf
If $iHeight = -1 Then
$iHeight = @DesktopHeight
EndIf
$tBD = DllStructCreate($tagBITMAPINFOHEADER & 'byte[' & ($iWidth * $iHeight * 3) & ']')
If @error Then
Return 0
EndIf
DllStructSetData($tBD, 'biSize', 40)
DllStructSetData($tBD, 'biWidth', $iWidth)
DllStructSetData($tBD, 'biHeight', -$iHeight)
DllStructSetData($tBD, 'biPlanes', 1)
DllStructSetData($tBD, 'biBitCount', 24)
DllStructSetData($tBD, 'biCompression', $BI_RGB)
$hBitmap = _WinAPI_CreateDIBSection(0, $tBD, $DIB_RGB_COLORS, $pBits)
$hDesktop = _WinAPI_GetDesktopWindow()
$hSrcDC = _WinAPI_GetDC($hDesktop)
$hDstDC = _WinAPI_CreateCompatibleDC($hSrcDC)
$hDstSv = _WinAPI_SelectObject($hDstDC, $hBitmap)
_WinAPI_StretchBlt ( $hDstDC, $iX, $iY, 800, 600, $hSrcDC, $iX, $iY, 1280, 1024,$SRCCOPY)
; _WinAPI_BitBlt($hDstDC, $iX, $iY, $iWidth, $iHeight, $hSrcDC, $iX, $iY, $SRCCOPY)
_WinAPI_SelectObject($hDstDC, $hDstSv)
_WinAPI_ReleaseDC($hDesktop, $hSrcDC)
_WinAPI_DeleteDC($hDstDC)
_WinAPI_GetBitmapBits($hBitmap, $iWidth * $iHeight * 3, DllStructGetPtr($tBD) + 40)
_WinAPI_DeleteObject($hBitmap)
$Lenght = _WinAPI_LZNTCompress($tBD, $tData)
$tOut = DllStructCreate('dword;dword;byte[' & ($Lenght - Mod($Lenght, 4) + 4) & ']')
DllStructSetData($tOut, 1, DllStructGetSize($tOut))
DllStructSetData($tOut, 2, $Lenght)
DllStructSetData($tOut, 3, DllStructGetData($tData, 1))
Return Binary(DllStructGetData(DllStructCreate('byte[' & DllStructGetSize($tOut) & ']', DllStructGetPtr($tOut)), 1))
EndFunc ;==>_GetScreenshot
Func _WinAPI_LZNTCompress(ByRef $tInput, ByRef $tOutput, $fMaximum = 0)
Local $tBuffer, $tWorkSpace, $Ret, $Format = 0x0002
If $fMaximum Then
$Format = BitOR($Format, 0x0102)
EndIf
$tOutput = 0
$Ret = DllCall('ntdll.dll', 'uint', 'RtlGetCompressionWorkSpaceSize', 'ushort', $Format, 'ulong*', 0, 'ulong*', 0)
If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
$tWorkSpace = DllStructCreate('byte[' & $Ret[2] & ']')
$tBuffer = DllStructCreate('byte[' & (DllStructGetSize($tInput) + 32) & ']')
$Ret = DllCall('ntdll.dll', 'uint', 'RtlCompressBuffer', 'ushort', $Format, 'ptr', DllStructGetPtr($tInput), 'ulong', DllStructGetSize($tInput), 'ptr', DllStructGetPtr($tBuffer), 'ulong', DllStructGetSize($tBuffer), 'ulong', 4096, 'ulong*', 0, 'ptr', DllStructGetPtr($tWorkSpace))
If @error Then
Return SetError(1, 0, 0)
Else
If $Ret[0] Then
Return SetError(1, $Ret[0], 0)
EndIf
EndIf
$tOutput = DllStructCreate('byte[' & $Ret[7] & ']')
DllCall('ntdll.dll', 'none', 'RtlMoveMemory', 'ptr', DllStructGetPtr($tOutput), 'ptr', DllStructGetPtr($tBuffer), 'ulong_ptr', $Ret[7])
If @error Then
$tOutput = 0
Return SetError(1, 0, 0)
EndIf
Return $Ret[7]
EndFunc ;==>_WinAPI_LZNTCompress