sndView.cpp
上传用户:wen82zi81
上传日期:2007-01-03
资源大小:40k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. // sndView.cpp : implementation of the CSndView class
  2. //
  3. #include "stdafx.h"
  4. #include "snd.h"
  5. #include "sndDoc.h"
  6. #include "sndView.h"
  7. #include "soundIn.h"
  8. extern CSoundIn SoundIn;
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CSndView
  16. IMPLEMENT_DYNCREATE(CSndView, CView)
  17. BEGIN_MESSAGE_MAP(CSndView, CView)
  18. //{{AFX_MSG_MAP(CSndView)
  19. ON_WM_TIMER()
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CSndView construction/destruction
  28. CSndView::CSndView()
  29. {
  30. // TODO: add construction code here
  31. }
  32. CSndView::~CSndView()
  33. {
  34. }
  35. BOOL CSndView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. // TODO: Modify the Window class or styles here by modifying
  38. //  the CREATESTRUCT cs
  39. return CView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CSndView drawing
  43. void CSndView::OnDraw(CDC* pDC)
  44. {
  45. CSndDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. // TODO: add draw code for native data here
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CSndView printing
  51. BOOL CSndView::OnPreparePrinting(CPrintInfo* pInfo)
  52. {
  53. // default preparation
  54. return DoPreparePrinting(pInfo);
  55. }
  56. void CSndView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  57. {
  58. // TODO: add extra initialization before printing
  59. }
  60. void CSndView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  61. {
  62. // TODO: add cleanup after printing
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CSndView diagnostics
  66. #ifdef _DEBUG
  67. void CSndView::AssertValid() const
  68. {
  69. CView::AssertValid();
  70. }
  71. void CSndView::Dump(CDumpContext& dc) const
  72. {
  73. CView::Dump(dc);
  74. }
  75. CSndDoc* CSndView::GetDocument() // non-debug version is inline
  76. {
  77. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSndDoc)));
  78. return (CSndDoc*)m_pDocument;
  79. }
  80. #endif //_DEBUG
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CSndView message handlers
  83. void CSndView::OnTimer(UINT nIDEvent) 
  84. {
  85. CRect rcClient;
  86. GetClientRect(rcClient);
  87. CClientDC dc(this);
  88. CBitmap Bitmap;
  89. CBitmap* pbmOld = NULL;
  90. CDC dcMem;
  91. dcMem.CreateCompatibleDC(&dc);
  92. Bitmap.CreateCompatibleBitmap(&dc,rcClient.right,rcClient.bottom);
  93. //pbmOld = dcMem.SelectObject(&m_bmBall);
  94. pbmOld = dcMem.SelectObject(&Bitmap);
  95. dcMem.PatBlt(0, 0,rcClient.right, rcClient.bottom, WHITENESS);
  96. dcMem.MoveTo(0,rcClient.bottom/2);
  97. // trace un graph correspondant a une fft (sinx/x)
  98.   //
  99. int x,y;
  100. dcMem.MoveTo(0,rcClient.bottom/2);
  101.   
  102. // display incomming signal
  103.   for  (x =0 ; x < (rcClient.right); x++)  // display Input
  104.   {
  105. y  = rcClient.bottom/2 - SoundIn.InputBuffer[x]/95 ;
  106. dcMem.LineTo(x,y);
  107. //yMoy[x] = (yMoy[x]+y)/2;
  108.   }
  109. dc.BitBlt(0,0,rcClient.right,rcClient.bottom,
  110. &dcMem, 0, 0, SRCCOPY);
  111. dcMem.SelectObject(pbmOld);
  112. dcMem.DeleteDC();
  113. // CView::OnTimer(nIDEvent);
  114. }
  115. void CSndView::OnInitialUpdate() 
  116. {
  117. CView::OnInitialUpdate();
  118. if (!SetTimer(1, 200 /*start slow*/, NULL))
  119. {
  120. MessageBox(_T("Not enough timers available for this window."),
  121. _T("Sound Test "), MB_ICONEXCLAMATION | MB_OK);
  122. // signal creation failure...
  123. return;
  124. }
  125. }