home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch18 / mykey / mykeyvw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-24  |  5.3 KB  |  252 lines

  1. // mykeyvw.cpp : implementation of the CMykeyView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "mykey.h"
  6.  
  7. #include "mykeydoc.h"
  8. #include "mykeyvw.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMykeyView
  17.  
  18. IMPLEMENT_DYNCREATE(CMykeyView, CView)
  19.  
  20. BEGIN_MESSAGE_MAP(CMykeyView, CView)
  21.     //{{AFX_MSG_MAP(CMykeyView)
  22.     ON_WM_KEYDOWN()
  23.     ON_WM_CHAR()
  24.     //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMykeyView construction/destruction
  29.  
  30. CMykeyView::CMykeyView()
  31. {
  32.     // TODO: add construction code here
  33.  
  34.      //////////////////////
  35.      // MY CODE STARTS HERE
  36.      //////////////////////
  37.  
  38.     char FileToOpen[255];
  39.  
  40.  
  41.     // Open the WAV session
  42.     strcpy ( FileToOpen, "\\vcProg\\WAV\\Numbers.WAV" );
  43.     m_NumbersSession = sp_OpenSession ( FileToOpen );
  44.  
  45.  
  46. // If WAV session can not be opened, display message box.
  47.     if ( m_NumbersSession < 0 )
  48.        {
  49.         CString Message, Caption;
  50.         Message = "Can't open the file: ";
  51.         Message = Message + FileToOpen;
  52.         Caption = "Error";
  53.         MessageBox ( Message, Caption );
  54.         }
  55.  
  56.  
  57.      ////////////////////
  58.      // MY CODE ENDS HERE
  59.      ////////////////////
  60.  
  61.  
  62. }
  63.  
  64. CMykeyView::~CMykeyView()
  65. {
  66.  
  67.      //////////////////////
  68.      // MY CODE STARTS HERE
  69.      //////////////////////
  70.  
  71.      sp_CloseSession ( m_NumbersSession );
  72.  
  73.      ////////////////////,
  74.      // MY CODE ENDS HERE
  75.      ////////////////////
  76.  
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CMykeyView drawing
  81.  
  82. void CMykeyView::OnDraw(CDC* pDC)
  83. {
  84.     CMykeyDoc* pDoc = GetDocument();
  85.     ASSERT_VALID(pDoc);
  86.  
  87.     // TODO: add draw code for native data here
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CMykeyView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CMykeyView::AssertValid() const
  95. {
  96.     CView::AssertValid();
  97. }
  98.  
  99. void CMykeyView::Dump(CDumpContext& dc) const
  100. {
  101.     CView::Dump(dc);
  102. }
  103.  
  104. CMykeyDoc* CMykeyView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMykeyDoc)));
  107.     return (CMykeyDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CMykeyView message handlers
  113.  
  114. void CMykeyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  115. {
  116.     // TODO: Add your message handler code here and/or call default
  117.  
  118.     //////////////////////
  119.     // MY CODE STARTS HERE
  120.     //////////////////////
  121.  
  122. switch (nChar)
  123. {
  124.  
  125. case VK_F1:
  126.  
  127.  if ( GetKeyState(VK_CAPITAL) & 0x0001 )
  128.     {
  129.      MessageBox ("You pressed F1. Caps Lock = ON");
  130.     }
  131.  else
  132.     {
  133.     MessageBox ("You pressed F1. Caps Lock = OFF");
  134.     }
  135.  break;
  136.  
  137.  case VK_LEFT:
  138.  
  139.  if ( GetKeyState(VK_CAPITAL) & 0x0001 )
  140.  {
  141.  MessageBox ("You pressed the Left arrow. Caps Lock = ON");
  142.  }
  143.  else
  144.  {
  145.  MessageBox ("You pressed the Left arrow. Caps Lock = OFF");
  146.  }
  147.  break;
  148.  
  149. }
  150.  
  151.      ////////////////////
  152.      // MY CODE ENDS HERE
  153.      ////////////////////
  154.  
  155.     
  156.     CView::OnKeyDown(nChar, nRepCnt, nFlags);
  157. }
  158.  
  159. void CMykeyView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  160. {
  161.     // TODO: Add your message handler code here and/or call default
  162.  
  163.      //////////////////////
  164.      // MY CODE STARTS HERE
  165.      //////////////////////
  166.  
  167.      if (nChar<32)
  168.        {
  169.        MessageBeep(-1);
  170.        }
  171.     else
  172.        {
  173.        CClientDC dc (this);
  174.  
  175.        dc.TextOut (10, 10, "     ");
  176.        dc.TextOut (10, 10, nChar);
  177.        }
  178.  
  179.  
  180.     switch (nChar)
  181.      {
  182.  
  183.         case '0':
  184.              sp_PlaySnd( m_NumbersSession,
  185.                          1667,
  186.                          8525 );
  187.              break;
  188.  
  189.         case '1':
  190.              sp_PlaySnd( m_NumbersSession,
  191.                          10100,
  192.                          16754 );
  193.              break;
  194.  
  195.         case '2':
  196.              sp_PlaySnd( m_NumbersSession,
  197.                          20673,
  198.                          26942 );
  199.              break;
  200.  
  201.           case '3':
  202.              sp_PlaySnd( m_NumbersSession,
  203.                          30270,
  204.                          38500 );
  205.              break;
  206.  
  207.           case '4':
  208.              sp_PlaySnd( m_NumbersSession,
  209.                          42030,
  210.                          51830 );
  211.              break;
  212.  
  213.           case '5':
  214.              sp_PlaySnd( m_NumbersSession,
  215.                          53390,
  216.                          61000 );
  217.              break;
  218.  
  219.  
  220.           case '6':
  221.              sp_PlaySnd( m_NumbersSession,
  222.                          64360,
  223.                          72200 );
  224.              break;
  225.  
  226.           case '7':
  227.              sp_PlaySnd( m_NumbersSession,
  228.                          75530,
  229.                          85720 );
  230.              break;
  231.  
  232.           case '8':
  233.              sp_PlaySnd( m_NumbersSession,
  234.                          87680,
  235.                          93950 );
  236.              break;
  237.  
  238.           case '9':
  239.              sp_PlaySnd( m_NumbersSession,
  240.                          98060,
  241.                          106492 );
  242.              break;
  243.  
  244.     }
  245.  
  246.      ////////////////////
  247.      // MY CODE ENDS HERE
  248.      ////////////////////
  249.     
  250.     CView::OnChar(nChar, nRepCnt, nFlags);
  251. }
  252.