home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
cyber.net 2
/
cybernet2.ISO
/
qtw111
/
mplayer
/
playmain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-11
|
16KB
|
486 lines
// ---------------------------------------------------------------------
//
// PlayMain.c - Movie Player - QuickTime for Windows
//
// Version 1.0
//
// (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
//
// ---------------------------------------------------------------------
// Includes
// --------
#include <Windows.h> // Required by Windows
#include <qtw.h> // Interface to QuickTime
#include <qtole.h> // Interface to qtole dll's
#include "common.h" // Interface to common.c routines
#include "player.h" // Interface to other *.c files
#include "player.hr" // Defines used in *.rc files
// Message-Persistent Data
// -----------------------
static struct // Hungarian notation: g
{HINSTANCE hInstance; // Instance handle
HINSTANCE hResources; // Resource-only DLL handle
HWND hwndFrame; // Frame window handle
HWND hwndClient; // MDI client window
HMENU hMenu; // Frame window menu
HACCEL hAccel; // Frame window accelerators
HWND hActiveModelessDlg; // Handle of active modeless dlg if any
QTOLE_OLEDATA qtoleOleData; // OLE data struct
} g;
// Internal Function Declarations
// ------------------------------
static LPSTR NEAR PlayerParseCmdLine (LPSTR);
static BOOL NEAR PlayerInitAppl (VOID);
static HWND NEAR PlayerInitInst (HINSTANCE, LPSTR, int);
static LONG NEAR PlayerTerminateInst (VOID);
static BOOL NEAR DoQuickTimeInit (HINSTANCE, LPSTR, LPINT);
static VOID NEAR KillQuickTime (VOID);
// Function: WinMain - Required Windows "Main" Routine
// --------------------------------------------------------------------
// Parameters: As required by Microsoft Windows
//
// Returns: As required by Microsoft Windows
// --------------------------------------------------------------------
int PASCAL WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
// Define function data
{
MSG msg; // Message
g.hInstance = hInstance; // Initialize global data
// Load resource-only DLL
if( !(g.hResources = CommonGetLocalizedResources
( PLAYER_ROOT_NAME, hInstance, PLAYER_STRING_NOMEMORY )))
return 0;
// Perform one-time initialization
if ( !hPrevInstance && !PlayerInitAppl() )
return 0;
// Perform initializations that apply to a specific instance and create
// create window
if ( !PlayerInitInst( hPrevInstance, lpCmdLine, nCmdShow ))
return 0;
// Main message loop
while (GetMessage (&msg, NULL, NULL, NULL)) {
if( !g.hActiveModelessDlg ||
!IsDialogMessage( g.hActiveModelessDlg, &msg )) {
if( !g.hwndClient ||
!TranslateMDISysAccel( g.hwndClient, &msg )) {
if( !g.hwndFrame ||
!TranslateAccelerator( g.hwndFrame, g.hAccel, &msg )) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
}
}
// Cleanup movie player
PlayerTerminateInst();
return msg.wParam;
}
// Function: PlayerInitAppl - Perform One-time Initialization
// --------------------------------------------------------------------
// Parameters: None
//
// Returns: TRUE if OK, else FALSE
// --------------------------------------------------------------------
static BOOL NEAR PlayerInitAppl ( VOID )
{
WNDCLASS wc; // Window class information
// Register the frame (main) window class
wc.style = 0;
wc.lpfnWndProc = PlayerFrameWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g.hInstance;
wc.hIcon = LoadIcon( g.hResources,
MAKEINTRESOURCE( PLAYER_PLAYER_ICON ));
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) ( COLOR_APPWORKSPACE + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = PLAYER_FRAME_CLASS;
if( !RegisterClass( &wc ))
return FALSE;
// Register the movie window class
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = PlayerMovieWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof( VOID NEAR * );
wc.hInstance = g.hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL; // Set to NULL so we can set cursor in the wndproc
wc.hbrBackground = (HBRUSH) NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = PLAYER_MOVIE_CLASS;
return RegisterClass( &wc );
}
// Function: PlayerInitInst - Perform Instance Initialization
// --------------------------------------------------------------------
// Parameters: HINSTANCE hPrevInstance; Previous instance
// LPSTR lpCmdLine; -->Command line arguments
// int nCmdShow; Parameter for first ShowWindow()
//
// Returns: HWND hwndFrame; Frame window handle
// or NULL if initialization failed
// --------------------------------------------------------------------
static HWND NEAR PlayerInitInst
( HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// Do QuickTime Initializations.
if( !DoQuickTimeInit( hPrevInstance, lpCmdLine, &nCmdShow ) )
return NULL;
// get menu and accelerators from localized resource
g.hAccel = LoadAccelerators ( g.hResources,
MAKEINTRESOURCE( PLAYER_ACCELERATORS ));
g.hMenu = LoadMenu( g.hResources,
MAKEINTRESOURCE( PLAYER_FRAME_MENU ));
if( !g.hAccel || !g.hMenu ) {
CommonTellUser( g.hResources, PLAYER_STRING_NOACCELORMENU,
PLAYER_STRING_CAPTION, MB_OK );
return NULL;
}
// Create a main window for this application instance.
if ( !(g.hwndFrame = CreateWindow( PLAYER_FRAME_CLASS, "",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, g.hMenu, g.hInstance, NULL ))) {
CommonTellUser( g.hResources, PLAYER_STRING_NOWINDOW,
PLAYER_STRING_CAPTION, MB_OK );
return NULL;
}
// Tell qtole.dll the server hwnd
QTOLE_SetApplicationHwnd( &g.qtoleOleData, g.hwndFrame );
// get MDI client window created during WM_CREATE message processing
g.hwndClient = PlayerQueryClientWindow(); // this is in FrameWnd.c
// Display the frame window
// If ole started the app, the window will be initially hidden
ShowWindow ( g.hwndFrame, nCmdShow );
if( nCmdShow != SW_HIDE )
UpdateWindow( g.hwndFrame );
// Check command line for movie file.
// Note: this must come after ShowWindow, UpdateWindow
if( lpCmdLine = PlayerParseCmdLine( lpCmdLine ))
SendMessage( g.hwndFrame, WM_PLAYER_CMDLINE,
0, (LPARAM) lpCmdLine );
return g.hwndFrame;
}
// Function: PlayerParseCmdLine - Parse the command line. Return -> to
// first argument and ignore any extras.
// The default extension is appended if
// name has no extension
// --------------------------------------------------------------------
// Parameters: LPSTR lpCmdLine command line pointer
//
// Returns: LPSTR lpCmdLine command line pointer to first
// argument, else NULL
// --------------------------------------------------------------------
static LPSTR NEAR PlayerParseCmdLine( LPSTR lpCmdLine )
{
LPSTR lpTemp; // Temp pointer
char szExtension[FILE_EXT_LEN + 1]; // Default file extension
BOOL bExtension; // Extension flag
// Command line is already in Ansi char set even if entered from DOS
// command line
// remove any leading blanks
while( *lpCm