home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch06 / sayhello / sayhevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-16  |  4.5 KB  |  201 lines

  1. // sayhevw.cpp : implementation of the CSayhelloView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "sayhello.h"
  6.  
  7. #include "sayhedoc.h"
  8. #include "sayhevw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSayhelloView
  17.  
  18. IMPLEMENT_DYNCREATE(CSayhelloView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CSayhelloView, CView)
  21.     //{{AFX_MSG_MAP(CSayhelloView)
  22.     ON_COMMAND(ID_FILE_SAYHELLO, OnFileSayhello)
  23.     ON_COMMAND(ID_FILE_SAYHAVEANICEDAY, OnFileSayhaveaniceday)
  24.     ON_COMMAND(ID_FILE_SAYGOODBYE, OnFileSaygoodbye)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CSayhelloView construction/destruction
  30.  
  31. CSayhelloView::CSayhelloView()
  32. {
  33.     // TODO: add construction code here
  34.  
  35.      //////////////////////
  36.      // MY CODE STARTS HERE
  37.      //////////////////////
  38.  
  39.     char FileToOpen[255];
  40.  
  41.  
  42.     // Open the Hello.WAV session
  43.     strcpy ( FileToOpen, "\\vcProg\\WAV\\Hello.WAV" );
  44.     m_HelloSession = sp_OpenSession ( FileToOpen );
  45.  
  46.      // Open the ItsBeen1.WAV session
  47.     strcpy ( FileToOpen, "\\vcProg\\WAV\\ItsBeen1.WAV" );
  48.     m_ItsBeenSession = sp_OpenSession ( FileToOpen );
  49.  
  50.     // If WAV session can not be opened, display message box.
  51.     if ( m_HelloSession < 0 )
  52.        {
  53.        CString Message, Caption;
  54.        Message = "Can't open the file: ";
  55.        Message = Message + FileToOpen;
  56.        Caption = "Error";
  57.        MessageBox ( Message, Caption );
  58.        }
  59.      else
  60.        {
  61.        // Play the Hello audio section.
  62.        sp_PlaySnd ( m_HelloSession,
  63.                     SP_START_OF_FILE,
  64.                     16000L);
  65.        }              
  66.  
  67.  
  68.      // If WAV session can not be opened, display message box.
  69.      if ( m_ItsBeenSession < 0 )
  70.        {
  71.         CString Message, Caption;
  72.         Message = "Can't open the file: ";
  73.         Message = Message + FileToOpen;
  74.         Caption = "Error";
  75.         MessageBox ( Message, Caption );
  76.         }
  77.  
  78.  
  79.      ////////////////////
  80.      // MY CODE ENDS HERE
  81.      ////////////////////
  82.  
  83. }
  84.  
  85. CSayhelloView::~CSayhelloView()
  86. {
  87.  
  88.      //////////////////////
  89.      // MY CODE STARTS HERE
  90.      //////////////////////
  91.  
  92.      sp_PlaySnd ( m_ItsBeenSession,
  93.                   SP_START_OF_FILE,
  94.                   SP_END_OF_FILE );
  95.  
  96.      sp_CloseSession ( m_HelloSession );
  97.      sp_CloseSession ( m_ItsBeenSession );
  98.  
  99.  
  100.      ////////////////////,
  101.      // MY CODE ENDS HERE
  102.      ////////////////////
  103.  
  104.  
  105.  
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CSayhelloView drawing
  110.  
  111. void CSayhelloView::OnDraw(CDC* pDC)
  112. {
  113.     CSayhelloDoc* pDoc = GetDocument();
  114.     ASSERT_VALID(pDoc);
  115.  
  116.     // TODO: add draw code for native data here
  117. }
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CSayhelloView diagnostics
  121.  
  122. #ifdef _DEBUG
  123. void CSayhelloView::AssertValid() const
  124. {
  125.     CView::AssertValid();
  126. }
  127.  
  128. void CSayhelloView::Dump(CDumpContext& dc) const
  129. {
  130.     CView::Dump(dc);
  131. }
  132.  
  133. CSayhelloDoc* CSayhelloView::GetDocument() // non-debug version is inline
  134. {
  135.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSayhelloDoc)));
  136.     return (CSayhelloDoc*)m_pDocument;
  137. }
  138. #endif //_DEBUG
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CSayhelloView message handlers
  142.  
  143. void CSayhelloView::OnFileSayhello()
  144. {
  145.     // TODO: Add your command handler code here
  146.     
  147.      //////////////////////
  148.      // MY CODE STARTS HERE
  149.      //////////////////////
  150.  
  151.      sp_PlaySnd ( m_HelloSession,
  152.                   SP_START_OF_FILE,
  153.                   16000L );
  154.  
  155.      ////////////////////,
  156.      // MY CODE ENDS HERE
  157.      ////////////////////
  158.  
  159.  
  160. }
  161.  
  162. void CSayhelloView::OnFileSayhaveaniceday()
  163. {
  164.     // TODO: Add your command handler code here
  165.  
  166.  
  167.      //////////////////////
  168.      // MY CODE STARTS HERE
  169.      //////////////////////
  170.  
  171.      sp_PlaySnd ( m_HelloSession,
  172.                   18000L,
  173.                   50000L );
  174.  
  175.      ////////////////////
  176.      // MY CODE ENDS HERE
  177.      ////////////////////
  178.     
  179. }
  180.  
  181. void CSayhelloView::OnFileSaygoodbye()
  182. {
  183.     // TODO: Add your command handler code here
  184.  
  185.  
  186.  
  187.      //////////////////////
  188.      // MY CODE STARTS HERE
  189.      //////////////////////
  190.  
  191.      sp_PlaySnd ( m_HelloSession,
  192.                   50000L,
  193.                   SP_END_OF_FILE );
  194.  
  195.  
  196.      ////////////////////,
  197.      // MY CODE ENDS HERE
  198.      ////////////////////
  199.     
  200. }
  201.