If you always wanted to create an application which uses a digital camera, this article is just for you. If you know how to deal with Timers and Bitmaps, this is going to be easy. Digital cameras produce bitmap pictures. There are a few simple functions to use, so let's get started.
Add to your project these libraries (project->settings->link): vfw32.lib, user32.lib, winmm.lib.
You must link these .lib files in order to be able to connect to the digital camera driver.
Include in your project, these files:
You must include these files in order to use the *.lib files mentioned above.
Use the following functions:
capDriverConnect (hWndC, 0);
Add member variables:
HWND hWndC as a capture window handle, and:
BITMAP bm; //bitmap struct
CBitmap m_bmp; //bitmap object
//Set a capture window.
hWndC = capCreateCaptureWindow ( "Capture Window", WS_CHILD /*|
WS_VISIBLE /*| WS_THICKFRAME */|WS_DLGFRAME
capDriverConnect (hWndC, 0); // 0 ->means default driver.
AfxMessageBox("Error Cammera is not connected!");//error message box.
SetTimer(1,66,NULL); //For Preview - we sample a frame(picture) from the
//camera every 66 msec.
In order to make a Preview function to view a video stream on a specific
CFrame rectFrame in your dialog (for example):
void CYourProject::OnTimer(UINT nIDEvent)
if(nIDEvent==1)// First Timer
capGrabFrame(hWndC); // simple macro that sample a single frame from the
capEditCopy(hWndC); // simple macro that edit a copy of the frame.
OpenClipboard(); //like virtual memory.
//m_hBmp is a Handle to Bitmap.
m_hBmp = (HBITMAP)::GetClipboardData(CF_BITMAP);
m_bmp.Detach(); //cleaning the bitmap.
m_bmp.Attach(m_hBmp); //connecting the bitmap throw the handle.
InvalidateRect(m_rectFrame,false); // m_rectFrame is the frame that the
// video stream will be present in.
OnPaint(); // calling to paint function to paint the bitmap
// into the frame on the dialog.
If you don't know how to paint a bitmap into a frame (
CFrame), inside the
OnPaint() function, you need to do:
CPaintDC dc(this); // device context for painting
//....... else stuff like icon painting ect.
if(PreViewFlag)//if it is a preview call
Now you can take a snapshot by using the following function:
KillTimer(1);, and you have the picture saved in
m_hBmp (handle to your Bitmap picture).
In order to choose your own camera settings: favorite resolution and pixels depth, you need to use the
capDlgVideoFormat(hWndC); function like this:
hWndC = capCreateCaptureWindow("Capture Window",
WS_CHILD |/* WS_VISIBLE |*//*WS_THICKFRAME*/WS_DLGFRAME,
GetSafeHwnd()/*hwndParent*/, 1);//Set a capture window
capDriverConnect (hWndC, 0);//connect to cammera's driver.
capDlgVideoFormat(hWndC); //to change the resolution and settings.
My name is Eyal Zoref, I'm from Israel, I'm a Management and Software Engineer. View my C.V..
For Q. you can reach me at EMail_ME.