#Include <GDIPlus.au3>
#Include <Memory.au3>
#Include <WinAPIEx.au3>
TCPStartup()
$Socket = TCPConnect(@IPAddress1, 33891)
If @error Then
Exit
EndIf
_GDIPlus_Startup()
Global $tEncoder, $pEncoder, $tParams, $pParams, $tQuality
$tEncoder = _WinAPI_GUIDFromString(_GDIPlus_EncodersGetCLSID('jpg'))
$pEncoder = DllStructGetPtr($tEncoder)
$tParams = _GDIPlus_ParamInit(1)
$pParams = DllStructGetPtr($tParams)
$tQuality = DllStructCreate('int')
DllStructSetData($tQuality, 1, 50) ; 0-100
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tQuality))
While 1
TCPSend($Socket, _GetScreenshot(0, 0, 800, 600))
If @error Then
ExitLoop
EndIf
Sleep(1000)
WEnd
_GDIPlus_Shutdown()
TCPShutdown()
Func _GetScreenshot($iX = 0, $iY = 0, $iWidth = -1, $iHeight = -1)
Local $hSrcDC, $hDstDC, $hDstSv, $hBitmap, $hDesktop, $hScreen, $hMemory, $pMemory, $pStream, $tOut, $pOut, $iSize
If $iWidth = -1 Then
$iWidth = @DesktopWidth
EndIf
If $iHeight = -1 Then
$iHeight = @DesktopHeight
EndIf
$hDesktop = _WinAPI_GetDesktopWindow()
$hSrcDC = _WinAPI_GetDC($hDesktop)
$hScreen = _WinAPI_CreateCompatibleBitmap($hSrcDC, $iWidth, $iHeight)
$hDstDC = _WinAPI_CreateCompatibleDC($hSrcDC)
$hDstSv = _WinAPI_SelectObject($hDstDC, $hScreen)
_WinAPI_BitBlt($hDstDC, $iX, $iY, $iWidth, $iHeight, $hSrcDC, $iX, $iY, $SRCCOPY)
_WinAPI_SelectObject($hDstDC, $hDstSv)
_WinAPI_ReleaseDC($hDesktop, $hSrcDC)
_WinAPI_DeleteDC($hDstDC)
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hScreen)
_WinAPI_DeleteObject($hScreen)
$pStream = _WinAPI_CreateStreamOnHGlobal(0)
_GDIPlus_ImageSaveToStream($hBitmap, $pStream, $pEncoder, $pParams)
_GDIPlus_BitmapDispose($hBitmap)
$hMemory = _WinAPI_GetHGlobalFromStream($pStream)
$pMemory = _MemGlobalLock($hMemory)
$iSize = _MemGlobalSize($hMemory)
$tOut = DllStructCreate('dword;dword;byte[' & ($iSize - Mod($iSize, 4) + 4) & ']')
$pOut = DllStructGetPtr($tOut)
DllStructSetData($tOut, 1, DllStructGetSize($tOut))
DllStructSetData($tOut, 2, $iSize)
_MemMoveMemory($pMemory, $pOut + 8, $iSize)
_MemGlobalFree($hMemory)
ConsoleWrite(_WinAPI_StrFormatByteSize($iSize) & @CR)
Return DllStructGetData(DllStructCreate('byte[' & DllStructGetSize($tOut) & ']', DllStructGetPtr($tOut)), 1)
EndFunc ;==>_GetScreenshot
Func _GDIPlus_ImageSaveToStream($hImage, $pStream, $pEncoder, $pParams = 0)
Local $Ret = DllCall($ghGDIPDll, 'uint', 'GdipSaveImageToStream', 'ptr', $hImage, 'ptr', $pStream, 'ptr', $pEncoder, 'ptr', $pParams)
If (@error) Or ($Ret[0]) Then
Return SetError(@error, @extended, 0)
EndIf
Return 1
EndFunc ;==>_GDIPlus_ImageSaveToStream