VocPlayerDlg.cpp
上传用户:zctools
上传日期:2013-04-03
资源大小:26k
文件大小:3k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. // VocPlayerDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "VocPlayer.h"
  5. #include "VocPlayerDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CVocPlayerDlg dialog
  13. CVocPlayerDlg::CVocPlayerDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CVocPlayerDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CVocPlayerDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  20. }
  21. void CVocPlayerDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CVocPlayerDlg)
  25. // NOTE: the ClassWizard will add DDX and DDV calls here
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CVocPlayerDlg, CDialog)
  29. //{{AFX_MSG_MAP(CVocPlayerDlg)
  30. ON_WM_PAINT()
  31. ON_WM_QUERYDRAGICON()
  32. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  33. ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
  34. //}}AFX_MSG_MAP
  35.    ON_MESSAGE( MM_WOM_DONE,            OnMMDone )
  36. END_MESSAGE_MAP()
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CVocPlayerDlg message handlers
  39. BOOL CVocPlayerDlg::OnInitDialog()
  40. {
  41. CDialog::OnInitDialog();
  42. SetIcon(m_hIcon, TRUE); // Set big icon
  43. SetIcon(m_hIcon, FALSE); // Set small icon
  44. // TODO: Add extra initialization here
  45.    GetDlgItem( IDC_BUTTON_PLAY )->EnableWindow( false );
  46. return TRUE;  // return TRUE  unless you set the focus to a control
  47. }
  48. // If you add a minimize button to your dialog, you will need the code below
  49. //  to draw the icon.  For MFC applications using the document/view model,
  50. //  this is automatically done for you by the framework.
  51. void CVocPlayerDlg::OnPaint() 
  52. {
  53. if (IsIconic())
  54. {
  55. CPaintDC dc(this); // device context for painting
  56. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  57. // Center icon in client rectangle
  58. int cxIcon = GetSystemMetrics(SM_CXICON);
  59. int cyIcon = GetSystemMetrics(SM_CYICON);
  60. CRect rect;
  61. GetClientRect(&rect);
  62. int x = (rect.Width() - cxIcon + 1) / 2;
  63. int y = (rect.Height() - cyIcon + 1) / 2;
  64. // Draw the icon
  65. dc.DrawIcon(x, y, m_hIcon);
  66. }
  67. else
  68. {
  69. CDialog::OnPaint();
  70. }
  71. }
  72. HCURSOR CVocPlayerDlg::OnQueryDragIcon()
  73. {
  74. return (HCURSOR) m_hIcon;
  75. }
  76. void CVocPlayerDlg::OnButtonBrowse() 
  77. {
  78.    CFileDialog DlgFileOpen( true, "voc", NULL,
  79.                             OFN_PATHMUSTEXIST|OFN_LONGNAMES|OFN_HIDEREADONLY,
  80.                             "VOC Files (*.voc)|*.voc||",
  81.                             this );
  82.    if ( DlgFileOpen.DoModal() != IDOK )
  83.       return;
  84.    Filename = DlgFileOpen.GetPathName();
  85.    GetDlgItem( IDC_STATIC_FILENAME )->SetWindowText( Filename );
  86.    GetDlgItem( IDC_BUTTON_PLAY )->EnableWindow( true );
  87. }
  88. void CVocPlayerDlg::OnButtonPlay() 
  89. {
  90.    CString Filename;
  91.    GetDlgItem( IDC_STATIC_FILENAME )->GetWindowText( Filename );
  92.    VocPlayer.Play( Filename, this );
  93. }
  94. void CVocPlayerDlg::OnMMDone( WPARAM, LPARAM )
  95. {
  96.    VocPlayer.Reset();
  97.    VocPlayer.Clear();
  98. }