Jump to content

4 Webcams Program Manager


Recommended Posts

Hello all,

It is my first thread on this forum.

I am a beginner on autoit but i love it.

I am also a beginner on programming.

I have found on this forum more exemple who use the webcam.au3 UDF .

I have modified a little bit the webcam.au3 UDF . Now i can use more than one devices.

webcam.au3 modified

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.11.7 (beta)
Author:         Ludocus
Modified for four webcams
Script Function:
       Webcam Udf

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <WindowsConstants.au3>
#include-once
$WM_CAP_START = 0x400
$WM_CAP_UNICODE_START = $WM_CAP_START +100
$WM_CAP_PAL_SAVEA = $WM_CAP_START + 81
$WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81
$WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW
$WM_CAP_ABORT = $WM_CAP_START + 69
$WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46
$WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43
$WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41
$WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42
$WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10
$WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11
$WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14
$WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12
$WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12
$WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13
$WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13
$WM_CAP_EDIT_COPY = $WM_CAP_START + 30
$WM_CAP_END = $WM_CAP_UNICODE_END
$WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22
$WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21
$WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21
$WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23
$WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23
$WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25
$WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25
$WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20
$WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20
$WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24
$WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36
$WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1
$WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67
$WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67
$WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65
$WM_CAP_GET_STATUS = $WM_CAP_START + 54
$WM_CAP_GET_USER_DATA = $WM_CAP_START + 8
$WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44
$WM_CAP_GRAB_FRAME = $WM_CAP_START + 60
$WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61
$WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83
$WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84
$WM_CAP_PAL_OPENA = $WM_CAP_START + 80
$WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80
$WM_CAP_PAL_PASTE = $WM_CAP_START + 82
$WM_CAP_SEQUENCE = $WM_CAP_START + 62
$WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63
$WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35
$WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85
$WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2
$WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2
$WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5
$WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3
$WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3
$WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6
$WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7
$WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4
$WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66
$WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66
$WM_CAP_SET_OVERLAY = $WM_CAP_START + 51
$WM_CAP_SET_PREVIEW = $WM_CAP_START + 50
$WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52
$WM_CAP_SET_SCALE = $WM_CAP_START + 53
$WM_CAP_SET_SCROLL = $WM_CAP_START + 55
$WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64
$WM_CAP_SET_USER_DATA = $WM_CAP_START + 9
$WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45
$WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72
$WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71
$WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70
$WM_CAP_STOP = $WM_CAP_START + 68
#include <GUIConstants.au3>
$avi = DllOpen("avicap32.dll")
$user = DllOpen("user32.dll")

;===============================================================================
;
; Description:      Open's a webcam preview screen in your gui
; Syntax:           _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight)
; Parameter(s):     $sHwnd     - The handle of the gui
;                   $sLeft     - Left coord. of the preview screen
;                   $sTop      - Top coord. of the preview screen
;                   $sWidth    - Width of the preview screen
;                   $sHeight   - Height of the preview screen
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns id needed for other controls
;                   On Failure - Returns -1
; Author(s):        Ludocus
; Note(s):          None
;
;===============================================================================
func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight,$WebCamId=0)
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", $WebCamId , "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
if @error then return -1
return $cap[0]
EndFunc

;===============================================================================
;
; Description:      Define the device for a webcam
; Syntax:           Settings($sId,$Settings)
; Parameter(s):     $sId       - Id (returned from _WebcamOpen)
;                   $Settings (compression,display,format,source)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        Ludocus
; Note(s):          None
;
;===============================================================================


Func Settings($sId,$Settings)
DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $Settings, "int", 1, "int", 0)
if @error then return -1
return $sId
EndFunc


;===============================================================================
;
; Description:      Creates a Snapshot from a webcam
; Syntax:           _WebcamSnap($sId, $sFile)
; Parameter(s):     $sId       - Id (returned from _WebcamOpen)
;                   $sFile     - File to save the snapshot to (*.bmp)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        Ludocus
; Note(s):          None
;
;===============================================================================
Func _WebcamSnap($sId, $sFile)
;   DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SET_CALLBACK_FRAME, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)
        if @error Then
            return 0
        Else
            return 1
        EndIf
EndFunc

;===============================================================================
;
; Description:      Closes the preview screen created with _WebcamOpen
; Syntax:           _WebcamClose($sId)
; Parameter(s):     $sId       - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        Ludocus
; Note(s):          None
;
;===============================================================================
Func _WebcamClose($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SET_CALLBACK_FRAME, "int", 0, "int", 0);ajout
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)
;   DllClose($avi);ajout
    DllClose($user)
        if @error Then
            return 0
        Else
            return 1
        EndIf
EndFunc

;===============================================================================
;
; Description:      Starts recording the webcam to a file
; Syntax:           _WebcamRecordStart($sFile, $sId)
; Parameter(s):     $sId       - Id (returned from _WebcamOpen)
;                   $sFile     - File to save the movie to (*.avi)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        Ludocus
; Note(s):          Stop recording by: _WebcamRecordStop($Id)
;
;===============================================================================
Func _WebcamRecordStart($sFile, $sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0)
        if @error Then
            return 0
        Else
            return 1
        EndIf

EndFunc

;===============================================================================
;
; Description:      Stops recording.
; Syntax:           _WebcamRecordStop($sId)
; Parameter(s):     $sId       - Id (returned from _WebcamOpen)
; Requirement(s):   A webcam
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
; Author(s):        Ludocus
; Note(s):          None
;
;===============================================================================
Func _WebcamRecordStop($sId)
    DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0)
        if @error Then
            return 0
        Else
            return 1
        EndIf
