home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch11 / myradio / myradvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-22  |  5.5 KB  |  237 lines

  1. // myradvw.cpp : implementation of the CMyradioView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "myradio.h"
  6.  
  7. #include "myraddoc.h"
  8. #include "myradvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMyradioView
  17.  
  18. IMPLEMENT_DYNCREATE(CMyradioView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CMyradioView, CView)
  21.     //{{AFX_MSG_MAP(CMyradioView)
  22.     ON_COMMAND(ID_FILE_TRYIT, OnFileTryit)
  23.     ON_COMMAND(ID_FILE_BEEP, OnFileBeep)
  24.     ON_COMMAND(ID_FILE_PLAYME, OnFilePlayme)
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CMyradioView construction/destruction
  30.  
  31. CMyradioView::CMyradioView()
  32. {
  33.     // TODO: add construction code here
  34.  
  35.      //////////////////////
  36.      // MY CODE STARTS HERE
  37.      //////////////////////
  38.  
  39.     // Declare local variables
  40.     char FileToOpen[255];
  41.     CString Message, Caption;
  42.  
  43.     // Open a WAV session for Hello.WAV
  44.     strcpy ( FileToOpen, "\\vcProg\\WAV\\Hello.WAV" );
  45.     m_HelloSession = sp_OpenSession ( FileToOpen );
  46.  
  47.      // If WAV session can't be opened, display an error
  48.      // message box.
  49.     if ( m_HelloSession < 0 )
  50.        {
  51.        Message = "Can't open the file: ";
  52.        Message = Message + FileToOpen;
  53.        Caption = "Error";
  54.        MessageBox ( Message, Caption );
  55.       }
  56.  
  57.     // Open a WAV session for 8Kenned3.WAV
  58.     strcpy ( FileToOpen, "\\vcProg\\WAV\\8Kenned3.WAV" );
  59.     m_KennedySession = sp_OpenSession ( FileToOpen );
  60.  
  61.      // If WAV session can't be opened, display an error
  62.      // message box.
  63.     if ( m_KennedySession < 0 )
  64.        {
  65.        Message = "Can't open the file: ";
  66.        Message = Message + FileToOpen;
  67.        Caption = "Error";
  68.        MessageBox ( Message, Caption );
  69.        }
  70.  
  71.      ////////////////////
  72.      // MY CODE ENDS HERE
  73.      ////////////////////
  74.  
  75. }
  76.  
  77. CMyradioView::~CMyradioView()
  78. {
  79.  
  80.  
  81.      //////////////////////
  82.      // MY CODE STARTS HERE
  83.      //////////////////////
  84.  
  85.      sp_PlaySnd ( m_HelloSession,
  86.                   52160L,
  87.                   SP_END_OF_FILE );
  88.  
  89.      sp_CloseSession ( m_HelloSession );
  90.      sp_CloseSession ( m_KennedySession );
  91.  
  92.  
  93.      ////////////////////,
  94.      // MY CODE ENDS HERE
  95.      ////////////////////
  96.  
  97.  
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMyradioView drawing
  102.  
  103. void CMyradioView::OnDraw(CDC* pDC)
  104. {
  105.     CMyradioDoc* pDoc = GetDocument();
  106.     ASSERT_VALID(pDoc);
  107.  
  108.     // TODO: add draw code for native data here
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMyradioView diagnostics
  113.  
  114. #ifdef _DEBUG
  115. void CMyradioView::AssertValid() const
  116. {
  117.     CView::AssertValid();
  118. }
  119.  
  120. void CMyradioView::Dump(CDumpContext& dc) const
  121. {
  122.     CView::Dump(dc);
  123. }
  124.  
  125. CMyradioDoc* CMyradioView::GetDocument() // non-debug version is inline
  126. {
  127.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyradioDoc)));
  128.     return (CMyradioDoc*)m_pDocument;
  129. }
  130. #endif //_DEBUG
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CMyradioView message handlers
  134.  
  135. void CMyradioView::OnFileTryit()
  136. {
  137.     // TODO: Add your command handler code here
  138.  
  139.      //////////////////////
  140.      // MY CODE STARTS HERE
  141.      //////////////////////
  142.  
  143.      // Display the dlg dialog box.
  144.      dlg.DoModal();
  145.  
  146.      ////////////////////
  147.      // MY CODE ENDS HERE
  148.      ////////////////////
  149.     
  150. }
  151.  
  152. void CMyradioView::OnFileBeep()
  153. {
  154.     // TODO: Add your command handler code here
  155.  
  156.      //////////////////////
  157.      // MY CODE STARTS HERE
  158.      //////////////////////
  159.  
  160.      // User selected Beep from the File menu, so beep.
  161.     DWORD start;
  162.     switch (dlg.m_BeepStatus)
  163.            {
  164.            case 0:
  165.                  // Beep
  166.                  MessageBeep(-1);
  167.                  break;
  168.            case 1:
  169.                  // Beep
  170.                  MessageBeep(-1);
  171.  
  172.                  // 1 second delay
  173.                  start = GetTickCount();
  174.                  while ( GetTickCount() < start + 1000 )
  175.                       ;
  176.  
  177.                  // Beep
  178.                  MessageBeep(-1);
  179.                  break;
  180.            case 2:
  181.                 // Beep
  182.                 MessageBeep(-1);
  183.  
  184.                 // 1 second delay
  185.                 start = GetTickCount();
  186.                 while ( GetTickCount() < start + 1000 )
  187.                       ;
  188.  
  189.                 // Beep
  190.                 MessageBeep(-1);
  191.  
  192.                 // 1 second delay
  193.                 start = GetTickCount();
  194.                 while ( GetTickCount() < start + 1000 )
  195.                       ;
  196.  
  197.                 // Beep
  198.                  MessageBeep(-1);
  199.                  break;
  200.             }
  201.  
  202.      ////////////////////
  203.      // MY CODE ENDS HERE
  204.      ////////////////////
  205.     
  206. }
  207.  
  208. void CMyradioView::OnFilePlayme()
  209. {
  210.     // TODO: Add your command handler code here
  211.  
  212.  
  213.      //////////////////////
  214.      // MY CODE STARTS HERE
  215.      //////////////////////
  216.  
  217.      switch (dlg.m_VoiceStatus)
  218.             {
  219.             case 0:
  220.                  sp_PlaySnd (m_HelloSession,
  221.                              SP_START_OF_FILE,
  222.                              SP_END_OF_FILE );
  223.                  break;
  224.  
  225.             case 1:
  226.                  sp_PlaySnd (m_KennedySession,
  227.                              SP_START_OF_FILE,
  228.                              SP_END_OF_FILE );
  229.                  break;
  230.  
  231.             }
  232.  
  233.      ////////////////////
  234.      // MY CODE ENDS HERE
  235.      ////////////////////
  236. }
  237.