home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / ch27 / kennedy / kennevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-12  |  5.2 KB  |  235 lines

  1. // kennevw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "kennedy.h"
  6. #include "kennevw.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CKennedyView
  15.  
  16. IMPLEMENT_DYNCREATE(CKennedyView, CFormView)
  17.  
  18. CKennedyView::CKennedyView()
  19.     : CFormView(CKennedyView::IDD)
  20. {
  21.     //{{AFX_DATA_INIT(CKennedyView)
  22.     m_wav = NULL;
  23.     //}}AFX_DATA_INIT
  24. }
  25.  
  26. CKennedyView::~CKennedyView()
  27. {
  28.  
  29.   ///////////////////////
  30.   // MY CODE STARTS HERE
  31.   //////////////////////
  32.  
  33.   // Delete the 4 bitmaps.
  34.   for (int i=0; i<4; i++)
  35.       delete m_pB[i];
  36.  
  37.   ////////////////////
  38.   // MY CODE ENDS HERE
  39.   ////////////////////
  40.  
  41.  
  42. }
  43.  
  44. void CKennedyView::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CFormView::DoDataExchange(pDX);
  47.     //{{AFX_DATA_MAP(CKennedyView)
  48.     DDX_VBControl(pDX, IDC_TEGOMM1, m_wav);
  49.     //}}AFX_DATA_MAP
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(CKennedyView, CFormView)
  54.     //{{AFX_MSG_MAP(CKennedyView)
  55.     ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
  56.     ON_VBXEVENT(VBN_STATUSUPDATE, IDC_TEGOMM1, OnStatusupdateTegomm1)
  57.     ON_VBXEVENT(VBN_DONE, IDC_TEGOMM1, OnDoneTegomm1)
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CKennedyView message handlers
  64.  
  65.  
  66. //////////////////////
  67. // MY CODE STARTS HERE
  68. //////////////////////
  69.  
  70. void CKennedyView::OnInitialUpdate()
  71. {
  72.  
  73.  // Call the base class function.
  74.  CFormView::OnInitialUpdate();
  75.  
  76.  // Set the DeviceType property for playback of WAV files.
  77.  m_wav->SetStrProperty("DeviceType","WaveAudio");
  78.  
  79.  // Disable the timer of the multimedia control.
  80.  m_wav->SetNumProperty("UpdateInterval",0);
  81.  
  82.  // Set the FileName property.
  83.  m_wav->SetStrProperty("FileName",
  84.                        "\\VCPROG\\WAV\\8KENNED3.WAV");
  85.  
  86.  // Make the multimedia control invisible.
  87.  m_wav->SetNumProperty("Visible", FALSE);
  88.  
  89.  // Issue an Open command to the multimedia control.
  90.  m_wav->SetStrProperty("Command","Open");
  91.  
  92.  // Load IDB_BITMAP1
  93.  m_pB[0] = new CBitmap;
  94.  m_pB[0]->LoadBitmap(IDB_BITMAP1);
  95.  
  96.  // Load IDB_BITMAP2
  97.  m_pB[1] = new CBitmap;
  98.  m_pB[1]->LoadBitmap(IDB_BITMAP2);
  99.  
  100.  // Load IDB_BITMAP3
  101.  m_pB[2] = new CBitmap;
  102.  m_pB[2]->LoadBitmap(IDB_BITMAP3);
  103.  
  104.  // Load IDB_BITMAP4
  105.  m_pB[3] = new CBitmap;
  106.  m_pB[3]->LoadBitmap(IDB_BITMAP4);
  107.  
  108. }
  109.  
  110. ////////////////////
  111. // MY CODE ENDS HERE
  112. ////////////////////
  113.  
  114.  
  115. ///////////////////////
  116. // MY CODE STARTS HERE
  117. ///////////////////////
  118.  
  119. void CKennedyView::OnDraw(CDC* pDC)
  120. {
  121.  
  122.   // Create a memory DC.
  123.   CDC* pMemDC = new CDC;
  124.   pMemDC->CreateCompatibleDC(pDC);
  125.  
  126.   // Select the bitmap into the memory DC.
  127.   pMemDC->SelectObject( m_pB[0] );
  128.  
  129.   // Copy the bitmap from the memory DC into the screen DC.
  130.   pDC->BitBlt(90,10,500,500,pMemDC,0,0,SRCCOPY);
  131.  
  132.   // Delete the memory DC.
  133.   delete pMemDC;
  134.  
  135. }
  136.  
  137. ////////////////////
  138. // MY CODE ENDS HERE
  139. ////////////////////
  140.  
  141. void CKennedyView::OnStartButton()
  142. {
  143.     // TODO: Add your control notification handler code here
  144.  
  145.    ///////////////////////
  146.    // MY CODE STARTS HERE
  147.    //////////////////////
  148.  
  149.    // Disable the Start button.
  150.    GetDlgItem(IDC_START_BUTTON)->EnableWindow(FALSE);
  151.  
  152.    // Initialize the current frame number to 0.
  153.    m_CurrentFrame = 0;
  154.  
  155.    // Rewind the multimedia control.
  156.    m_wav->SetStrProperty("Command","Prev");
  157.  
  158.    // Start playing the WAV file.
  159.    m_wav->SetStrProperty("Command","Play");
  160.  
  161.    // Set the interval of the multimedia control timer.
  162.    m_wav->SetNumProperty("UpdateInterval",350);
  163.  
  164.    ////////////////////
  165.    // MY CODE ENDS HERE
  166.    ////////////////////
  167.  
  168.     
  169. }
  170.  
  171. void CKennedyView::OnStatusupdateTegomm1(UINT, int, CWnd*, LPVOID)
  172. {
  173.     // TODO: Add your VBX event notification handler code here
  174.  
  175.   ///////////////////////
  176.   // MY CODE STARTS HERE
  177.   //////////////////////
  178.  
  179.   // Get the current position.
  180.   long position = m_wav->GetNumProperty("Position");
  181.  
  182.   // Set the frame number in accordance with the current
  183.   // playback position.
  184.   if (position<3000)
  185.      m_CurrentFrame = 1;
  186.   if (position>3000 && position<7000)
  187.      m_CurrentFrame = 2;
  188.   if (position>7000)
  189.      m_CurrentFrame = 3;
  190.  
  191.   // Get a DC for the screen.
  192.   CClientDC dc(this);
  193.  
  194.   // Create a memory DC.
  195.   CDC* pMemDC = new CDC;
  196.   pMemDC->CreateCompatibleDC(&dc);
  197.  
  198.   // Select the bitmap into the memory DC.
  199.   pMemDC->SelectObject( m_pB[m_CurrentFrame] );
  200.  
  201.   // Copy the bitmap from the memory DC into the screen DC.
  202.   dc.BitBlt(90,10,500,500,pMemDC,0,0,SRCCOPY);
  203.  
  204.   // Delete the memory DC.
  205.   delete pMemDC;
  206.  
  207.   ////////////////////
  208.   // MY CODE ENDS HERE
  209.   ////////////////////
  210.     
  211. }
  212.  
  213. void CKennedyView::OnDoneTegomm1(UINT, int, CWnd*, LPVOID)
  214. {
  215.     // TODO: Add your VBX event notification handler code here
  216.  
  217.     //////////////////////
  218.     // MY CODE STARTS HERE
  219.     //////////////////////
  220.  
  221.      // Disable the multimedia control timer.
  222.      m_wav->SetNumProperty("UpdateInterval",0);
  223.  
  224.     // Enable the Start button.
  225.     GetDlgItem(IDC_START_BUTTON)->EnableWindow(TRUE);
  226.  
  227.     // Trigger a call to the OnDraw() function.
  228.     Invalidate();
  229.  
  230.     ////////////////////
  231.     // MY CODE ENDS HERE
  232.     ////////////////////
  233.     
  234. }
  235.