home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
cyber.net 2
/
cybernet2.ISO
/
qtw111
/
pviewer
/
viewmain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-11
|
17KB
|
522 lines
// ---------------------------------------------------------------------
//
// ViewMain.c - Picture Viewer - 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
#include "common.h" // Interface to common.c routines
#include "viewer.h" // Interface to other *.c files
#include "viewer.hr" // Defines used in *.rc files
#include "picture.h" // Needed for registering
// child window controls
// 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
BOOL fPalettized; // Palettized device
QTOLE_OLEDATA qtoleOleData; // OLE data struct
} g;
// Internal Function Declarations
// ------------------------------
static LPSTR NEAR ViewerParseCmdLine (LPSTR);
static BOOL NEAR ViewerInitAppl (VOID);
static HWND NEAR ViewerInitInst (HINSTANCE, LPSTR, int);
static LONG NEAR ViewerTerminateInst (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
( VIEWER_ROOT_NAME, hInstance, VIEWER_STRING_NOMEMORY )))
return 0;
// Perform one-time initialization
if( !hPrevInstance && !ViewerInitAppl() )
return 0;
// Perform initializations that apply to a specific instance and
// create window
if( !ViewerInitInst( 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 Picture Viewer
ViewerTerminateInst();
return msg.wParam;
}
// Function: ViewerInitAppl - Perform One-time Initialization
// --------------------------------------------------------------------
// Parameters: None
//
// Returns: TRUE if OK, else FALSE
// --------------------------------------------------------------------
static BOOL NEAR ViewerInitAppl( VOID )
{
WNDCLASS wc; // Window class information
// Register the frame (main) window class
wc.style = 0;
wc.lpfnWndProc = ViewerFrameWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g.hInstance;
wc.hIcon = LoadIcon( g.hResources,
MAKEINTRESOURCE( VIEWER_VIEWER_ICON ));
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) ( COLOR_APPWORKSPACE + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = VIEWER_FRAME_CLASS;
if( !RegisterClass( &wc ))
return FALSE;
// Register the picture window class
wc.style = 0;
wc.lpfnWndProc = ViewerPictureWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof( VOID NEAR * );
wc.hInstance = g.hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = PICBACKGRNDBRUSH;
wc.lpszMenuName = NULL;
wc.lpszClassName = VIEWER_PICTURE_CLASS;
if( !RegisterClass( &wc ))
return FALSE;
// Register the child classes used by the picture windows
// This function is in PictKids.c
if( !RegisterChildControls( g.hInstance ))
return FALSE;
return TRUE;
}
// Function: ViewerInitInst - 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 ViewerInitInst
( HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HDC hdcIC;
// Do QuickTime Initializations.
if( !DoQuickTimeInit( hPrevInstance, lpCmdLine, &nCmdShow ))
return NULL;
// Is this a palettized device?
if( hdcIC = CreateIC( "DISPLAY", NULL, NULL, NULL )) {
g.fPalettized =
( GetDeviceCaps( hdcIC, RASTERCAPS ) & RC_PALETTE );
DeleteDC( hdcIC );
}
// get menu and accelerators from localized resource
g.hAccel = LoadAccelerators( g.hResources,
MAKEINTRESOURCE( VIEWER_ACCELERATORS ));
g.hMenu = LoadMenu( g.hResources,
MAKEINTRESOURCE( VIEWER_FRAME_MENU ));
if( !g.hAccel || !g.hMenu ) {
CommonTellUser( g.hResources, VIEWER_STRING_NOACCELORMENU,
VIEWER_STRING_CAPTION, MB_OK );
return NULL;
}
// Create a main window for this application instance.
if( !(g.hwndFrame = CreateWindow( VIEWER_FRAME_CLASS, "",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, g.hMenu, g.hInstance, NULL ))) {
CommonTellUser( g.hResources, VIEWER_STRING_NOWINDOW,
VIEWER_STRING_CAPTION, MB_OK );
return NULL;
}
// Tell qtole.dll the server hwnd
QTOLE_SetApplicationHwnd( &g.qtoleOleData, g.hwndFrame );
// save MDI client window created during WM_CREATE message processing
g.hwndClient = ViewerQueryClientWindow(); // 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 picture file.
// Note: this must come after ShowWindow, UpdateWindow
if( lpCmdLine = ViewerParseCmdLine( lpCmdLine ))
SendMessage( g.hwndFrame,
WM_VIEWER_CMDLINE, 0, (LPARAM) lpCmdLine );
return g.hwndFrame;
}
// Function: ViewerParseCmdLine - Parse the command line. Return -> to
// first argument and ignore any extras.
// The default extension is added if there
// is no extension
// --------------------------------------------------------------------
// Parameters: LPSTR lpCmdLine command line pointer
//
// Returns: LPSTR lpCmdLine command line pointer to