我在MFC Application中建立基于对话框的工程,有两个按钮,现在已经实现的功能:点第一个按钮放第一首歌,点第二个放第二首歌。  求教高人:我想加第三个按钮,名为执行。从而实现:点第一个或第二个按钮,然后再点第一个按钮或第二个按钮,然后再点第一个或第二个按钮......直到我点执行按钮,之前点的按钮按顺序执行。例如,我第一次点了第二个按钮,第二次点了第二个,第三次点了第一个,点执行按钮,就播放第二首歌,接着放第二首歌,然后放第一首歌。请问代码里我要加什么?   附上代码,哪位大哥帮我加一下,感激不尽。前面的代码都没动,只是后面两个我加了一点放音乐的代码。// 1Dlg.cpp : implementation file
//#include "stdafx.h"
#include "1.h"
#include "1Dlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
enum { IDD = IDD_ABOUTBOX }; protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support// Implementation
protected:
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CMy1Dlg dialog
CMy1Dlg::CMy1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy1Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CMy1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CMy1Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CMy1Dlg::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &CMy1Dlg::OnBnClickedCancel)
END_MESSAGE_MAP()
// CMy1Dlg message handlersBOOL CMy1Dlg::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 return TRUE;  // return TRUE  unless you set the focus to a control
}void CMy1Dlg::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 CMy1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy1Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMy1Dlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here////////////其他都没动,下面是放歌曲一的第一个按钮
_mp3Playing = true;
_mp3Player.Open("./DATA/song1.mp3");
_mp3Player.Play();
}void CMy1Dlg::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here/////下面是放歌曲一的第一个按钮 _mp3Playing = true;
_mp3Player.Open("./DATA/song2.mp3");
_mp3Player.Play();
}

解决方案 »

  1.   

    那你这个点击次数,是不是会很多或者很小啊?那可以用vector<int> 来存储你点击的数值啊,点击第一个按钮,在vector里加入 1 ,点击第二个按钮,加入2。等点击 “执行”时,再遍历这个vector 来依次执行就了了啊!
      

  2.   

    实在不行,如果方便的话,把你工程发到我邮箱 [email protected]我有时间再帮你看看,或者你百度一下 vector 怎么用
      

  3.   

    #include <vector>
    using namespace std;void CSongPlayDlg::OnBnClickedButton1()
    {
    string name="./成功.mp3";
    songvec.push_back(name);
    }void CSongPlayDlg::OnBnClickedButton2()
    {
    string name="./03.mp3";
    songvec.push_back(name);
    }void CSongPlayDlg::OnBnClickedButton3()
             
            string songname;
            _mp3Playing = true for(int i=0;i<songvec.size();i++){ songname=songvec[i];
    _mp3Player.Open(songname);
    _mp3Player.Play(); }  
    }  
      

  4.   

    #include <vector>
    using namespace std;
    vector <string> songvec;....
      

  5.   


    出现以下错误:
    error C2664: 'CMPlayer::Open' : cannot convert parameter 1 from 'std::string' to 'const char *'
    附:
    int CMPlayer::Open(const char* filename)
    {... }
      

  6.   

    额,学会看懂error。这里说,不能转换的参数string成为char *类型,自己网上百度下怎么转~~因为以后要经常用到这种基本的东西的~~
      

  7.   

    把工程发给我看看吧,[email protected]
      

  8.   

    你将你点击的顺序记录下来,保存在数组或者vector容器中,然后依次取出播放对应的文件即可