EndFunc

FunButton.au3 (exemple found it on the french forum )Funkey exemple

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3. (beta)
Author:

Script Function: FunButton Udf

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <WindowsConstants.au3>
#include-once

Func _GUICtrlCreateBitBtn($sText, $iLeft, $iTop, $iWidth, $iHeight, $sImg, $iIndex = 0, $iMaxIconHeight = -1, $iDist = 0, $nAllign = 0, $iFontSize = 8.5, $iFontWeight = Default)
    ;funkey 16.12.2009
    Local $iOffsetX, $iOffsetY, $LabelStyle = 0x201
    Local $a = _GetTextSize("a     a", $iFontSize)
    Local $b = _GetTextSize("aa", $iFontSize)
    Local $SpaceLen = ($a[0] - $b[0]) / 5
    Local $aSize = _GetTextSize($sText, $iFontSize)
    Local $iIconHeight = $iMaxIconHeight
    If $iMaxIconHeight = -1 Or $iMaxIconHeight > $iHeight - 8 Then
        $iIconHeight = $iHeight - 8
    EndIf
    Local $iSpaces = Ceiling(($iIconHeight + $iDist) / $SpaceLen)
    Switch $nAllign
        Case 0 ;Icon is left
            $iOffsetX = $iWidth / 2 - $aSize[0] / 2 - $iIconHeight / 2 - $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
            $sText = StringFormat("%" & $iSpaces + StringLen($sText) & "s", $sText)
        Case 1 ;Icon is right
            $iOffsetX = $iWidth / 2 + $aSize[0] / 2 - $iIconHeight / 2 + $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
            $sText = StringFormat("%" & - $iSpaces - StringLen($sText) & "s", $sText)
        Case 2 ;Icon is on the top
            $iOffsetX = $iWidth / 2 - $iIconHeight / 2
            $iOffsetY = 4
            $LabelStyle = 0x1
        Case 3 ;Icon is on the bottom
            $iOffsetX = $iWidth / 2 - $iIconHeight / 2
            $iOffsetY = $iHeight - $iIconHeight - 4
            $LabelStyle = 0x1
        Case 4 ;Icon is in the middle
            $iOffsetX = $iWidth / 2 - $iIconHeight / 2 + $iDist / 2
            $iOffsetY = ($iHeight - $iIconHeight) / 2
    EndSwitch
    Local $hBtn = GUICtrlCreateLabel("", $iLeft, $iTop, $iWidth, $iHeight)
    GUICtrlCreateIcon($sImg, $iIndex, $iLeft + $iOffsetX, $iTop + $iOffsetY, $iIconHeight, $iIconHeight, 0)
    GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, $LabelStyle, 0x200)
    GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
    GUICtrlSetFont(-1, $iFontSize, $iFontWeight)
    GUICtrlSetState(-1, 32) ;$GUI_HIDE
    GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, $LabelStyle, 0x001)
    GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT
    GUICtrlSetFont(-1, $iFontSize, $iFontWeight)
    Return $hBtn
EndFunc   ;==>_GUICtrlCreateBitBtn

Func _BitBtnClick($IdBtn)
    ;funkey 16.12.2009
    Local $aInfo, $aInfoLast
    GUICtrlSetState($IdBtn + 3, 32) ;$GUI_HIDE
    GUICtrlSetState($IdBtn + 2, 16) ;$GUI_SHOW
    $aInfoLast = GUIGetCursorInfo()
    Do
        Sleep(10)
        $aInfo = GUIGetCursorInfo()
        If @error Then Return 0
        If $aInfo[4] <> $aInfoLast[4] Then ;if changing the hover-control
            If $aInfo[4] < $IdBtn Or $aInfo[4] > $IdBtn + 3 Then ;if not hovering the BitBtn
                GUICtrlSetState($IdBtn + 2, 32) ;$GUI_HIDE
                GUICtrlSetState($IdBtn + 3, 16) ;$GUI_SHOW
            Else
                GUICtrlSetState($IdBtn + 3, 32) ;$GUI_HIDE
                GUICtrlSetState($IdBtn + 2, 16) ;$GUI_SHOW
            EndIf
        EndIf
        $aInfoLast = $aInfo
    Until Not $aInfo[2]
    GUICtrlSetState($IdBtn + 2, 32) ;$GUI_HIDE
    GUICtrlSetState($IdBtn + 3, 16) ;$GUI_SHOW
    If $aInfo[4] <> $IdBtn + 2 And $aInfo[4] <> $IdBtn + 1 Then Return 0
    Return 1
EndFunc   ;==>_BitBtnClick

Func _GetTextSize($nText, $iFontSize = 8.5, $sFont = 'Microsoft Sans Serif', $iFontAttributes = 0)
    ;Author: Bugfix
    ;Modified: funkey
    If $nText = '' Then Return
    _GDIPlus_Startup()
    Local $hFormat = _GDIPlus_StringFormatCreate(0)
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iFontAttributes, 3)
    Local $tLayout = _GDIPlus_RectFCreate(15, 171, 0, 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $nText, $hFont, $tLayout, $hFormat)
    Local $iWidth = Ceiling(DllStructGetData($aInfo[0], "Width"))
    Local $iHeight = Ceiling(DllStructGetData($aInfo[0], "Height"))
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Local $aSize[2] = [$iWidth, $iHeight]
    Return $aSize
EndFunc   ;==>_GetTextSize

