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

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // ViewMain.c - Picture Viewer - 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
  19.  
  20. #include "common.h" // Interface to common.c routines
  21.  
  22. #include "viewer.h"  // Interface to other *.c files
  23. #include "viewer.hr" // Defines used in *.rc files
  24. #include "picture.h" // Needed for registering
  25.                      // child window controls
  26.  
  27.  
  28. // Message-Persistent Data
  29. // -----------------------
  30. static struct // Hungarian notation: g
  31.   {HINSTANCE     hInstance;          // Instance handle
  32.    HINSTANCE     hResources;         // Resource-only DLL handle
  33.    HWND          hwndFrame;          // Frame window handle
  34.    HWND          hwndClient;         // MDI client window
  35.    HMENU         hMenu;              // Frame window menu
  36.    HACCEL        hAccel;             // Frame window accelerators
  37.    HWND          hActiveModelessDlg; // Handle of active modeless dlg if any
  38.    BOOL          fPalettized;        // Palettized device
  39.    QTOLE_OLEDATA qtoleOleData;       // OLE data struct
  40.   } g;
  41.  
  42.  
  43. // Internal Function Declarations
  44. // ------------------------------
  45. static LPSTR NEAR ViewerParseCmdLine    (LPSTR);
  46. static  BOOL NEAR ViewerInitAppl        (VOID);
  47. static  HWND NEAR ViewerInitInst        (HINSTANCE, LPSTR, int);
  48. static  LONG NEAR ViewerTerminateInst   (VOID);
  49. static  BOOL NEAR DoQuickTimeInit       (HINSTANCE, LPSTR, LPINT);
  50. static  VOID NEAR KillQuickTime         (VOID);
  51.  
  52. // Function: WinMain - Required Windows "Main" Routine
  53. // --------------------------------------------------------------------
  54. // Parameters: As required by Microsoft Windows
  55. //
  56. // Returns:    As required by Microsoft Windows
  57. // --------------------------------------------------------------------
  58. int PASCAL WinMain( HINSTANCE hInstance,
  59.                  HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  60.  
  61. // Define function data
  62.  
  63. {
  64.     MSG  msg; // Message
  65.  
  66.     g.hInstance = hInstance; // Initialize global data
  67.  
  68.     // Load resource-only DLL
  69.     if( !(g.hResources = CommonGetLocalizedResources
  70.         ( VIEWER_ROOT_NAME, hInstance, VIEWER_STRING_NOMEMORY )))
  71.         return 0;
  72.  
  73.     // Perform one-time initialization
  74.  
  75.     if( !hPrevInstance && !ViewerInitAppl() )
  76.         return 0;
  77.  
  78.     // Perform initializations that apply to a specific instance and
  79.     // create window
  80.     if( !ViewerInitInst( hPrevInstance, lpCmdLine, nCmdShow ))
  81.         return 0;
  82.  
  83.  
  84.     // main message loop
  85.     while( GetMessage( &msg, NULL, NULL, NULL )) {
  86.         if( !g.hActiveModelessDlg ||
  87.             !IsDialogMessage( g.hActiveModelessDlg, &msg )) {
  88.             if( !g.hwndClient ||
  89.                 !TranslateMDISysAccel( g.hwndClient, &msg )) {
  90.                 if( !g.hwndFrame ||
  91.                     !TranslateAccelerator( g.hwndFrame, g.hAccel, &msg )) {
  92.                     TranslateMessage(&msg);
  93.                     DispatchMessage (&msg);
  94.                 }
  95.             }
  96.         }
  97.     }
  98.  
  99.     // Cleanup Picture Viewer
  100.  
  101.     ViewerTerminateInst();
  102.  
  103.     return msg.wParam;
  104. }
  105.  
  106.  
  107. // Function: ViewerInitAppl - Perform One-time Initialization
  108. // --------------------------------------------------------------------
  109. // Parameters: None
  110. //
  111. // Returns:    TRUE if OK, else FALSE
  112. // --------------------------------------------------------------------
  113. static BOOL NEAR ViewerInitAppl( VOID )
  114.  
  115. {
  116.     WNDCLASS wc; // Window class information
  117.  
  118.     // Register the frame (main) window class
  119.  
  120.     wc.style         = 0;
  121.     wc.lpfnWndProc   = ViewerFrameWndProc;
  122.     wc.cbClsExtra    = 0;
  123.     wc.cbWndExtra    = 0;
  124.     wc.hInstance     = g.hInstance;
  125.     wc.hIcon         = LoadIcon( g.hResources,
  126.         MAKEINTRESOURCE( VIEWER_VIEWER_ICON ));
  127.     wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
  128.     wc.hbrBackground = (HBRUSH) ( COLOR_APPWORKSPACE + 1 );
  129.     wc.lpszMenuName  = NULL;
  130.     wc.lpszClassName = VIEWER_FRAME_CLASS;
  131.  
  132.     if( !RegisterClass( &wc ))
  133.         return FALSE;
  134.  
  135.     // Register the picture window class
  136.  
  137.     wc.style         = 0;
  138.     wc.lpfnWndProc   = ViewerPictureWndProc;
  139.     wc.cbClsExtra    = 0;
  140.     wc.cbWndExtra    = sizeof( VOID NEAR * );
  141.     wc.hInstance     = g.hInstance;
  142.     wc.hIcon         = NULL;
  143.     wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
  144.     wc.hbrBackground = PICBACKGRNDBRUSH;
  145.     wc.lpszMenuName  = NULL;
  146.     wc.lpszClassName = VIEWER_PICTURE_CLASS;
  147.  
  148.     if( !RegisterClass( &wc ))
  149.         return FALSE;
  150.  
  151.     // Register the child classes used by the picture windows
  152.     // This function is in PictKids.c
  153.  
  154.     if( !RegisterChildControls( g.hInstance ))
  155.         return FALSE;
  156.  
  157.     return TRUE;
  158. }
  159.  
  160.  
  161. // Function: ViewerInitInst - Perform Instance Initialization
  162. // --------------------------------------------------------------------
  163. // Parameters: HINSTANCE hPrevInstance;  Previous instance
  164. //             LPSTR     lpCmdLine;      -->Command line arguments
  165. //             int       nCmdShow;       Parameter for first ShowWindow()
  166. //
  167. // Returns:    HWND      hwndFrame;      Frame window handle
  168. //                                       or NULL if initialization failed
  169. // --------------------------------------------------------------------
  170. static HWND NEAR ViewerInitInst
  171.               ( HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  172.  
  173. {
  174.     HDC hdcIC;
  175.  
  176.     // Do QuickTime Initializations.
  177.     if( !DoQuickTimeInit( hPrevInstance, lpCmdLine, &nCmdShow ))
  178.         return NULL;
  179.  
  180.     // Is this a palettized device?
  181.     if( hdcIC = CreateIC( "DISPLAY", NULL, NULL, NULL )) {
  182.         g.fPalettized = 
  183.             ( GetDeviceCaps( hdcIC, RASTERCAPS ) & RC_PALETTE );
  184.         DeleteDC( hdcIC );
  185.     }
  186.  
  187.     // get menu and accelerators from localized resource
  188.     g.hAccel = LoadAccelerators( g.hResources,
  189.         MAKEINTRESOURCE( VIEWER_ACCELERATORS ));
  190.     g.hMenu  = LoadMenu( g.hResources,
  191.         MAKEINTRESOURCE( VIEWER_FRAME_MENU ));
  192.     if( !g.hAccel || !g.hMenu ) {
  193.         CommonTellUser( g.hResources, VIEWER_STRING_NOACCELORMENU,
  194.             VIEWER_STRING_CAPTION, MB_OK );
  195.         return NULL;
  196.     }
  197.  
  198.     // Create a main window for this application instance.
  199.     if( !(g.hwndFrame = CreateWindow( VIEWER_FRAME_CLASS, "",
  200.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  201.         CW_USEDEFAULT, CW_USEDEFAULT,
  202.         CW_USEDEFAULT, CW_USEDEFAULT,
  203.         NULL, g.hMenu, g.hInstance, NULL ))) {
  204.         CommonTellUser( g.hResources, VIEWER_STRING_NOWINDOW,
  205.             VIEWER_STRING_CAPTION, MB_OK );
  206.         return NULL;
  207.     }
  208.  
  209.     // Tell qtole.dll the server hwnd
  210.     QTOLE_SetApplicationHwnd( &g.qtoleOleData, g.hwndFrame ); 
  211.  
  212.     // save MDI client window created during WM_CREATE message processing
  213.     g.hwndClient = ViewerQueryClientWindow(); // this is in FrameWnd.c
  214.  
  215.     // Display the frame window
  216.     // If ole started the app, the window will be initially hidden
  217.     ShowWindow( g.hwndFrame, nCmdShow );
  218.     if( nCmdShow != SW_HIDE )
  219.         UpdateWindow( g.hwndFrame );
  220.  
  221.     // Check command line for picture file.
  222.     // Note: this must come after ShowWindow, UpdateWindow
  223.     if( lpCmdLine = ViewerParseCmdLine( lpCmdLine ))
  224.         SendMessage( g.hwndFrame, 
  225.         WM_VIEWER_CMDLINE, 0, (LPARAM) lpCmdLine );
  226.  
  227.     return g.hwndFrame;
  228. }
  229.  
  230. // Function: ViewerParseCmdLine - Parse the command line. Return -> to
  231. //                                first argument and ignore any extras.
  232. //                                The default extension is added if there
  233. //                                is no extension
  234. // --------------------------------------------------------------------
  235. // Parameters: LPSTR      lpCmdLine     command line pointer
  236. //
  237. // Returns:    LPSTR      lpCmdLine     command line pointer to