home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch29 / play / play.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  5.0 KB  |  223 lines

  1. // play.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "play.h"
  6.  
  7. //////////////////////
  8. // MY CODE STARTS HERE
  9. //////////////////////
  10.  
  11. #include "\vcprog\dll\TegoSND.h"
  12.  
  13. ////////////////////
  14. // MY CODE ENDS HERE
  15. ////////////////////
  16.  
  17.  
  18.  
  19. #include "mainfrm.h"
  20. #include "playdoc.h"
  21. #include "playview.h"
  22.  
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char BASED_CODE THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CPlayApp
  30.  
  31. BEGIN_MESSAGE_MAP(CPlayApp, CWinApp)
  32.     //{{AFX_MSG_MAP(CPlayApp)
  33.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  34.         // NOTE - the ClassWizard will add and remove mapping macros here.
  35.         //    DO NOT EDIT what you see in these blocks of generated code!
  36.     //}}AFX_MSG_MAP
  37.     // Standard file based document commands
  38.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  39.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  40. END_MESSAGE_MAP()
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CPlayApp construction
  44.  
  45. CPlayApp::CPlayApp()
  46. {
  47.     // TODO: add construction code here,
  48.     // Place all significant initialization in InitInstance
  49.  
  50.     ///////////////////////
  51.     // MY CODE STARTS HERE
  52.     //////////////////////
  53.  
  54.     // Open a sound session.
  55.     char FileToPlay[255];
  56.  
  57.     strcpy( FileToPlay, "\\VCPROG\\WAV\\regga2m3.WAV" );
  58.     m_MusicSession = sp_OpenSession ( FileToPlay );
  59.  
  60.  
  61. // If WAV session cannot be opened, display message box.
  62.     if ( m_MusicSession < 0 )
  63.        {
  64.         char Message[255], Caption[255];
  65.         strcpy ( Message, "Can't open the file: ");
  66.         strcat ( Message,  FileToPlay );
  67.         strcpy ( Caption, "Error" );
  68.         MessageBox ( NULL,
  69.                      Message,
  70.                      Caption,
  71.                      MB_OK | MB_ICONHAND);
  72.         }
  73.  
  74.  
  75.     // Mouse should be available during playback.
  76.     sp_MouseON(m_MusicSession);
  77.  
  78.     // Initialize the playback position.
  79.     m_PlayPosition = 0;
  80.  
  81.     ////////////////////
  82.     // MY CODE ENDS HERE
  83.     ////////////////////
  84.  
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // The one and only CPlayApp object
  89.  
  90. CPlayApp NEAR theApp;
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CPlayApp initialization
  94.  
  95. BOOL CPlayApp::InitInstance()
  96. {
  97.     // Standard initialization
  98.     // If you are not using these features and wish to reduce the size
  99.     //  of your final executable, you should remove from the following
  100.     //  the specific initialization routines you do not need.
  101.  
  102.     SetDialogBkColor();        // Set dialog background color to gray
  103.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  104.  
  105.     // Register the application's document templates.  Document templates
  106.     //  serve as the connection between documents, frame windows and views.
  107.  
  108.     CSingleDocTemplate* pDocTemplate;
  109.     pDocTemplate = new CSingleDocTemplate(
  110.         IDR_MAINFRAME,
  111.         RUNTIME_CLASS(CPlayDoc),
  112.         RUNTIME_CLASS(CMainFrame),     // main SDI frame window
  113.         RUNTIME_CLASS(CPlayView));
  114.     AddDocTemplate(pDocTemplate);
  115.  
  116.     // create a new (empty) document
  117.     OnFileNew();
  118.  
  119.     if (m_lpCmdLine[0] != '\0')
  120.     {
  121.         // TODO: add command line processing here
  122.     }
  123.  
  124.  
  125.     return TRUE;
  126. }
  127.  
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CAboutDlg dialog used for App About
  130.  
  131. class CAboutDlg : public CDialog
  132. {
  133. public:
  134.     CAboutDlg();
  135.  
  136. // Dialog Data
  137.     //{{AFX_DATA(CAboutDlg)
  138.     enum { IDD = IDD_ABOUTBOX };
  139.     //}}AFX_DATA
  140.  
  141. // Implementation
  142. protected:
  143.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  144.     //{{AFX_MSG(CAboutDlg)
  145.         // No message handlers
  146.     //}}AFX_MSG
  147.     DECLARE_MESSAGE_MAP()
  148. };
  149.  
  150. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  151. {
  152.     //{{AFX_DATA_INIT(CAboutDlg)
  153.     //}}AFX_DATA_INIT
  154. }
  155.  
  156. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  157. {
  158.     CDialog::DoDataExchange(pDX);
  159.     //{{AFX_DATA_MAP(CAboutDlg)
  160.     //}}AFX_DATA_MAP
  161. }
  162.  
  163. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  164.     //{{AFX_MSG_MAP(CAboutDlg)
  165.         // No message handlers
  166.     //}}AFX_MSG_MAP
  167. END_MESSAGE_MAP()
  168.  
  169. // App command to run the dialog
  170. void CPlayApp::OnAppAbout()
  171. {
  172.     CAboutDlg aboutDlg;
  173.     aboutDlg.DoModal();
  174. }
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CPlayApp commands
  178.  
  179.  
  180. //////////////////////
  181. // MY CODE STARTS HERE
  182. //////////////////////
  183.  
  184. BOOL CPlayApp::OnIdle(LONG lCount)
  185. {
  186.  
  187.    // Call the base class function.
  188.    CWinApp::OnIdle(lCount);
  189.  
  190.  
  191.    m_PlayPosition =
  192.           sp_PlaySnd ( m_MusicSession,
  193.                        m_PlayPosition,
  194.                        m_PlayPosition + 10000 );
  195.  
  196.  
  197.    return TRUE;
  198.  
  199. }
  200.  
  201. ////////////////////
  202. // MY CODE ENDS HERE
  203. ////////////////////
  204.  
  205.  
  206. ///////////////////////
  207. // MY CODE STARTS HERE
  208. //////////////////////
  209.  
  210. int CPlayApp::ExitInstance()
  211. {
  212.  
  213. // Close the sound session.
  214. sp_CloseSession(m_MusicSession);
  215.  
  216. return CWinApp::ExitInstance();
  217.  
  218. }
  219.  
  220. ////////////////////
  221. // MY CODE ENDS HERE
  222. ////////////////////
  223.