Here is my code with several bugs:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\..\..\..\..\..\tmp\Icones\Webcam_4.ico
#AutoIt3Wrapper_outfile=MultiWebcam.exe
#AutoIt3Wrapper_Res_Description=4 Webcam Gui with snapshot bmp and avi files
#AutoIt3Wrapper_Res_Fileversion=0.1.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <AVIConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Webcam.au3>
#include <Date.au3>
#include <GDIPlus.au3>
#include <FunButton.au3>

;Global $sId, $cap, $MultiCam, $pic1, $avi, $user, $snapfile, $formchild1
Global $dt0, $dt1, $dt2, $dt3
Dim $On = "Green-on-16.jpg", $Off = "Red-on-16.jpg", $cap, $avi, $wcamid, $wcamid2, $wcamid3, $wcamid4, $Version = "MultiCam beta v0.1"
;$snapfile = @ScriptDir & "\scrshot.bmp"

;création du fichier ini
If Not FileExists("multicam.ini") Then
Iniwrite("multicam.ini","Devices","NumberOfDevice","4")
Iniwrite("multicam.ini","Devices","DeviceName1","0")
Iniwrite("multicam.ini","Devices","DeviceName2","1")
Iniwrite("multicam.ini","Devices","DeviceName3","2")
Iniwrite("multicam.ini","Devices","DeviceName4","3")
Iniwrite("multicam.ini","SaveNames","Prefix","")
EndIf
$CamId1 = IniRead("multicam.ini","Devices","DeviceName1","")
$CamId2 = IniRead("multicam.ini","Devices","DeviceName2","")
$CamId3 = IniRead("multicam.ini","Devices","DeviceName3","")
$CamId4 = IniRead("multicam.ini","Devices","DeviceName4","")

;définition du préfix des fichiers sauvegardés
Dim $PrefixName, $DateTimeCorrected
$DateTime = _Date_Time_GetSystemTime()
$DateTimeCorrected = StringReplace(StringReplace(StringReplace(_Date_Time_SystemTimeToDateTimeStr($DateTime),"/",""),":","")," ","_")
If IniRead("multicam.ini","SaveNames","Prefix","") = "" Then
    $PrefixName = $DateTimeCorrected
Else
    $PrefixName = IniRead("multicam.ini","SaveNames","Prefix","")&$DateTimeCorrected
EndIf

;définition de la fenêtre principale
#Region ### START Koda GUI section ###
Local $IcoPath = @ScriptDir &  "\Webcam.ico"
Local $IcoBckPath = @ScriptDir &  "\Webcam_Backup.ico"
$MultiCam = GUICreate($Version, 664, 462, 198, 136)

;$Cam1 = GUICtrlCreateButton("Cam 1", 552, 78, 44, 46, $BS_FLAT);ON/OFF caméra 1
;$Cam2 = GUICtrlCreateButton("Cam 2", 613, 78, 44, 46, $BS_FLAT);ON/OFF caméra 2
;$Cam3 = GUICtrlCreateButton("Cam 3", 552, 132, 44, 46, $BS_FLAT);ON/OFF caméra 3
;$Cam4 = GUICtrlCreateButton("Cam 4", 613, 132, 44, 46, $BS_FLAT);ON/OFF caméra 4
$Cam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$Cam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$Cam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 120, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$Cam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 122, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 4


$Led0 = GUICtrlCreatePic("", 595, 72, 6, 40);ON/OFF caméra 1
$Led1 = GUICtrlCreatePic("", 608, 72, 6, 40);ON/OFF caméra 2
$Led2 = GUICtrlCreatePic("", 595, 124, 6, 40);ON/OFF caméra 3
$Led3 = GUICtrlCreatePic("", 608, 124, 6, 40);ON/OFF caméra 4

$Group1 = GUICtrlCreateGroup(" Nbr Of Cam ", 550, 0, 110, 45)
$Group2 = GUICtrlCreateGroup(" Caméra 1 ", 8, 0, 265, 225)
$Group3 = GUICtrlCreateGroup(" Caméra 2 ", 280, 0, 265, 225)
$Group4 = GUICtrlCreateGroup(" Caméra 3 ", 8, 224, 265, 225)
$Group5 = GUICtrlCreateGroup(" Caméra 4 ", 280, 224, 265, 225)
$BTONOFF = GUICtrlCreateGroup(" ON / OFF ", 550, 50, 110, 125)
$Group6 = GUICtrlCreateGroup(" Save Type ", 550, 180, 110, 45)
$BTONOFF = GUICtrlCreateGroup(" Save ", 550, 230, 110, 125)

;$SnapShotCam1 = GUICtrlCreateButton("Cam 1", 552, 278, 44, 46, $BS_FLAT);Snap shot caméra 1
;$SnapShotCam2 = GUICtrlCreateButton("Cam 2", 611, 278, 44, 46, $BS_FLAT);Snap shot caméra 2
;$SnapShotCam3 = GUICtrlCreateButton("Cam 3", 552, 332, 44, 46, $BS_FLAT);Snap shot caméra 3
;$SnapShotCam4 = GUICtrlCreateButton("Cam 4", 611, 332, 44, 46, $BS_FLAT);Snap shot caméra 4
$SnapShotCam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$SnapShotCam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$SnapShotCam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$SnapShotCam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 4

;choix du réglage à afficher
$label1 = GUICtrlCreateLabel("Cam1:", 544, 363, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Cam2:", 544, 383, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label3 = GUICtrlCreateLabel("Cam3:", 544, 403, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label4 = GUICtrlCreateLabel("Cam4:", 544, 423, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label5 = GUICtrlCreateLabel("ConsoleWrite", 42, 448, 500, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$Cam1Settings = GUICtrlCreateCombo("", 580, 360, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam2Settings = GUICtrlCreateCombo("", 580, 380, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam3Settings = GUICtrlCreateCombo("", 580, 400, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam4Settings = GUICtrlCreateCombo("", 580, 420, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")

