Click here to Skip to main content
Click here to Skip to main content

MFC Wrapper Class for MCIWnd

, 11 Jan 2003
Rate this:
Please Sign up or sign in to vote.
An MFC Wrapper Class for MCIWnd
<!-- Download Links --> <!-- Article image -->

Sample Image - MCIWndWrapper.gif

<!-- Add the rest of your HTML here -->

Introduction

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 class 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 CMCIWnd 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 CMCIWnd::Play() function to recognize the repeat setting and have the AVI loop if CMCIWnd::GetRepeat() is TRUE.

History

  • 12/25/2002 Created.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Paul Kissel
Web Developer
United States United States
Paul Kissel is presently a Principal with RiverBend Software, Inc. - a consulting services company specializing in the design and development of consumer-focused, commercial application software for Microsoft Windows.

Comments and Discussions

 
QuestionOpen file after play error Pinmemberphydthekid16-Dec-09 4:44 
GeneralDrag the slider hang the application PinmemberHa_Tim10-Dec-09 16:19 
GeneralNeed Information about CDateTimeCtrl in VC++ PinmemberJohn50218-Mar-09 22:28 
GeneralMCIWndOpenInterface & AVI Streams Pinmembersdancer7531-Oct-07 2:02 
GeneralRe: MCIWndOpenInterface & AVI Streams PinmemberViorel.31-Oct-07 3:18 
GeneralRe: MCIWndOpenInterface &amp; AVI Streams [modified] Pinmembersdancer7531-Oct-07 3:48 
GeneralVideo position using time format hh:mm:ss Pinmembersdancer7510-Oct-07 5:21 
QuestionPlay an encrypted AVI PinmemberFarshid13583-May-06 9:50 
GeneralThanks! PinmemberS Douglas24-Jan-06 16:14 
GeneralRe: Thanks! PinmemberLordofthePings11-May-11 9:11 
GeneralRe: Thanks! PinmemberS Douglas11-May-11 11:38 
GeneralMCIWnd Blinks in Upper Left Corner PinsussPFG2329-Mar-05 5:37 
GeneralMCIWnd has severe bug Pinmemberyinfudan16-Jan-05 0:59 
GeneralRe: MCIWnd has severe bug PinsussPFG2329-Mar-05 5:33 
GeneralRe: MCIWnd has severe bug Pinmemberyinfudan29-Mar-05 14:46 
Generalhelp!!!!!! Pinsusssantra11-Jun-03 1:15 
Generalurgent help Pinsusssantra28-May-03 21:36 
GeneralRe: urgent help PinmemberPaul Kissel29-May-03 7:13 
Hi,
 
Glad to help. Well for starters, to try to reproduce the problem I added:
 
// Step the opened AVI file.
m_mciWnd.Step(1);
 
in the sample program's CWrapperDlg::OnPlayAVI() function right before the line:
 
// Play the opened AVI file.
m_mciWnd.Play();
 
The call to Step() returned a 0 return code (no error) and indeed it skipped past the first frame of the video.
 
Try this same test with the sample application running on the machine on which you are seeing the 259 error code.
 
The MCI error return codes for the MCIWnd functions are in the Microsoft header file mmsystem.h. The return codes start at value 257 (MCIERR_BASE + 1). Look for the line in the file:
 
#define MCIERR_INVALID_DEVICE_ID (MCIERR_BASE + 1)
 
The return code of 259 you're getting is:
 
#define MCIERR_UNRECOGNIZED_KEYWORD (MCIERR_BASE + 3)
 
The only reference in MSDN that I could find describes this error as: "An unknown command parameter was specified."
 
Ok, try out the test with the sample and let me know if it works or not...but if it doesn't work, I'm not sure what to tell you. The class I wrote is really just a VERY thin wrapper around the MCIWnd calls and not much more. If you're getting an error, the problem will probably be in the MCIWnd layer and not in my class. Not much there to go wrong.
 
Smiles, Smile | :)
Paul K.
 

GeneralRe: urgent help PinsussSantra1-Jun-03 19:23 
GeneralRe: urgent help PinmemberPaul Kissel1-Jun-03 21:35 
GeneralRe: urgent help Pinmemberluweiwinson16-Jul-08 21:19 
GeneralMemory Leak HELP!!!! PinsussPablo Vivera30-Apr-03 18:56 
GeneralRe: Memory Leak HELP!!!! PinmemberGaryMLong25-Jun-03 16:00 
GeneralRe: Memory Leak HELP!!!! Pinmemberpvivera26-Jun-03 3:41 
GeneralNotification Pinmemberitlk19-Feb-03 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 12 Jan 2003
Article Copyright 2003 by Paul Kissel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid