Advertisement

Using a avi with Windows MCI?

Started by August 27, 2002 08:26 PM
4 comments, last by Noods 22 years, 4 months ago
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!
Can you give us some source code?
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
Advertisement
Here we go:

quote: #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 LoadImages(LPDIRECTDRAWSURFACE,LPDIRECTDRAWPALETTE); //LoadImages prototype
BOOL KeyboardHandler(WPARAM keystroke); //KeyboardHandler prototype
LPDIRECTDRAWPALETTE CreatePalette(LPDIRECTDRAWSURFACE surface); //CreatePalette prototype
BOOL InitDirectDraw(HWND hwnd); //InitDirectDraw prototype
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); //WndProc 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
g_MCIHand=MCIWndCreate(hwnd,g_hInstance,
MCIWNDF_NOTIFYMODE|MCIWNDF_NOTIFYMEDIA|
MCIWNDF_NOMENU|MCIWNDF_NOPLAYBAR,filename);
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
if(OK)
OK=LoadImages(lpPrimary,lpPrimaryPalette); //load images from disk
if(!OK) //bail out if LoadImages failed
{
DestroyWindow(hwnd); //close the window we created
return FALSE;
}

PlayMovie("ub.avi";

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
break;

case MCIWNDM_NOTIFYMODE:
if((int)lParam==MCI_MODE_STOP) //if movie over
StartLevel(); //start game engine
break;

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

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
}


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]
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.
Woot!!! Found the problem, thanks anyway.

This topic is closed to new replies.

Advertisement