1. Introduction to MCI & MCIWndCreate
In this article, we will see how we play an AVI video file in MFC Application. To play the AVI file, we will use the Media Control Interface (MCI) function and its API function MCIWndCreate. The Animate control that ships with MFC can play the AVI files, but you will not get any sound when the video is playing. OK. Let us start with this simple and quick example that plays the video file comp.avi. The AVI file that I am packing with this example has no sound information, so replace that with any video file, which has sound information in it. Note, we call the MCIWndCreate API from the MCI interface embedded into the MFC dialog.
2. Start the Project
First, we create a dialog based Visual C++ MFC application and name it as AVIFilePlay. After this step, we need to access the functions from the MCI Library. To provide access to the library, we add Vfw32.lib in the Additional Dependencies Entry of the project settings. The below screenshot shows where we should provide the access to this external library Vfw32.lib:

Once the required library access is provided to the project we can start our coding.
3. Code Implementation
3.1 Include Header File
Add the required header to the Dialog Class Implementation file. In our case, we add the header file in the AviFilePlayDlg.cpp.
1 2 |
//Sample 01: Required Header #include "Vfw.h" include "Vfw.h" |
Note that our project is aware of the header file Vfw.h as in the previous step, we provided access to the required library file.
3.2 Create Media Playback Window Using MCIWndCreate
Next, in the OnInitDialog function implementation, by passing the window handle of our dialog to the function MCIWndCreate, we create the media control interface (MCI) window. Note, the file which we like to play is staying in the D:\Temp directory. We can play the file from any path by pointing out the fully qualified path to the windows media AVI file. The call to the function MCIWndCreate() on success returns the window handle and we store that handle in the hVideoWindow. Below is the code:
1 2 3 4 |
//Sample 02: Create Media Control Interface Window CAVIFilePlayApp* pApp = (CAVIFilePlayApp*) AfxGetApp(); HWND hVideoWindow = MCIWndCreate(this->m_hWnd, pApp->m_hInstance, NULL, _T("D:\Temp\Comp.Avi")); |
3.3 MCIWndPlay of VFW32.Lib
Finally, we make a call to the MCI function MCIWndPlay(). The MCIWndplay() function requires a window handle, which is compatible for playing the window media file (AVI in our case). Below is the code for it:
1 2 |
//Sample 03: Play the Video MCIWndPlay(hVideoWindow); |
When you run the application the video play occurs as shown below:

Source Code: Download MFC Dialog Playing Media File From Google Drive
Categories: MFC
Tags: MCIWndCreate, MCIWndPlay(), Vfw32.lib