This is not a hard thing to do.
We are going to use some functions from USER32 and avicap32.dll, so the first thing is to declare them.
<pre>Private Declare Function SendMessage Lib “USER32″ Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function capCreateCaptureWindow Lib “avicap32.dll” Alias “capCreateCaptureWindowA” (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long</pre>
To start using the cam, you need to create a capture window. This could be done in the Form_load event:
<pre>mCapHwnd = capCreateCaptureWindow(“WebcamCapture”, 0, 0, 0, 640, 480, Me.hwnd, 0)
SendMessage mCapHwnd, CONNECT, 0, 0</pre>
Then you get the frame, put it in a PictureBox control, and save it. This can be done in the Click event of a button:
<pre>SendMessage mCapHwnd, GET_FRAME, 0, 0
SendMessage mCapHwnd, COPY, 0, 0
Picture1.Picture = Clipboard.GetData
SavePicture Picture1.Image, “C:\picture.bmp”</pre>
At the end, you should disconnect the capture window:
<pre>SendMessage mCapHwnd, DISCONNECT, 0, 0</pre>
And that’s it.
If you want to see the camera preview, you could create a loop, in which you are getting frames until the user press the button to capture the picture.