; http://ej.bantz.com/video/ ; http://ej.bantz.com/video/detail/ ; http://www.dotnet4all.com/dotnet-code/2004/12/video-capture.html /* Full blown app possible settings/options (inspired by Dorgem) * Video stream: resolution pixel depth and compression size (bytes) * Capture: 1 - file filetype (avi/pictures) compression framerate location/path watermark auto-name refreshrate (replace or add to max) 2 - ftp (file settings +) url:port log * Motion detection: sensitivity action (run, email) * Multiple camera support ??? */ ; Basic Demo - v 0.2 hModule := DllCall("LoadLibrary", "str", "avicap32.dll") Gui, Add, GroupBox, x4 y4 w492 h100, Available Video Drivers Gui, Add, ListView, x8 y20 w400 h80 vCapDriversLV, Index|Name Gui, Add, Picture, x434 y16 w32 h32 Icon204, %A_WinDir%\system32\shell32.dll Gui, Add, Button, x412 y50 w80 h24 gRefreshDrivers, Refresh Gui, Add, Button, x412 y76 w80 h24 gSelectDriver vSelectDriverB, Select ; --- Video preview section of Gui Gui, Add, GroupBox, x4 y108 w492 h262, Video ; Video preview placeholder Gui, Add, Text, x10 y124 w320 h240 vVidPlaceholder GuiControl, +0x7, VidPlaceholder ; frame Gui, Font, s32 Gui, Add, Text, x32 y200 w280 h64 Center, Preview Gui, Font Gui, Add, CheckBox, x340 y120 w100 h24 vPreviewToggleState gPreviewToggle, Preview video Gui, Add, Button, x440 y120 w50 h24 gCopyToClipBoard, Copy Gui, Add, Button, x400 y160 w90 h24 gSenToFile, &Send to File /* ; --- Presets section Gui, Add, GroupBox, x336 y144 w154 h220, Presets Gui, Add, DropDownList, x342 y164 w142 h30 r30 vPresetChoice, Create new preset...||My save to picture set|My save to avi set|My save to ftp|My motion detection set Gui, Add, Button, x342 y190 w70 h24 vSelectPresetB, Select Gui, Add, Button, x414 y190 w70 h24 vNewPresetB, Edit Gui, Add, Text, x342 y220 w142 h106 vPresetInfoT, Gui, Add, Button, x342 y334 w70 h24 vRunPresetB, Run Gui, Add, Button, x414 y334 w70 h24 vStopPresetB, Stop */ ; --- Statusbar Gui, Add, StatusBar,, Done SB_SetIcon("shell32.dll", 222, 1) ; Get drivers GoSub, RefreshDrivers ; Get handle of Gui Gui +LastFound hwndParent := WinExist() ; Show Gui, Show, w500 h400, Video For Windows for AutoHotkey - VFW4AHK ;Gosub, ConnectToDriver Return PreviewToggle: msgbox Only once! ; If PreviewToggleState GoSub ConnectToDriver ; Else ; GoSub DisconnectDriver Return ConnectToDriver: ; --- Connect and preview capHwnd := Cap_CreateCaptureWindow(hwndParent, 10, 124, 320, 240) ;ToolTip % errorlevel WM_USER = 0x0400 WM_CAP_START := WM_USER WM_CAP_GRAB_FRAME_NOSTOP := WM_USER + 61 WM_CAP_FILE_SAVEDIB := WM_CAP_START + 25 WM_CAP := 0x400 WM_CAP_DRIVER_CONNECT := WM_CAP + 10 WM_CAP_DRIVER_DISCONNECT := WM_CAP + 11 WM_CAP_EDIT_COPY := WM_CAP + 30 WM_CAP_SET_PREVIEW := WM_CAP + 50 WM_CAP_SET_PREVIEWRATE := WM_CAP + 52 WM_CAP_SET_SCALE := WM_CAP + 53 ; Connect to driver if SelectedDriver = { MsgBox, 16, Error!, You didn't select a video driver Return } SendMessage, WM_CAP_DRIVER_CONNECT, %SelectedDriver%, 0, , ahk_id %capHwnd% ;ToolTip % errorlevel ; Set the preview scale SendMessage, WM_CAP_SET_SCALE, 1, 0, , ahk_id %capHwnd% ;ToolTip % errorlevel ; Set the preview rate in milliseconds SendMessage, WM_CAP_SET_PREVIEWRATE, 66, 0, , ahk_id %capHwnd% ;ToolTip % errorlevel ; Start previewing the image from the camera SendMessage, WM_CAP_SET_PREVIEW, 1, 0, , ahk_id %capHwnd% ;ToolTip % errorlevel ToolTip Return CopyToClipBoard: SendMessage, WM_CAP_EDIT_COPY, 0, 0, , ahk_id %capHwnd% Return SenToFile: imagefile = C:\image.bmp SendMessage, WM_CAP_FILE_SAVEDIB, 0, &imagefile, , ahk_id %capHwnd% ToolTip % errorlevel return DisconnectDriver: SendMessage, WM_CAP_DRIVER_DISCONNECT, 1, 0, , ahk_id %capHwnd% Return RefreshDrivers: foundDriver = 0 LV_Delete() Loop { thisInfo := Cap_GetDriverDescription(A_Index-1) If thisInfo { foundDriver = 1 LV_Add("", A_Index-1, thisInfo) } Else Break } If !foundDriver { LV_Delete() LV_Add("", "", "Could not get video drivers") GuiControl, Disable, CapDriversLV GuiControl, Disable, SelectDriverB } Return SelectDriver: FocusedRowNumber := LV_GetNext(0, "F") ; Find the focused row. if not FocusedRowNumber ; No row is focused. return LV_GetText(SelectedDriver, FocusedRowNumber, 1) Return /* '// The two functions exported by AVICap Declare Function capCreateCaptureWindowA Lib "avicap32.dll" ( _ ByVal lpszWindowName As String, _ ByVal dwStyle As Long, _ ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Integer, _ ByVal hWndParent As Long, ByVal nID As Long) As Long Declare Function capGetDriverDescriptionA Lib "avicap32.dll" ( _ ByVal wDriver As Integer, _ ByVal lpszName As String, _ ByVal cbName As Long, _ ByVal lpszVer As String, _ ByVal cbVer As Long) As Boolean */ Cap_CreateCaptureWindow(hWndParent, x, y, w, h) { WS_CHILD := 0x40000000 WS_VISIBLE := 0x10000000 lpszWindowName := "test" lwndC := DLLCall("avicap32.dll\capCreateCaptureWindowA" , "Str", lpszWindowName , "UInt", WS_VISIBLE | WS_CHILD ; dwStyle , "Int", x , "Int", y , "Int", w , "Int", h , "UInt", hWndParent , "Int", 0) ;msgbox % lwndC " | " errorlevel " | " lpszWindowName " | " hwndParent Return lwndC } Cap_GetDriverDescription(wDriver) { VarSetCapacity(lpszName, 100) VarSetCapacity(lpszVer, 100) res := DLLCall("avicap32.dll\capGetDriverDescriptionA" , "Short", wDriver , "Str", lpszName , "Int", 100 , "Str", lpszVer , "Int", 100) If res capInfo := lpszName ; " | " lpszVer Return capInfo } GuiClose: GoSub, DisconnectDriver DllCall("FreeLibrary", "str", hModule) ExitApp Return !r::Reload ; for debugging(Source)
Which implements a WebCam viewing control into an AHK GUI. Very useful. The above version also has a "Save to file" button which is also very cool.
I was wondering if the process could be completed without showing the following dialog when clicking the "Preview" checkbox. The big goal is to be able to complete the processes with my own GUI, with no driver selection or preview check or camera selection,etc.
Thanks in advance.