home *** CD-ROM | disk | FTP | other *** search
/ cyber.net 2 / cybernet2.ISO / qtw111 / mplayer / playmain.c < prev    next >
C/C++ Source or Header  |  1994-01-11  |  16KB  |  486 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // PlayMain.c - Movie Player - QuickTime for Windows
  5. //
  6. //              Version 1.0
  7. //
  8. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Includes
  14. // --------
  15. #include <Windows.h> // Required by Windows
  16.  
  17. #include <qtw.h>   // Interface to QuickTime
  18. #include <qtole.h> // Interface to qtole dll's
  19.  
  20. #include "common.h" // Interface to common.c routines
  21.  
  22. #include "player.h"  // Interface to other *.c files
  23. #include "player.hr" // Defines used in *.rc files
  24.  
  25.  
  26. // Message-Persistent Data
  27. // -----------------------
  28. static struct // Hungarian notation: g
  29.   {HINSTANCE      hInstance;          // Instance handle
  30.    HINSTANCE      hResources;         // Resource-only DLL handle
  31.    HWND           hwndFrame;          // Frame window handle
  32.    HWND           hwndClient;         // MDI client window
  33.    HMENU          hMenu;              // Frame window menu
  34.    HACCEL         hAccel;             // Frame window accelerators
  35.    HWND           hActiveModelessDlg; // Handle of active modeless dlg if any
  36.    QTOLE_OLEDATA  qtoleOleData;       // OLE data struct
  37.  
  38.   } g;
  39.  
  40.  
  41. // Internal Function Declarations
  42. // ------------------------------
  43. static LPSTR NEAR PlayerParseCmdLine    (LPSTR);
  44. static  BOOL NEAR PlayerInitAppl        (VOID);
  45. static  HWND NEAR PlayerInitInst        (HINSTANCE, LPSTR, int);
  46. static  LONG NEAR PlayerTerminateInst   (VOID);
  47. static  BOOL NEAR DoQuickTimeInit       (HINSTANCE, LPSTR, LPINT);
  48. static  VOID NEAR KillQuickTime         (VOID);
  49.  
  50.  
  51. // Function: WinMain - Required Windows "Main" Routine
  52. // --------------------------------------------------------------------
  53. // Parameters: As required by Microsoft Windows
  54. //
  55. // Returns:    As required by Microsoft Windows
  56. // --------------------------------------------------------------------
  57. int PASCAL WinMain (HINSTANCE hInstance,
  58.                  HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  59.  
  60. // Define function data
  61.  
  62. {
  63.     MSG  msg; // Message
  64.  
  65.     g.hInstance = hInstance; // Initialize global data
  66.  
  67.     // Load resource-only DLL
  68.     if( !(g.hResources = CommonGetLocalizedResources
  69.         ( PLAYER_ROOT_NAME, hInstance, PLAYER_STRING_NOMEMORY )))
  70.         return 0;
  71.  
  72.     // Perform one-time initialization
  73.     if ( !hPrevInstance && !PlayerInitAppl() )
  74.         return 0;
  75.  
  76.     // Perform initializations that apply to a specific instance and create
  77.     // create window
  78.     if ( !PlayerInitInst( hPrevInstance, lpCmdLine, nCmdShow ))
  79.         return 0;
  80.  
  81.     // Main message loop
  82.     while (GetMessage (&msg, NULL, NULL, NULL)) {
  83.         if( !g.hActiveModelessDlg ||
  84.             !IsDialogMessage( g.hActiveModelessDlg, &msg )) {
  85.             if( !g.hwndClient ||
  86.                 !TranslateMDISysAccel( g.hwndClient, &msg )) {
  87.                 if( !g.hwndFrame ||
  88.                     !TranslateAccelerator( g.hwndFrame, g.hAccel, &msg )) {
  89.                     TranslateMessage (&msg);
  90.                     DispatchMessage  (&msg);
  91.                 }
  92.             }
  93.         }
  94.     }
  95.  
  96.     // Cleanup movie player
  97.  
  98.     PlayerTerminateInst();
  99.  
  100.     return msg.wParam;
  101. }
  102.  
  103.  
  104. // Function: PlayerInitAppl - Perform One-time Initialization
  105. // --------------------------------------------------------------------
  106. // Parameters: None
  107. //
  108. // Returns:    TRUE if OK, else FALSE
  109. // --------------------------------------------------------------------
  110. static BOOL NEAR PlayerInitAppl ( VOID )
  111.  
  112. {
  113.     WNDCLASS wc; // Window class information
  114.  
  115.     // Register the frame (main) window class
  116.  
  117.     wc.style         = 0;
  118.     wc.lpfnWndProc   = PlayerFrameWndProc;
  119.     wc.cbClsExtra    = 0;
  120.     wc.cbWndExtra    = 0;
  121.     wc.hInstance     = g.hInstance;
  122.     wc.hIcon         = LoadIcon( g.hResources,
  123.         MAKEINTRESOURCE( PLAYER_PLAYER_ICON ));
  124.     wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
  125.     wc.hbrBackground = (HBRUSH) ( COLOR_APPWORKSPACE + 1 );
  126.     wc.lpszMenuName  = NULL;
  127.     wc.lpszClassName = PLAYER_FRAME_CLASS;
  128.  
  129.     if( !RegisterClass( &wc ))
  130.         return FALSE;
  131.  
  132.     // Register the movie window class
  133.  
  134.     wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  135.     wc.lpfnWndProc   = PlayerMovieWndProc;
  136.     wc.cbClsExtra    = 0;
  137.     wc.cbWndExtra    = sizeof( VOID NEAR * );
  138.     wc.hInstance     = g.hInstance;
  139.     wc.hIcon         = NULL;
  140.     wc.hCursor       = NULL; // Set to NULL so we can set cursor in the wndproc
  141.     wc.hbrBackground = (HBRUSH) NULL;
  142.     wc.lpszMenuName  = NULL;
  143.     wc.lpszClassName = PLAYER_MOVIE_CLASS;
  144.  
  145.     return RegisterClass( &wc );
  146. }
  147.  
  148.  
  149. // Function: PlayerInitInst - Perform Instance Initialization
  150. // --------------------------------------------------------------------
  151. // Parameters: HINSTANCE hPrevInstance;  Previous instance
  152. //             LPSTR     lpCmdLine;      -->Command line arguments
  153. //             int       nCmdShow;       Parameter for first ShowWindow()
  154. //
  155. // Returns:    HWND      hwndFrame;      Frame window handle
  156. //                                       or NULL if initialization failed
  157. // --------------------------------------------------------------------
  158. static HWND NEAR PlayerInitInst
  159.               ( HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  160.  
  161. {
  162.     // Do QuickTime Initializations.
  163.     if( !DoQuickTimeInit( hPrevInstance, lpCmdLine, &nCmdShow ) )
  164.         return NULL;
  165.  
  166.     // get menu and accelerators from localized resource
  167.     g.hAccel = LoadAccelerators ( g.hResources,
  168.         MAKEINTRESOURCE( PLAYER_ACCELERATORS ));
  169.     g.hMenu  = LoadMenu( g.hResources,
  170.         MAKEINTRESOURCE( PLAYER_FRAME_MENU ));
  171.     if( !g.hAccel || !g.hMenu ) {
  172.         CommonTellUser( g.hResources, PLAYER_STRING_NOACCELORMENU,
  173.             PLAYER_STRING_CAPTION, MB_OK );
  174.         return NULL;
  175.     }
  176.  
  177.     // Create a main window for this application instance.
  178.     if ( !(g.hwndFrame = CreateWindow( PLAYER_FRAME_CLASS, "",
  179.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  180.         CW_USEDEFAULT, CW_USEDEFAULT,
  181.         CW_USEDEFAULT, CW_USEDEFAULT,
  182.         NULL, g.hMenu, g.hInstance, NULL ))) {
  183.         CommonTellUser( g.hResources, PLAYER_STRING_NOWINDOW,
  184.             PLAYER_STRING_CAPTION, MB_OK );
  185.         return NULL;
  186.     }
  187.  
  188.     // Tell qtole.dll the server hwnd
  189.     QTOLE_SetApplicationHwnd( &g.qtoleOleData, g.hwndFrame ); 
  190.  
  191.     // get MDI client window created during WM_CREATE message processing
  192.     g.hwndClient = PlayerQueryClientWindow(); // this is in FrameWnd.c
  193.  
  194.     // Display the frame window
  195.     // If ole started the app, the window will be initially hidden
  196.     ShowWindow  ( g.hwndFrame, nCmdShow );
  197.     if( nCmdShow != SW_HIDE )
  198.         UpdateWindow( g.hwndFrame );
  199.  
  200.     // Check command line for movie file.
  201.     // Note: this must come after ShowWindow, UpdateWindow
  202.     if( lpCmdLine = PlayerParseCmdLine( lpCmdLine ))
  203.         SendMessage( g.hwndFrame, WM_PLAYER_CMDLINE,
  204.         0, (LPARAM) lpCmdLine );
  205.  
  206.     return g.hwndFrame;
  207. }
  208.  
  209. // Function: PlayerParseCmdLine - Parse the command line. Return -> to
  210. //                                first argument and ignore any extras.
  211. //                                The default extension is appended if
  212. //                                name has no extension
  213. // --------------------------------------------------------------------
  214. // Parameters: LPSTR      lpCmdLine     command line pointer
  215. //
  216. // Returns:    LPSTR      lpCmdLine     command line pointer to first
  217. //                                      argument, else NULL
  218. // --------------------------------------------------------------------
  219. static LPSTR NEAR PlayerParseCmdLine( LPSTR lpCmdLine )
  220.  
  221. {
  222.     LPSTR  lpTemp;                        // Temp pointer
  223.     char   szExtension[FILE_EXT_LEN + 1]; // Default file extension
  224.     BOOL   bExtension;                    // Extension flag
  225.  
  226.     // Command line is already in Ansi char set even if entered from DOS
  227.     // command line
  228.  
  229.     // remove any leading blanks
  230.     while( *lpCm