Introduction
When I was trying to implement video preview in my programs, I have been found some documentation an example to use VFW (Video For Windows) tecnology and it seems to be more simple than DirectShow and taking some code from here and from there, I wrote my C++ VFW class. But on some Windows version combined with some camera drivers, often, it shows the source selection window instead the preview window and it was impossible to use it. So.... I have decided to start writing another class to handle WDM (Windows Driver Mode).
Finally, I have written two classes, one for VFW and one for WDM. For now this is a basic approach, this code implements only Video Preview (...for now). For writing this classes I used MSDN help and Your help too, so, I hope it can be usefull for who is starting using Video Capture (like me...). Everyone can add features to this class, like video analizing, capturing and so on.
I develope my Windows programs with Builder C++ XE2 compiler but these class are written using the most compatibility win32 api, so, they can be used with any compilers (I hope it).
The peculiarity of this code is that the public functions of both classes are the same, so, You can write only one program to handle VFW of WDM class.
I have commented the code in Doxygen mode, compiled and added it to the downloadable file, so You can open the index.html page in html folder to consult classes documentation.
Using the code:
1. Include the header file:
#include "VfwVideoCap.h"
or
#include "WdmVideoCap.h"
2. Declare a pointer to the class ( I suggest You to declare it global)
DVfwCap *cap;
or
DWdmCap *cap;
3. Create a class instance, you must specify the handle of the window on which You want to see the preview
cap=new DVfwCap(hWnd);
or
cap=new DWdmCap(hWnd);
4. From here You can use the same calls to handle the preview window
cap->CreateCapWindow(0, 0, 0, 320, 240 ); cap->StartPreview();
...That's all, it's easy
You can also handle the previewing using:
cap->StopPreview(); cap->PausePreview() cap->SetCapSize(0,0,640,480);
before exit program don't forget to destroy the class instance
delete cap;
List of funcions that can be used in both classes:
int EnumerateVideoCaptureDevices(void);
int EnumerateVideoCompressorDevices(void);
char* GetVideoCaptureDeviceName(unsigned int DeviceId);
char* GetVideoCompressorDeviceName(unsigned int DeviceId);
HRESULT CreateCapWindow(HWND hwndParent, int iDeviceID, int X, int Y, int iWidth, int iHeight);
HRESULT CreateCapWindow(int iDeviceID, int X, int Y, int Width, int Height);
HRESULT CreateCapWindow(void);
HRESULT SetCapSize(int X, int Y, int Width, int Height);
HRESULT SetLowRes(void);
HRESULT SetMidRes(void);
HRESULT SetHiRes(void);
bool StartPreview(void);
bool StopPreview(void);
bool PausePreview(void);
void ShowPreviewWindow(void);
void HidePreviewWindow(void);
See the class documenation for using its.