Code: Select all
ImageGadget(#Image,window1X,window1Y, videoW, videoH,UseImage(71))
Code: Select all
ImageGadget(#Image,window1X,window1Y, videoW, videoH,UseImage(71))
Code: Select all
Procedure MyWebcamErrorCallback(hwnd.l, nID.l, lpsz.l)
If nID = #IDS_CAP_DRIVER_ERROR ; (= 418) there are more error messages available but for now i only use 418
MessageRequester("Error", "Error connecting to capture device." + Chr(10)+Chr(13) + "Application will now close", #MB_ICONERROR)
CloseWindow(#Window_0)
Else
MessageRequester("Error", "Unspecified capture device error (" + Str(nID) + ")", #MB_ICONERROR)
EndIf
EndProcedure
Code: Select all
OpenLibrary(0, "C:\WINDOWS\system32\avicap32.dll") ; don't forget to CloseLibray(0) when finished
;- use this to enumerate and get driver info. I only have 1 VFW driver so I use driver 0
driverName$ = Space(256)
driverVer$ = Space(256)
*driverInfo = IsFunction(0, "capGetDriverDescriptionA")
webcam = #False
For driverID = 0 To 9
If CallFunctionFast(*driverInfo, driverID, @driverName$, 256, @driverVer$, 256)
; you can select your driverID from here
webcam = #True
Debug driverID ; remove
Debug driverName$ ; remove
Debug driverVer$ ; remove
EndIf
Next
If webcam
; A capture driver has been found. In a few lines down from
; here, we'll see if a capture device can be found (connected)
useDriverID = 0 ; my one and only VFW driver
Else
MyWebcamErrorCallback(0, #IDS_CAP_DRIVER_ERROR, 0)
EndIf
Code: Select all
;- define capture device error callback procedure
SendMessage_(handle_to_your_capture_window, #WM_CAP_SET_CALLBACK_ERRORA, 0, @MyWebcamErrorCallback())
Code: Select all
If SendMessage_(handle_to_your_capture_window, #WM_CAP_DRIVER_CONNECT, useDriverID, 0)
Code: Select all
#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_FILE_SAVEDIBA = #WM_CAP_START + 25
#WM_CAP_GRAB_FRAME = #WM_CAP_START + 60
#WM_CAP_STOP = #WM_CAP_START + 68
Global hWndC
Procedure SnapShot()
If OpenWindow(0,0,0,0,0,#PB_Window_SystemMenu,"test")
If OpenLibrary(0, "avicap32.dll")
*capAddress = IsFunction(0, "capCreateCaptureWindowA")
hWndC = CallFunctionFast(*capAddress, "", #WS_CHILD, 10, 10, 320, 240, WindowID(0),1)
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_GRAB_FRAME, 0, 0)
SendMessage_(hWndC, #WM_CAP_FILE_SAVEDIBA, 0, "test.bmp")
SendMessage_(hWndC, #WM_CAP_STOP, 0, 0)
SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow_(hWndC)
CloseLibrary(0)
EndIf
EndIf
EndProcedure
SnapShot()
Code: Select all
#WM_CAP_START = #WM_USER
#WM_CAP_DRIVER_CONNECT = #WM_CAP_START + 10
#WM_CAP_DRIVER_DISCONNECT = #WM_CAP_START + 11
#WM_CAP_FILE_SAVEDIBA = #WM_CAP_START + 25
#WM_CAP_GRAB_FRAME = #WM_CAP_START + 60
#WM_CAP_STOP = #WM_CAP_START + 68
#WM_CAP_SET_CALLBACK_ERRORA = #WM_CAP_START + 2 ; define your callback constant
#IDS_CAP_DRIVER_ERROR = 418 ; Driver specific error message
Global hWndC
Procedure myWindowCallback(hwnd, msg, wParam, lParam)
Shared dlgClosed
result = #PB_ProcessPureBasicEvents
; handle video source dialog (here we close it by sending Escape key)
; kind of messy right now but it seems to work
If hwnd = WindowID(0) And msg = #WM_KILLFOCUS And driverConnected = #False
hDlg = FindWindowEx_(0, 0, "#32770", "Video Source") ; get the handle to the dialog
EndIf
If hDlg <> 0 And driverConnected = #False
If dlgClosed = #False
dlgClosed = #True ; this ensures we send Escape key one time only
keybd_event_(#VK_ESCAPE, 0, 0, 0)
keybd_event_(#VK_ESCAPE, 0, #KEYEVENTF_KEYUP, 0)
EndIf
EndIf
ProcedureReturn result
EndProcedure
Procedure MyCapErrorCallback(hwnd.l, nId.l, lpsz.l)
If nId = #IDS_CAP_DRIVER_ERROR
MessageRequester("Error", "Error connecting to capture device." + Chr(10)+Chr(13) + "Application will now close", #MB_ICONERROR)
CloseWindow(0)
Else
MessageRequester("Error", "Unspecified capture device error (" + Str(nId) + ")", #MB_ICONERROR)
EndIf
EndProcedure
Procedure SnapShot()
If OpenWindow(0,0,0,0,0,#PB_Window_SystemMenu,"test")
If OpenLibrary(0, "avicap32.dll")
*capAddress = IsFunction(0, "capCreateCaptureWindowA")
hWndC = CallFunctionFast(*capAddress, "", #WS_CHILD, 10, 10, 320, 240, WindowID(0),1)
SendMessage_(hWndC, #WM_CAP_SET_CALLBACK_ERRORA, 0, @MyCapErrorCallback())
SendMessage_(hWndC, #WM_CAP_DRIVER_CONNECT, 0, 0)
SendMessage_(hWndC, #WM_CAP_GRAB_FRAME, 0, 0)
SendMessage_(hWndC, #WM_CAP_FILE_SAVEDIBA, 0, "test.bmp")
SendMessage_(hWndC, #WM_CAP_STOP, 0, 0)
SendMessage_(hWndC, #WM_CAP_DRIVER_DISCONNECT, 0, 0)
DestroyWindow_(hWndC)
CloseLibrary(0)
EndIf
EndIf
EndProcedure
SnapShot()