$Cancel = GUICtrlCreateButton("Cancel", 560, 442, 100, 20, $BS_FLAT);Sortir du pogramme

;choix du nombre de caméra (1 => 1 seule caméra plein écran , 2,3,4 => écran partagé en quatre)
$NbWebCam = GUICtrlCreateCombo("", 555, 15, 100, 25)
GUICtrlSetData(-1, "1|2|3|4", "4")

$SavePicOrAvi = GUICtrlCreateCombo("", 555, 195, 100, 25)
GUICtrlSetData(-1, "Save Bmp|Save Avi|Save Web Page", "Save Bmp")
$AviSave =  GUICtrlRead($SavePicOrAvi)
;If $AviSave = "Save Avi" Then
;$Group7 = GUICtrlCreateGroup(" Time in s ", 680, 200, 80, 50)
;$AviTime =  GUICtrlCreateCombo("", 685, 220, 50, 25)
;GUICtrlSetData(-1, "5|10", "5")
;EndIf
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_SetState($wcamid,12, 15, 257, 201,$CamId1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Cancel
;           For $i = 1 to 4
;               _WebcamClose($CamId1&$i)
;               _WebcamClose($CamId2&$i)
;               _WebcamClose($CamId3&$i)
;               _WebcamClose($CamId4&$i)
;           Next
;           Guidelete($MultiCam)
            Exit

        Case $NbWebCam
            $Nb = GUICtrlRead($NbWebCam)
                Select
                    Case $Nb = "1"
                        _Gui1();GUI une seule caméra prenant toute la fenêtre

                    Case $Nb = "2"
                        _Gui4();GUI quatre caméras sur toute la fenêtre

                    Case $Nb = "3"
                        _Gui4();GUI quatre caméras sur toute la fenêtre

                    Case $Nb = "4"
                        _Gui4();GUI quatre caméras sur toute la fenêtre
                EndSelect

        Case $Cam1;ON/OFF caméra 1
            $wcamid = _WebcamOpen($MultiCam, 12, 15, 257, 201,$CamId1);fenêtre caméra 1
;           WebCamON(12, 15, 257, 201,$CamId1)
            $dt0 = Number(Not($dt0))
            _SetState($wcamid, 12, 15, 257, 201,$CamId1)

        Case $Cam2;ON/OFF caméra 2
            $wcamid2 = _WebcamOpen($MultiCam, 285, 15, 257, 201,$CamId2);fenêtre caméra 2
;           WebCamON(285, 15, 257, 201,$CamId2)
            $dt1 = Number(Not($dt1))
            _SetState($wcamid2,285, 15, 257, 201,$CamId2)

        Case $Cam3;ON/OFF caméra 3
            $wcamid3 = _WebcamOpen($MultiCam, 12, 239, 257, 201,$CamId3);fenêtre caméra 3
;           WebCamON(12, 239, 257, 201,$CamId3)
            $dt2 = Number(Not($dt2))
            _SetState($wcamid3,12, 239, 257, 201,$CamId3)

        Case $Cam4;ON/OFF caméra 4
            $wcamid4 = _WebcamOpen($MultiCam, 285, 239, 257, 201,$CamId4);fenêtre caméra 4
;           WebCamON(285, 239, 257, 201,$CamId4)
            $dt3 = Number(Not($dt3))
            _SetState($wcamid4,285, 239, 257, 201,$CamId4)

        Case $SnapShotCam1
            ;Choix sauvegarde (Bmp ou Avi)
            $SaveCam = GUICtrlRead($SavePicOrAvi)
                Select
                    Case $SaveCam = "Save Bmp"
                        _SaveBmp($wcamid);sauvegarde d'images
                        GuiCtrlSetData($label5, "Cam1 SnapShot file > " &$PrefixName&".bmp")
;                       SnapShot($CamId1, $snapfile)

                    Case $SaveCam = "Save Avi"
                        _SaveAvi($wcamid);sauvegarde par vidéo
                        GuiCtrlSetData($label5, "Cam1 Save video file > " &$PrefixName&".avi")
;                       Select
;                           Case $AviTime = "5"

;                           Case $AviTime = "10"
;                       EndSelect

                    Case $SaveCam = "Save Web Page"
                        _SaveHtmlIp();sauvegarde Bmp dans page Html
                EndSelect

        Case $SnapShotCam2
            $SaveCam = GUICtrlRead($SavePicOrAvi)
                Select
                    Case $SaveCam = "Save Bmp"
;                       DateTime()
                        _SaveBmp($wcamid2);sauvegarde d'images
                        GuiCtrlSetData($label5, "Cam2 SnapShot file > " &$PrefixName&".bmp")
;                       TagTextImage()

                    Case $SaveCam = "Save Avi"
                        _SaveAvi($wcamid2);sauvegarde par vidéo
                        GuiCtrlSetData($label5, "Cam2 Save video file > " &$PrefixName&".avi")
                EndSelect

        Case $SnapShotCam3
            $SaveCam = GUICtrlRead($SavePicOrAvi)
                Select
                    Case $SaveCam = "Save Bmp"
                        _SaveBmp($wcamid3);sauvegarde d'images
                        GuiCtrlSetData($label5, "Cam3 SnapShot file > " &$PrefixName&".bmp")

                    Case $SaveCam = "Save Avi"
                        _SaveAvi($wcamid3);sauvegarde par vidéo
                        GuiCtrlSetData($label5, "Cam3 Save video file > " &$PrefixName&".avi")
                EndSelect

        Case $SnapShotCam4
            $SaveCam = GUICtrlRead($SavePicOrAvi)
                Select
                    Case $SaveCam = "Save Bmp"
                        _SaveBmp($wcamid4);sauvegarde d'images
                        GuiCtrlSetData($label5, "Cam4 SnapShot file > " &$PrefixName&".bmp")

                    Case $SaveCam = "Save Avi"
                        _SaveAvi($wcamid4);sauvegarde par vidéo
                        GuiCtrlSetData($label5, "Cam4 Save video file > " &$PrefixName&".avi")
                EndSelect


        Case $Cam1Settings
            $TypeSetting = GUICtrlRead($Cam1Settings)
                Select
                    Case $TypeSetting = "COMPRESSION"
                        Settings($wcamid,$WM_CAP_DLG_VIDEOCOMPRESSION)

                    Case $TypeSetting = "DISPLAY"
                        Settings($wcamid,$WM_CAP_DLG_VIDEODISPLAY)

                    Case $TypeSetting = "FORMAT"
                        Settings($wcamid,$WM_CAP_DLG_VIDEOFORMAT)

                    Case $TypeSetting = "SOURCE"
                        Settings($wcamid,$WM_CAP_DLG_VIDEOSOURCE)
                EndSelect

        Case $Cam2Settings
            $TypeSetting = GUICtrlRead($Cam2Settings)
                Select
                    Case $TypeSetting = "COMPRESSION"
                        Settings($wcamid2,$WM_CAP_DLG_VIDEOCOMPRESSION)

                    Case $TypeSetting = "DISPLAY"
                        Settings($wcamid2,$WM_CAP_DLG_VIDEODISPLAY)

                    Case $TypeSetting = "FORMAT"
                        Settings($wcamid2,$WM_CAP_DLG_VIDEOFORMAT)

                    Case $TypeSetting = "SOURCE"
                        Settings($wcamid2,$WM_CAP_DLG_VIDEOSOURCE)
                EndSelect

        Case $Cam3Settings
            $TypeSetting = GUICtrlRead($Cam3Settings)
                Select
                    Case $TypeSetting = "COMPRESSION"
                        Settings($wcamid3,$WM_CAP_DLG_VIDEOCOMPRESSION)

                    Case $TypeSetting = "DISPLAY"
                        Settings($wcamid3,$WM_CAP_DLG_VIDEODISPLAY)

                    Case $TypeSetting = "FORMAT"
                        Settings($wcamid3,$WM_CAP_DLG_VIDEOFORMAT)

                    Case $TypeSetting = "SOURCE"
                        Settings($wcamid3,$WM_CAP_DLG_VIDEOSOURCE)
                EndSelect

        Case $Cam4Settings
            $TypeSetting = GUICtrlRead($Cam4Settings)
                Select
                    Case $TypeSetting = "COMPRESSION"
                        Settings($wcamid4,$WM_CAP_DLG_VIDEOCOMPRESSION)

                    Case $TypeSetting = "DISPLAY"
                        Settings($wcamid4,$WM_CAP_DLG_VIDEODISPLAY)

                    Case $TypeSetting = "FORMAT"
                        Settings($wcamid4,$WM_CAP_DLG_VIDEOFORMAT)

                    Case $TypeSetting = "SOURCE"
                        Settings($wcamid4,$WM_CAP_DLG_VIDEOSOURCE)
                EndSelect
    EndSwitch
WEnd

Func _Gui1()
Local $IcoPath = @ScriptDir &  "\Webcam.ico"
Local $IcoBckPath = @ScriptDir &  "\Webcam_Backup.ico"
$MultiCam1 = GUICreate($Version, 664, 462, 198, 136, BitOR($WS_CHILD, $WS_TABSTOP), -1, $MultiCam)

;$Cam1 = GUICtrlCreateButton("Cam 1", 552, 78, 44, 46, $BS_FLAT);ON/OFF caméra 1
;$Cam2 = GUICtrlCreateButton("Cam 2", 613, 78, 44, 46, $BS_FLAT);ON/OFF caméra 2
;$Cam3 = GUICtrlCreateButton("Cam 3", 552, 132, 44, 46, $BS_FLAT);ON/OFF caméra 3
;$Cam4 = GUICtrlCreateButton("Cam 4", 613, 132, 44, 46, $BS_FLAT);ON/OFF caméra 4
$Cam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$Cam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$Cam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 120, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$Cam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 122, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 4


$Led0 = GUICtrlCreatePic("", 595, 72, 6, 40);ON/OFF caméra 1
$Led1 = GUICtrlCreatePic("", 608, 72, 6, 40);ON/OFF caméra 2
$Led2 = GUICtrlCreatePic("", 595, 124, 6, 40);ON/OFF caméra 3
$Led3 = GUICtrlCreatePic("", 608, 124, 6, 40);ON/OFF caméra 4

$Group1 = GUICtrlCreateGroup(" Nbr Of Cam ", 550, 0, 110, 45)
$Group2 = GUICtrlCreateGroup(" Caméra 1 ", 8, 0, 265, 225)
$Group3 = GUICtrlCreateGroup(" Caméra 2 ", 280, 0, 265, 225)
$Group4 = GUICtrlCreateGroup(" Caméra 3 ", 8, 224, 265, 225)
$Group5 = GUICtrlCreateGroup(" Caméra 4 ", 280, 224, 265, 225)
$BTONOFF = GUICtrlCreateGroup(" ON / OFF ", 550, 50, 110, 125)
$Group6 = GUICtrlCreateGroup(" Save Type ", 550, 180, 110, 45)
$BTONOFF = GUICtrlCreateGroup(" Save ", 550, 230, 110, 125)

;$SnapShotCam1 = GUICtrlCreateButton("Cam 1", 552, 278, 44, 46, $BS_FLAT);Snap shot caméra 1
;$SnapShotCam2 = GUICtrlCreateButton("Cam 2", 611, 278, 44, 46, $BS_FLAT);Snap shot caméra 2
;$SnapShotCam3 = GUICtrlCreateButton("Cam 3", 552, 332, 44, 46, $BS_FLAT);Snap shot caméra 3
;$SnapShotCam4 = GUICtrlCreateButton("Cam 4", 611, 332, 44, 46, $BS_FLAT);Snap shot caméra 4
$SnapShotCam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$SnapShotCam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$SnapShotCam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$SnapShotCam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 4

;choix du réglage à afficher
$label1 = GUICtrlCreateLabel("Cam1:", 544, 363, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Cam2:", 544, 383, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label3 = GUICtrlCreateLabel("Cam3:", 544, 403, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label4 = GUICtrlCreateLabel("Cam4:", 544, 423, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label5 = GUICtrlCreateLabel("ConsoleWrite", 42, 448, 500, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$Cam1Settings = GUICtrlCreateCombo("", 580, 360, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam2Settings = GUICtrlCreateCombo("", 580, 380, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam3Settings = GUICtrlCreateCombo("", 580, 400, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam4Settings = GUICtrlCreateCombo("", 580, 420, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")

$Cancel = GUICtrlCreateButton("Cancel", 560, 442, 100, 20, $BS_FLAT);Sortir du pogramme

;choix du nombre de caméra (1 => 1 seule caméra plein écran , 2,3,4 => écran partagé en quatre)
$NbWebCam = GUICtrlCreateCombo("", 555, 15, 100, 25)
GUICtrlSetData(-1, "1|2|3|4", "4")

$SavePicOrAvi = GUICtrlCreateCombo("", 555, 195, 100, 25)
GUICtrlSetData(-1, "Save Bmp|Save Avi|Save Html>IP", "Save Bmp")
$AviSave =  GUICtrlRead($SavePicOrAvi)
;If $SavePicOrAvi = "Save Avi" Then
;$AviTime =  GUICtrlCreateCombo("Avi Time", 685, 220, 50, 25)
;GUICtrlSetData(-1, "5|10", "5")
;EndIf
GUISetState(@SW_SHOW, $MultiCam1)
GUISwitch($MultiCam)
EndFunc

Func _Gui4()
Local $IcoPath = @ScriptDir &  "\Webcam.ico"
Local $IcoBckPath = @ScriptDir &  "\Webcam_Backup.ico"
$MultiCam4 = GUICreate($Version, 664, 462, 198, 136, BitOR($WS_CHILD, $WS_TABSTOP), -1, $MultiCam)

;$Cam1 = GUICtrlCreateButton("Cam 1", 552, 78, 44, 46, $BS_FLAT);ON/OFF caméra 1
;$Cam2 = GUICtrlCreateButton("Cam 2", 613, 78, 44, 46, $BS_FLAT);ON/OFF caméra 2
;$Cam3 = GUICtrlCreateButton("Cam 3", 552, 132, 44, 46, $BS_FLAT);ON/OFF caméra 3
;$Cam4 = GUICtrlCreateButton("Cam 4", 613, 132, 44, 46, $BS_FLAT);ON/OFF caméra 4
$Cam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$Cam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 68, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$Cam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 120, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$Cam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 122, 44, 46, $IcoPath, 20, 35, 0, 3, 10);ON/OFF caméra 4


