Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Using a avi with Windows MCI?

This topic is 5923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im looking for some help from anyone who has ever used an .avi in their program. I have taken some code from a program that displays an .avi and added it to my program. The code is very minimal. My program worked fne before I added the code. All it essentially does is displays a .bmp, and with the added code, it should display a short .avi then display the .bmp. What happens now is the program just bails prematurely. No errors at all. The .avi works fine outside the program. I tried walking through the debugger but it has problems as I am using a full screen window. I am showing the .avi with a Windows API MCI call. Does anyone have any suggestions where I should start troubleshooting this? Thanks!

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Here we go:

#include <windows.h> //system include
#include <windowsx.h> //system include
#include <ddraw.h> //system include
#include <stdio.h> //system include
#include <vfw.h> //system include

#define WIN32_LEAN_AND_MEAN //system define

#include "defines.h" //custom includes
#include "bmpfilereader.h" //custom includes

LPDIRECTDRAW lpDirectDrawObject=NULL; //direct draw object to manage the video hardware
LPDIRECTDRAWSURFACE lpPrimary=NULL; //primary surface
LPDIRECTDRAWPALETTE lpPrimaryPalette; //its palette
BOOL ActiveApp; //is this application active?
HINSTANCE g_hInstance; //instance handle
BOOL g_bPlayingMovie=TRUE; //TRUE if playing a movie
HWND g_MCIHand; //handle to MCI window (for AVI movie)
HWND hwnd; //window handle

BOOL KeyboardHandler(WPARAM keystroke); //KeyboardHandler prototype
LPDIRECTDRAWPALETTE CreatePalette(LPDIRECTDRAWSURFACE surface); //CreatePalette prototype
BOOL InitDirectDraw(HWND hwnd); //InitDirectDraw prototype
HWND CreateDefaultWindow(char* appname,HINSTANCE hInstance); //CreateDefaultWindow prototype

void PlayMovie(char *filename)
DDBLTFX ddBltFx; //blit fx structure
ZeroMemory(&ddBltFx,sizeof(DDBLTFX)); //zero it
ddBltFx.dwSize=sizeof(DDBLTFX); //set size
ddBltFx.dwFillColor=0; //black fill
lpPrimary->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&ddBltFx); //fill
MCIWndPlay(g_MCIHand); // play it

void KillMovie()
if(g_MCIHand) //if valid handle
MCIWndDestroy(g_MCIHand); g_MCIHand=NULL; //kill it

void StartLevel()
KillMovie(); //kill movie
g_bPlayingMovie=FALSE; //movie is off

BOOL KeyboardHandler(WPARAM keystroke) //keyboard handler
BOOL result=FALSE; //return TRUE if game is to end
if(g_bPlayingMovie)StartLevel(); else
switch(keystroke) //what is the keystroke
case VK_ESCAPE: result=TRUE; break; //escape tells us to exit the game
return result;

int WINAPI WinMain(HINSTANCE hInstance, //instance handle
HINSTANCE hPrevInstance, //previous instance
PSTR szCmdLine, //command line
int iCmdShow) //state of the window
char* appname = "Quelzar''s Quest"; //program name
MSG msg; //current message

hwnd=CreateDefaultWindow(appname,hInstance); //create window
if(!hwnd) //bail out if CreateDefaultWindow failed
return FALSE;
ShowWindow(hwnd,iCmdShow); //show window
UpdateWindow(hwnd); //draw the window
SetFocus(hwnd); //allow input from keyboard
ShowCursor(FALSE); //hide the cursor
BOOL OK=InitDirectDraw(hwnd); //initialize DirectDraw
OK=LoadImages(lpPrimary,lpPrimaryPalette); //load images from disk
if(!OK) //bail out if LoadImages failed
DestroyWindow(hwnd); //close the window we created
return FALSE;


while(TRUE) //start message pump
if(PeekMessage(&msg, //pointer to the current message
NULL, //handle to the message whose messages are to be examined
0, //specifies the integer value of the lowest message value to be retreived
0, //specifies the integer value of the highest message value to be retreived
PM_NOREMOVE)) //specifies if messages are removed from the que after processing
if(!GetMessage(&msg, //pointer to the current message
NULL, //handle to the window whose messages need to be retreived
0, //specifies the integer value of the lowest message value to be retreived
0)) //specifies the integer value of the highest message value to be retreived
return msg.wParam; //return message information
TranslateMessage(&msg); //function to translate keyboard messages
DispatchMessage(&msg); //windows message handling function call
else if(!ActiveApp) //check to see if this is the active application
WaitMessage(); //let other programs run if this is not the active window

LRESULT CALLBACK WndProc(HWND hwnd, //window handle
UINT message, //message identifier
WPARAM wParam, //message parameter
LPARAM lParam) //message parameter
switch(message) //loop to compute current message
case WM_ACTIVATEAPP: //message that our window is active
ActiveApp=wParam; //tells the program we are the active application

if((int)lParam==MCI_MODE_STOP) //if movie over
StartLevel(); //start game engine

case WM_KEYDOWN: //keyboard hit
if(KeyboardHandler(wParam)) //check key command
DestroyWindow(hwnd); //close the program

case WM_DESTROY: //close the program message
if(lpDirectDrawObject!=NULL) //if DirectDraw object exists
if(lpPrimary!=NULL) //if primary surface exists
lpPrimary->Release(); //release primary surface
lpDirectDrawObject->Release(); //release DirectDraw object
ShowCursor(TRUE); //show the mouse cursor
PostQuitMessage(0); //drop WinMain out of the message loop
return 0;
return DefWindowProc(hwnd,message,wParam,lParam); //processes any messages this application doesnt process

Share this post

Link to post
Share on other sites
Whoops double post. What is the syntax for putting code in the "code quote?"

[edited by - Noods on August 27, 2002 10:06:01 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Just for your own amusement, this line:

#define WIN32_LEAN_AND_MEAN //system define

has to go before :

#include <windows.h>

or else it does nothing.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!