【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“PlayMIDIDlg.cpp”一文,供大家参考学习!
// PlayMIDIDlg.cpp : 实现文件(implementation file)
//
#include "stdafx.h"
#include "PlayMIDI.h"
#include "PlayMIDIDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV Support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlayMidiDlg dialog
CPlayMidiDlg::CPlayMidiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPlayMidiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPlayMidiDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPlayMidiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPlayMidiDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPlayMidiDlg, CDialog)
//{{AFX_MSG_MAP(CPlayMidiDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPENFILE, OnOpenFile)
ON_BN_CLICKED(IDC_PLAY, OnPlay)
ON_BN_CLICKED(IDC_STOP, OnStop)
//}}AFX_MSG_MAP
ON_MESSAGE(MM_MCINOTIFY, OnMciNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlayMidiDlg message handlers
BOOL CPlayMidiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
midi.Open(this); // 开启 CMidi 音源
SetDlgItemText(IDC_MESSAGE, "");
GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CPlayMidiDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPlayMidiDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPlayMidiDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPlayMidiDlg::OnOpenFile()
{
// TODO: Add your control notification handler code here
char path[_MAX_PATH];
GetDlgItemText(IDC_PATH, path, _MAX_PATH);
CFileDialog dlg(TRUE, "mid", path, OFN_HIDEREADONLY, "MIDI(*.mid,*.rmi)|*.mid;*.rmi||", this);
dlg.m_ofn.lpstrFile = path;
if (dlg.DoModal() == IDOK) {
SetDlgItemText(IDC_PATH, path);
}
}
void CPlayMidiDlg::OnPlay()
{
// TODO: Add your control notification handler code here
char path[_MAX_PATH];
GetDlgItemText(IDC_PATH, path, _MAX_PATH);
if (midi.Play(path)) {
char str[_MAX_PATH + 16];
sprintf(str, "正在播放%s", path);
SetDlgItemText(IDC_MESSAGE, str);
GetDlgItem(IDC_STOP)->EnableWindow(TRUE);
}
}
void CPlayMidiDlg::OnStop()
{
// TODO: Add your control notification handler code here
midi.Stop();
SetDlgItemText(IDC_MESSAGE, "停止中");
GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
}
// MCI 的通知
LRESULT CPlayMidiDlg::OnMciNotify(WPARAM wParam, LPARAM lParam)
{
if (wParam == MCI_NOTIFY_SUCCESSFUL) {
if (midi.MciNotify(LOWORD(lParam))) {
// 播放完毕
if (SendDlgItemMessage(IDC_LOOP, BM_GETCHECK) == BST_CHECKED) {
// 重覆播放
midi.Replay();
}
else {
// 停止掆巭偡傞
midi.Stop();
SetDlgItemText(IDC_MESSAGE, "播放完毕");
GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
}
return 0L;
}
}
// 如果这里收到的不是midi传来的通知(Notify),就是发生错误
return 0L;
}
上一篇:
PlayMIDI.cpp
下一篇:
产品定价因素分析MBA论文:以印度移动应用程序定价分析为例