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:
2. Declare a pointer to the class ( I suggest You to declare it global)
3. Create a class instance, you must specify the handle of the window on which You want to see the preview
4. From here You can use the same calls to handle the preview window
...That's all, it's easy
You can also handle the previewing using:
before exit program don't forget to destroy the class instance
List of funcions that can be used in both classes:
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 SetCapSize(int X, int Y, int Width, int Height);
See the class documenation for using its.