home *** CD-ROM | disk | FTP | other *** search
/ Master Visual C++ 1.5 / MASTERVC15.ISO / vcprog / original / appendix / dance / dancevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-12  |  6.7 KB  |  293 lines

  1. // dancevw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "dance.h"
  6. #include "dancevw.h"
  7.  
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char BASED_CODE THIS_FILE[] = __FILE__;
  11. #endif
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDanceView
  15.  
  16. IMPLEMENT_DYNCREATE(CDanceView, CFormView)
  17.  
  18. CDanceView::CDanceView()
  19.     : CFormView(CDanceView::IDD)
  20. {
  21.     //{{AFX_DATA_INIT(CDanceView)
  22.     m_pc = NULL;
  23.     m_MultiTask = FALSE;
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27. CDanceView::~CDanceView()
  28. {
  29.  
  30.   ///////////////////////
  31.   // MY CODE STARTS HERE
  32.   //////////////////////
  33.  
  34.   // Delete the 4 bitmaps.
  35.   for (int i=0; i<4; i++)
  36.       delete m_pB[i];
  37.   
  38.   ////////////////////
  39.   // MY CODE ENDS HERE
  40.   ////////////////////
  41.  
  42. }
  43.  
  44. void CDanceView::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CFormView::DoDataExchange(pDX);
  47.     //{{AFX_DATA_MAP(CDanceView)
  48.     DDX_VBControl(pDX, IDC_TEGOMM1, m_pc);
  49.     DDX_Check(pDX, IDC_MULTITASK, m_MultiTask);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53.  
  54. BEGIN_MESSAGE_MAP(CDanceView, CFormView)
  55.     //{{AFX_MSG_MAP(CDanceView)
  56.     ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
  57.     ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton)
  58.     ON_VBXEVENT(VBN_DONE, IDC_TEGOMM1, OnDoneTegomm1)
  59.     ON_VBXEVENT(VBN_STATUSUPDATE, IDC_TEGOMM1, OnStatusupdateTegomm1)
  60.     ON_BN_CLICKED(IDC_MULTITASK, OnMultitask)
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CDanceView message handlers
  67.  
  68. //////////////////////
  69. // MY CODE STARTS HERE
  70. //////////////////////
  71.  
  72. void CDanceView::OnInitialUpdate()
  73. {
  74.  
  75.    // Call the base class function.
  76.    CFormView::OnInitialUpdate();
  77.  
  78.    // Set the DeviceType property for playback through the PC speaker.
  79.    m_pc->SetStrProperty("DeviceType","PCSpeaker");    
  80.     
  81.    // Disable the timer of the multimedia control.
  82.    m_pc->SetNumProperty("UpdateInterval",0);
  83.  
  84.    // Set the FileName property.
  85.    m_pc->SetStrProperty("FileName","\\VCPROG\\WAV\\BOURB2M3.WAV");    
  86.     
  87.    // Make the multimedia control invisible.
  88.    m_pc->SetNumProperty("Visible", FALSE);    
  89.  
  90.    // Issue an Open command to the multimedia control.
  91.    m_pc->SetStrProperty("Command","Open");
  92.  
  93.    // Was the sound file opened successfully?
  94.    if ( m_pc->GetNumProperty("Error") != 0 )
  95.       MessageBox("Cannot open the file "+m_pc->GetStrProperty("FileName"), "Error", MB_ICONEXCLAMATION); 
  96.    
  97.    // Load IDB_BITMAP1
  98.    m_pB[0] = new CBitmap;
  99.    m_pB[0]->LoadBitmap(IDB_BITMAP1);
  100.  
  101.    // Load IDB_BITMAP2
  102.    m_pB[1] = new CBitmap;
  103.    m_pB[1]->LoadBitmap(IDB_BITMAP2);
  104.  
  105.    // Load IDB_BITMAP3
  106.    m_pB[2] = new CBitmap;
  107.    m_pB[2]->LoadBitmap(IDB_BITMAP3);
  108.  
  109.    // Load IDB_BITMAP4
  110.    m_pB[3] = new CBitmap;
  111.    m_pB[3]->LoadBitmap(IDB_BITMAP4);
  112.  
  113. }
  114.  
  115. ////////////////////
  116. // MY CODE ENDS HERE
  117. ////////////////////
  118.  
  119.  
  120. ///////////////////////
  121. // MY CODE STARTS HERE
  122. ///////////////////////
  123.  
  124. void CDanceView::OnDraw(CDC* pDC)
  125. {
  126.  
  127.     // Create a memory DC.
  128.     CDC* pMemDC = new CDC;
  129.     pMemDC->CreateCompatibleDC(pDC);
  130.     
  131.     // Select the bitmap into the memory DC.
  132.     pMemDC->SelectObject( m_pB[0] );
  133.     
  134.     // Copy the bitmap from the memory DC (pMemDC) into the screen DC (pDC).
  135.     pDC->BitBlt(100,10,500,500,pMemDC,0,0,SRCCOPY);
  136.     
  137.     // Delete the memory DC.
  138.     delete pMemDC;
  139.     
  140. }
  141.  
  142. ////////////////////
  143. // MY CODE ENDS HERE
  144. ////////////////////
  145.  
  146. void CDanceView::OnStartButton()
  147. {
  148.     // TODO: Add your control notification handler code here
  149.     
  150.     //////////////////////
  151.     // MY CODE STARTS HERE
  152.     //////////////////////
  153.     
  154.     // Disable the Start push button.
  155.     GetDlgItem(IDC_START_BUTTON)->EnableWindow(FALSE);
  156.  
  157.     // Initialize the current frame number to 0.
  158.     m_CurrentFrame = 0;
  159.     
  160.     // Rewind the multimedia control.
  161.     m_pc->SetStrProperty("Command","Prev");
  162.     
  163.  
  164.     // Set the interval of the multimedia control timer.
  165.     m_pc->SetNumProperty("UpdateInterval",400);
  166.  
  167.     // Start playing.
  168.     m_pc->SetStrProperty("Command","Play");
  169.     
  170.     ////////////////////
  171.     // MY CODE ENDS HERE
  172.     ////////////////////
  173.     
  174. }
  175.  
  176.  
  177. void CDanceView::OnStopButton()
  178. {
  179.     // TODO: Add your control notification handler code here
  180.     
  181.     ///////////////////////
  182.     // MY CODE STARTS HERE
  183.     //////////////////////
  184.     
  185.     // Stop the playback.
  186.     m_pc->SetStrProperty("Command","Stop");    
  187.     
  188.     ////////////////////
  189.     // MY CODE ENDS HERE
  190.     ////////////////////
  191.     
  192. }
  193.  
  194.  
  195. void CDanceView::OnDoneTegomm1(UINT, int, CWnd*, LPVOID)
  196. {
  197.     // TODO: Add your VBX event notification handler code here
  198.     
  199.     //////////////////////
  200.     // MY CODE STARTS HERE
  201.     //////////////////////
  202.  
  203.     // Disable the multimedia control timer.
  204.     m_pc->SetNumProperty("UpdateInterval",0);
  205.  
  206.     // If in multitasking mode and position is end of file, restart playback.
  207.     if (m_MultiTask==TRUE && m_pc->GetNumProperty("Position")==m_pc->GetNumProperty("Length"))
  208.        {
  209.        // Restart the playback.
  210.        OnStartButton();
  211.        }
  212.     else
  213.        {
  214.        // Enable the Start push button.
  215.        GetDlgItem(IDC_START_BUTTON)->EnableWindow(TRUE);
  216.  
  217.        // Display the first frame of the show (i.e. trigger a call to the OnDraw() function).
  218.        Invalidate();
  219.        }
  220.  
  221.     ////////////////////
  222.     // MY CODE ENDS HERE
  223.     ////////////////////
  224.  
  225. }
  226.  
  227.  
  228. void CDanceView::OnStatusupdateTegomm1(UINT, int, CWnd*, LPVOID)
  229. {
  230.     // TODO: Add your VBX event notification handler code here
  231.  
  232.     ///////////////////////
  233.     // MY CODE STARTS HERE
  234.     //////////////////////
  235.     
  236.     // Increment the current frame number.
  237.     m_CurrentFrame++;
  238.  
  239.     // Was the last frame of the dance displayed?
  240.     if (m_CurrentFrame==4)
  241.        m_CurrentFrame=1;
  242.     
  243.     // Get a DC for the screen.
  244.     CClientDC dc(this);
  245.     
  246.     // Create a memory DC.
  247.     CDC* pMemDC = new CDC;
  248.     pMemDC->CreateCompatibleDC(&dc);
  249.     
  250.     // Select the bitmap into the memory DC.
  251.     pMemDC->SelectObject( m_pB[m_CurrentFrame] );    
  252.     
  253.     // Copy the bitmap from the memory DC (pMemDC) into the screen DC (dc).
  254.     dc.BitBlt(100,10,500,500,pMemDC,0,0,SRCCOPY);
  255.     
  256.     // Delete the memory DC.
  257.     delete pMemDC;
  258.     
  259.     ////////////////////
  260.     // MY CODE ENDS HERE
  261.     ////////////////////
  262.     
  263. }
  264.  
  265. void CDanceView::OnMultitask()
  266. {
  267.     // TODO: Add your control notification handler code here
  268.  
  269.     ///////////////////////
  270.     // MY CODE STARTS HERE
  271.     //////////////////////
  272.     
  273.     // Update the variable of the Multitasking check box (m_MultiTask).
  274.     UpdateData(TRUE);
  275.     
  276.     // Enable multi-tasking?
  277.     if (m_MultiTask==TRUE)
  278.        {
  279.        m_pc->SetNumProperty("pcMouseEnabled", TRUE);
  280.        m_pc->SetNumProperty("pcTaskInterval",400);
  281.        }
  282.     else
  283.        {
  284.        m_pc->SetNumProperty("pcMouseEnabled", FALSE);
  285.        m_pc->SetNumProperty("pcTaskInterval",0);
  286.        }
  287.     
  288.     ////////////////////
  289.     // MY CODE ENDS HERE
  290.     ////////////////////
  291.     
  292. }
  293.