home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / mfcplay.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  7.4 KB  |  267 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. // player.cpp : Defines the class behaviors for the application.
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "mfcplay.h"
  17.  
  18. #include "mainfrm.h"
  19. #include "mfcdoc.h"
  20. #include "mfcvw.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CPlayerApp
  29.  
  30. BEGIN_MESSAGE_MAP(CPlayerApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CPlayerApp)
  32.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  33.         // NOTE - the ClassWizard will add and remove mapping macros here.
  34.         //    DO NOT EDIT what you see in these blocks of generated code!
  35.     //}}AFX_MSG_MAP
  36.     // Standard file based document commands
  37.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  38.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CPlayerApp construction
  43.  
  44. CPlayerApp::CPlayerApp()
  45. {
  46.     // Place all significant initialization in InitInstance
  47.  
  48.     m_pPlayerDoc = NULL;
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // The one and only CPlayerApp object
  53.  
  54. CPlayerApp theApp;
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CPlayerApp initialization
  58.  
  59. BOOL CPlayerApp::InitInstance()
  60. {
  61.     // Standard initialization
  62.     // If you are not using these features and wish to reduce the size
  63.     //  of your final executable, you should remove from the following
  64.     //  the specific initialization routines you do not need.
  65.  
  66.     Enable3dControls();
  67.  
  68.     LoadStdProfileSettings( 0 );  // Load standard INI file options (including MRU)
  69.  
  70.     // Initialize the quartz library
  71.     CoInitialize(NULL);
  72.     
  73.     // Register the application's document templates.  Document templates
  74.     //  serve as the connection between documents, frame windows and views.
  75.  
  76.     CSingleDocTemplate* pDocTemplate;
  77.     pDocTemplate = new CSingleDocTemplate(
  78.         IDR_MAINFRAME,
  79.         RUNTIME_CLASS(CPlayerDoc),
  80.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  81.         RUNTIME_CLASS(CPlayerView));
  82.     AddDocTemplate(pDocTemplate);
  83.  
  84.     // Enable DDE Execute open
  85.     EnableShellOpen();
  86.     RegisterShellFileTypes();
  87.  
  88.     // simple command line parsing
  89.     if (m_lpCmdLine[0] == '\0')
  90.     {
  91.         // create a new (empty) document
  92.         OnFileNew();
  93.     }
  94.     else
  95.     {
  96.         // open an existing document
  97.         if(!OpenDocumentFile(m_lpCmdLine))
  98.                     return FALSE;
  99.     }
  100.  
  101.     // Enable drag/drop open
  102.     m_pMainWnd->DragAcceptFiles();
  103.  
  104.     return TRUE;
  105. }
  106.  
  107. int CPlayerApp::ExitInstance( )
  108. {
  109.     CoUninitialize();
  110.  
  111.     return CWinApp::ExitInstance();
  112. }
  113.  
  114. void CPlayerApp::OnDocumentCreated( CPlayerDoc *pPlayerDoc )
  115. {
  116.     // Single documents only
  117.     // If you want to convert to an MDI you will need to hold a list
  118.     // of all created documents and change CPlayerApp::Run to build
  119.     // up a list of event handles to wait for.
  120.     ASSERT( m_pPlayerDoc == NULL );
  121.     m_pPlayerDoc = pPlayerDoc;
  122.  
  123. }
  124.  
  125. void CPlayerApp::OnDocumentDestroyed( CPlayerDoc *pPlayerDoc )
  126. {
  127.     // Single documents only
  128.     ASSERT( m_pPlayerDoc == pPlayerDoc );
  129.     m_pPlayerDoc = NULL;
  130.  
  131. }
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CAboutDlg dialog used for App About
  135.  
  136. class CAboutDlg : public CDialog
  137. {
  138. public:
  139.     CAboutDlg();
  140.  
  141. // Dialog Data
  142.     //{{AFX_DATA(CAboutDlg)
  143.     enum { IDD = IDD_ABOUTBOX };
  144.     //}}AFX_DATA
  145.  
  146. // Implementation
  147. protected:
  148.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  149.     //{{AFX_MSG(CAboutDlg)
  150.         // No message handlers
  151.     //}}AFX_MSG
  152.     DECLARE_MESSAGE_MAP()
  153. };
  154.  
  155. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  156. {
  157.     //{{AFX_DATA_INIT(CAboutDlg)
  158.     //}}AFX_DATA_INIT
  159. }
  160.  
  161. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  162. {
  163.     CDialog::DoDataExchange(pDX);
  164.     //{{AFX_DATA_MAP(CAboutDlg)
  165.     //}}AFX_DATA_MAP
  166. }
  167.  
  168. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  169.     //{{AFX_MSG_MAP(CAboutDlg)
  170.         // No message handlers
  171.     //}}AFX_MSG_MAP
  172. END_MESSAGE_MAP()
  173.  
  174. // App command to run the dialog
  175. void CPlayerApp::OnAppAbout()
  176. {
  177.     CAboutDlg aboutDlg;
  178.     aboutDlg.DoModal();
  179. }
  180.  
  181. int CPlayerApp::Run()
  182. {   // Overridden to check for Graph events as well as messages
  183.  
  184.     if (m_pMainWnd == NULL && AfxOleGetUserCtrl())
  185.     {
  186.         // Not launched /Embedding or /Automation, but has no main window!
  187.         TRACE0("Warning: m_pMainWnd is NULL in CPlayerApp::Run - quitting application.\n");
  188.         AfxPostQuitMessage(0);
  189.     }
  190.  
  191.     BOOL bIdle = TRUE;
  192.     LONG lIdleCount = 0;
  193.     HANDLE  ahObjects[1];               // handles that need to be waited on
  194.     const int cObjects = 1;             // no of objects that we are waiting on
  195.  
  196.     // message loop lasts until we get a WM_QUIT message
  197.     // upon which we shall return from the function
  198.     while (TRUE) {
  199.  
  200.         // If we don't have an event handle then process idle
  201.         // routines until a message arrives or until the idle routines
  202.         // stop (when we block until a message arrives). The graph event
  203.         // handle can only be created in response to a message
  204.         if( (ahObjects[ 0 ] = m_pPlayerDoc->GetGraphEventHandle()) == NULL ){
  205.             while (    bIdle
  206.                     && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
  207.             {
  208.                 // call OnIdle while in bIdle state
  209.                 if (!OnIdle(lIdleCount++)){
  210.                     bIdle = FALSE;
  211.                     WaitMessage();
  212.                 }
  213.             }
  214.         } else {
  215.             // wait for any message sent or posted to this queue
  216.             // or for a graph notification. If there is no message or event
  217.             // and we are idling then we process the idle time routines
  218.             DWORD result;
  219.  
  220.             result = MsgWaitForMultipleObjects( cObjects
  221.                                               , ahObjects
  222.                                               , FALSE
  223.                                               , (bIdle ? 0 : INFINITE)
  224.                                               , QS_ALLINPUT
  225.                                               );
  226.             if( result != (WAIT_OBJECT_0 + cObjects) ){
  227.                 // not a message...
  228.  
  229.                 if( result == WAIT_OBJECT_0 )
  230.                     m_pPlayerDoc->OnGraphNotify();
  231.  
  232.                 else if( result == WAIT_TIMEOUT )
  233.                     if(!OnIdle(lIdleCount++))
  234.                         bIdle = FALSE;
  235.  
  236.                 continue;
  237.             }
  238.         }
  239.  
  240.  
  241.         // When here, we either have a message or no event handle
  242.         // has been created yet.
  243.  
  244.         // read all of the messages in this next loop
  245.         // removing each message as we read it
  246.         do
  247.         {
  248.             // pump message, but quit on WM_QUIT
  249.             if (!PumpMessage())
  250.                 return ExitInstance();
  251.  
  252.             // reset "no idle" state after pumping "normal" message
  253.             if (IsIdleMessage(&m_msgCur))
  254.             {
  255.                 bIdle = TRUE;
  256.                 lIdleCount = 0;
  257.             }
  258.  
  259.         } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
  260.  
  261.     } // end of the always while-loop
  262.  
  263.  
  264. }
  265. /////////////////////////////////////////////////////////////////////////////
  266. // CPlayerApp commands
  267.