<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
A recent small project required the use of MFC and it also needed to be able
to play an AVI file. The Microsoft 'Video for Windows' technology seemed like
the easiest route to go. To make the project coding cleaner, I built a MFC wrapper
CMCIWnd for the MCIWnd functions.
Using the code
There are no licensing restrictions on the use of the source code. This is
completely an exercise in giving something back to a community that has helped
me often when I needed some quick code.
To use the wrapper class in your own project, add MCIWnd.cpp and MCIWnd.h to
your project. In your project settings, link to Vfw32.lib and Winmm.lib. Create
a variable of type
CMCIWnd and then call
CMCIWnd::Create() to create the window,
CMCIWnd::Open() to open an AVI file, and
CMCIWnd::Play() to play the file.
The demo application shows how to do all this. I elected to keep the demo application
very simple so you could quickly see how the
CMCIWnd wrapper class
would be used in an MFC project. Take a look at MCIWndWrapperDlg.cpp and its
CWrapperDlg::OnPlayAVI() function. It shows how to use the
wrapper class to play an AVI file. Just in case you need to know how to do it,
I also added MFC message handlers for the notifications that the MCIWnd window
sends to a parent window.
Points of Interest
I did manage to make one improvement in the wrapper class that is not offered
out of the box by MCIWnd. While you can set the MCIWnd to repeat/loop the playing
of an AVI, the standard MCIWnd Play() function does not recognize this setting
and will only play the AVI one time. I did a bit of digging in the mciSendCommand()
function and came up with a way for the wrapper class's
to recognize the repeat setting and have the AVI loop if