$Led0 = GUICtrlCreatePic("", 595, 72, 6, 40);ON/OFF caméra 1
$Led1 = GUICtrlCreatePic("", 608, 72, 6, 40);ON/OFF caméra 2
$Led2 = GUICtrlCreatePic("", 595, 124, 6, 40);ON/OFF caméra 3
$Led3 = GUICtrlCreatePic("", 608, 124, 6, 40);ON/OFF caméra 4

$Group1 = GUICtrlCreateGroup(" Nbr Of Cam ", 550, 0, 110, 45)
$Group2 = GUICtrlCreateGroup(" Caméra 1 ", 8, 0, 265, 225)
$Group3 = GUICtrlCreateGroup(" Caméra 2 ", 280, 0, 265, 225)
$Group4 = GUICtrlCreateGroup(" Caméra 3 ", 8, 224, 265, 225)
$Group5 = GUICtrlCreateGroup(" Caméra 4 ", 280, 224, 265, 225)
$BTONOFF = GUICtrlCreateGroup(" ON / OFF ", 550, 50, 110, 125)
$Group6 = GUICtrlCreateGroup(" Save Type ", 550, 180, 110, 45)
$BTONOFF = GUICtrlCreateGroup(" Save ", 550, 230, 110, 125)

;$SnapShotCam1 = GUICtrlCreateButton("Cam 1", 552, 278, 44, 46, $BS_FLAT);Snap shot caméra 1
;$SnapShotCam2 = GUICtrlCreateButton("Cam 2", 611, 278, 44, 46, $BS_FLAT);Snap shot caméra 2
;$SnapShotCam3 = GUICtrlCreateButton("Cam 3", 552, 332, 44, 46, $BS_FLAT);Snap shot caméra 3
;$SnapShotCam4 = GUICtrlCreateButton("Cam 4", 611, 332, 44, 46, $BS_FLAT);Snap shot caméra 4
$SnapShotCam1 = _GUICtrlCreateBitBtn("Cam 1", 552, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 1
$SnapShotCam2 = _GUICtrlCreateBitBtn("Cam 2", 613, 248, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 2
$SnapShotCam3 = _GUICtrlCreateBitBtn("Cam 3", 552, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 3
$SnapShotCam4 = _GUICtrlCreateBitBtn("Cam 4", 613, 302, 44, 46, $IcoBckPath, 20, 35, 0, 3, 10);ON/OFF caméra 4

;choix du réglage à afficher
$label1 = GUICtrlCreateLabel("Cam1:", 544, 363, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Cam2:", 544, 383, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label3 = GUICtrlCreateLabel("Cam3:", 544, 403, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label4 = GUICtrlCreateLabel("Cam4:", 544, 423, 40, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$label5 = GUICtrlCreateLabel("ConsoleWrite", 42, 448, 500, 25)
GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")
$Cam1Settings = GUICtrlCreateCombo("", 580, 360, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam2Settings = GUICtrlCreateCombo("", 580, 380, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam3Settings = GUICtrlCreateCombo("", 580, 400, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")
$Cam4Settings = GUICtrlCreateCombo("", 580, 420, 80, 25)
GUICtrlSetData(-1, "COMPRESSION|DISPLAY|FORMAT|SOURCE", "SOURCE")

$Cancel = GUICtrlCreateButton("Cancel", 560, 442, 100, 20, $BS_FLAT);Sortir du pogramme

;choix du nombre de caméra (1 => 1 seule caméra plein écran , 2,3,4 => écran partagé en quatre)
$NbWebCam = GUICtrlCreateCombo("", 555, 15, 100, 25)
GUICtrlSetData(-1, "1|2|3|4", "4")

$SavePicOrAvi = GUICtrlCreateCombo("", 555, 195, 100, 25)
GUICtrlSetData(-1, "Save Bmp|Save Avi|Save Html>IP", "Save Bmp")
$AviSave =  GUICtrlRead($SavePicOrAvi)
;If $SavePicOrAvi = "Save Avi" Then
;$AviTime =  GUICtrlCreateCombo("Avi Time", 685, 220, 50, 25)
;GUICtrlSetData(-1, "5|10", "5")
;EndIf
GUISetState(@SW_SHOW, $MultiCam4)
GUISwitch($MultiCam)
EndFunc;Fin Gui à quatre caméras

Func _SaveBmp($WebcamId);sauvegarde d'une image bmp
        ConsoleWrite("Taking snapshot ..." &$PrefixName&".bmp"& @CRLF)
        _WebcamSnap($WebcamId,@ScriptDir & "\"&$PrefixName&".bmp")
;       GuiCtrlSetData($label5, " SnapShot file > " &$PrefixName&".bmp")
        ;compression de bmp en jpg
        _GDIPlus_StartUp()
        $img = _GDIPlus_ImageLoadFromFile($PrefixName&".bmp")
        $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
        _GDIPlus_ImageSaveToFileEx ($img, $PrefixName&".jpg", $sCLSID)
        _GDIPlus_ShutDown()
;       msgbox(0,"msgbox",$PrefixName)
        sleep(1000)
        If FileExists(@ScriptDir & "\"&$PrefixName&".bmp") Then
        Filedelete($PrefixName&".bmp")
        EndIf
EndFunc

Func _SaveAvi($WebcamId);sauvegarde d'une vidéo
        ConsoleWrite("Taking snapshot ..." &$PrefixName&@CRLF)
;       GuiCtrlSetData($label5, "Save video file > " &$PrefixName&".avi")
        _WebcamRecordStart(@ScriptDir & "\"&$PrefixName&".avi", $WebcamId)

;       sleep(10000)
        _WebcamRecordStop($WebcamId)
EndFunc

Func TagTextImage()
;Add the text to a new image
$hImage   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\splash.bmp")
$hBmp = _ImageDrawText((@ScriptDir & "\splash.bmp"), "Text drawn on image", 100, 200, 0xFFFFFF)
EndFunc

#cs
Func TextToImage($PictureBMP,$sString,$FontName,$FontSize,$XsString,$YsString)
;$PictureBMP.....: Picture's name to load
;$sString........: Text to write on the picture
;$FontName.......: Font name
;$FontSize.......: Font's size
;$XsString.......: X text's position
;$YsString.......: Y text's position
; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $DateTime = _Date_Time_GetSystemTime()
Global $DateTimeCorrected = StringReplace(StringReplace(StringReplace(_Date_Time_SystemTimeToDateTimeStr($DateTime),"/",""),":","")," ","_")
Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
;Global $sString = "  Created with AutoIt  "
Global $sString = $DateTimeCorrected

; Initialize GDI+ library
_GDIPlus_StartUp()

; Capture screen
;$hBitmap  = _ScreenCapture_Capture(@Scriptdir & '\'& $PictureBMP)
$hBitmap  = @Scriptdir & '\'& $PictureBMP

; Load image and emboss text
$hImage   = _GDIPlus_ImageLoadFromFile(@Scriptdir & '\'& $PictureBMP)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hFamily  = _GDIPlus_FontFamilyCreate("Arial")
$hFont    = _GDIPlus_FontCreate($hFamily, 16, 1)
$tLayout  = _GDIPlus_RectFCreate(0, 0)
$hFormat  = _GDIPlus_StringFormatCreate(2)
$hBrush1  = _GDIPlus_BrushCreateSolid(0xA2FFFFFF)
$hBrush2  = _GDIPlus_BrushCreateSolid(0xC4FF0000)
$hPen     = _GDIPlus_PenCreate(0xC4000000, 2)
$aInfo    = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth   = DllStructGetData($aInfo[0], "Width" )
$iHeight  = DllStructGetData($aInfo[0], "Height")

_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush1)
_GDIPlus_GraphicsDrawRect($hGraphic, 1, 1, $iWidth, $iHeight, $hPen   )
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2)

; Save image
_GDIPlus_ImageSaveToFile($hImage, @Scriptdir & '\'& $PictureBMP)

; Free resources
_GDIPlus_PenDispose         ($hPen    )
_GDIPlus_BrushDispose       ($hBrush1 )
_GDIPlus_BrushDispose       ($hBrush2 )
_GDIPlus_StringFormatDispose($hFormat )
_GDIPlus_FontDispose        ($hFont   )
_GDIPlus_FontFamilyDispose  ($hFamily )
_GDIPlus_GraphicsDispose    ($hGraphic)
_GDIPlus_ImageDispose       ($hImage  )
_GDIPlus_ShutDown()

; Show image
;Run("MSPaint.exe " & '"' & @Scriptdir & '\'& $PictureBMP')
EndFunc
#ce

Func _ImageDrawText($hImage, $sText, $iX = 0, $iY = 0, $iRGB = 0x000000, $iSize = 9, $iStyle = 0, $sFont = "Arial")
    Local $w, $h, $hGraphic1, $hBitmap, $hGraphic2, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo
    $w = _GDIPlus_ImageGetWidth($hImage)
    $h = _GDIPlus_ImageGetHeight($hImage)

    ;Create a new bitmap, this way the original opened png is left unchanged

;    $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND(_WinAPI_GetDesktopWindow())
    $hGraphic1   = _GDIPlus_ImageLoadFromFile(@Scriptdir & '\' & $hImage)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphic1)
    $hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    ; Draw the original opened png into my newly created bitmap
    _GDIPlus_GraphicsDrawImageRect($hGraphic2, $hImage, 0, 0, $w, $h)

    ;Create the font
    $hBrush = _GDIPlus_BrushCreateSolid ("0xFF" & Hex($iRGB, 6))
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate ($sFont)
    $hFont = _GDIPlus_FontCreate ($hFamily, $iSize, $iStyle)
    $tLayout = _GDIPlus_RectFCreate ($iX, $iY, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic2, $sText, $hFont, $tLayout, $hFormat)

    ;Draw the font onto the new bitmap
    _GDIPlus_GraphicsDrawStringEx ($hGraphic2, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)

    ; Save image
    _GDIPlus_ImageSaveToFile($hGraphic2, $hImage)

    ;Cleanup the no longer needed resources
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic2)
    _GDIPlus_GraphicsDispose ($hGraphic1)

    ;Return the new bitmap
    Return $hBitmap
EndFunc

Func _SaveHtmlIp();sauvegarde Bmp dans page Html
            SplashTextOn("Warning !!!", "This option is " & _
                "not actived !!!", 250, 60, 350, 350, 0, "", 12, 800)
        Sleep(3000)
        SplashOff()
EndFunc

Func WebCamON($sLeft, $sTop, $sWidth, $sHeight,$CamId)
$formchild = GUICreate("", $sLeft, $sTop, $sWidth, $sHeight, BitOR($WS_CHILD, $WS_TABSTOP), -1, $MultiCam)
_WebcamOpen($MultiCam, $sLeft, $sTop, $sWidth, $sHeight,$CamId)
#cs
$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 12, "int", 15, "int", 257, "int", 201, "hwnd", $MultiCam, "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", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)
DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)
#ce
GUISetState(@SW_SHOW, $formchild)
GUISwitch($MultiCam)
EndFunc

;definition de l'état des led ON OFF
Func _SetState($Nbwcamid,$sLeft, $sTop, $sWidth, $sHeight, $CamId)
        For $i = 0 To 3
            If Eval('dt' & $i) = 1 Then
                GUICtrlSetImage(Eval('led' & $i), $On)
;               $formchild = GUICreate("", $sLeft, $sTop, $sWidth, $sHeight, BitOR($WS_CHILD, $WS_TABSTOP), -1, $MultiCam)
;               $Nbwcamid = _WebcamOpen($MultiCam, $sLeft, $sTop, $sWidth, $sHeight,$CamId)
;               GUISetState(@SW_SHOW, $formchild)
;               GUISwitch($MultiCam)
            Else
                GUICtrlSetImage(Eval('led' & $i), $Off)
;               _WebcamClose($CamId)
;               DllClose($user)
;               GUIDelete($formchild)
;               GUICtrlDelete($CamId)
;               GUICtrlDelete($avi)
;~              GUIDelete($cap)
;~              GUIDelete($avi)
;               GUICtrlDelete($user)
;               GUIctrlSetState(@SW_HIDE, $formchild)
;               GUISetState(@SW_hide, $formchild)
            EndIf
        Next
EndFunc   ;==>_SetState

Actually i can to do:

-save bmp or avi for each webcam but only if on cam is ON

-define the device for each webcam in a ini file

[Devices]
NumberOfDevice=4
DeviceName1=0
DeviceName2=1
DeviceName3=2
DeviceName4=3
[SaveNames]
Prefix=

-change the settings after a webcam ON command (format,compression,source)

That i can't to do:

-close a webcam

-exit the program if more than one webcam is on

-save a bmp/avi file if more than one webcam is on

-can't to delete the bmp file when the jpg file is created.

All files are downloadable 4webcams.zip

Thanks for any help for to finish this program !!!

Edited by pierrotm777
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...