home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / IPLAY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-23  |  7.1 KB  |  257 lines

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