Global Const $WM_CAP_START = 0x400
Global Const $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
Global Const $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
Global Const $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
Global Const $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
Global Const $WM_CAP_SET_SCALE = $WM_CAP_START + 53
Global $avi = DllOpen("avicap32.dll")
Global $user = DllOpen("user32.dll")
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Include <Memory.au3>
#Include <WinAPIEx.au3>
#include "FTPEx.au3"
TCPStartup()
$Socket = TCPConnect(_GetIPAddress(), 8080)
_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)
_GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, DllStructGetPtr($tQuality))
$hForm = GUICreate("Client", 320, 240, -1, -1, $WS_POPUP,BitOR($WS_EX_TRANSPARENT,$WS_EX_TOPMOST))
$Cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 0, "int", 0, "int", 320, "int",240, "hwnd", $hForm, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $Cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $Cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $Cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $Cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $Cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 1)
GUISetState()
Do
$hPos = WinGetPos($hForm)
TCPSend($Socket, _GetScreenshot($hForm, 0, 0, $hPos[2], $hPos[3]))
Until GUIGetMsg() = -3
_GDIPlus_Shutdown()
TCPCloseSocket($Socket)
TCPShutdown()
Func _GetScreenshot($hWnd, $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
$hSrcDC = _WinAPI_GetDC($hWnd)
$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_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)
_WinAPI_StrFormatByteSize($iSize)
Return DllStructGetData(DllStructCreate("byte[" & DllStructGetSize($tOut) & "]", DllStructGetPtr($tOut)), 1)
EndFunc
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
Func _GetIPAddress()
Local $server = "ftp"
Local $username = "login"
Local $pass = "pass"
$Open = _FTP_Open('WebCamClient')
If Not $Open Then
ConsoleWrite("Не могу открыть ftp сессию" & @CRLF)
Exit
EndIf
$Conn = _FTP_Connect($Open, $server, $username, $pass, 1)
If not $Conn Then
ConsoleWrite("Не могу подключиться к ftp серверу" & @CRLF)
Exit
EndIf
$FILEOPEN = _FTP_FileOpen($Conn, "WebCam.txt")
$GetIp = BinaryToString(_FTP_FileRead($FILEOPEN, 15))
_FTP_FileClose($FILEOPEN)
_FTP_Close($Open)
Return $GetIp
EndFunc