ClassWizard也可以,选择基类为Generic Class,跟着填写你的类名字,然后选择OK按钮。成了

解决方案 »

  1.   

    我也试过在vc开发环境里简单的用菜单File->New先建立一个类的头文件(.h),再建立一个类的实现文件(.cpp),代码一点问题都没有,但当我把这两个文件添加到别的工程中去的时候,却怎么也无法编译运行了!气人不气人?
    ----把你的类的.h, .cpp贴出来看看,把报的错也贴出来看看!
      

  2.   

    用jy(树) 的方法没问题.用菜单File->New先建立一个类的头文件(.h),再建立一个类的实现文件(.cpp),
    也应该没问题. 我经常这末干.
    把报的错也贴出来看看?
      

  3.   

        用file/new方法建立类的文件时,是不是没有考虑怎么防止重复包含?
      

  4.   

    下面是此类的.h文件和.cpp文件:
    一,头文件:include <afxwin.h>
    #include <mmsystem.h>
    #include <mciavi.h>
    #include <digitalv.h>class CWave
    {
    public:
    BOOL m_bOpen; //文件是否打开
    BOOL m_bIsPlaying; //文件是否播放
    BOOL m_bIsRecording; //是否正在录音
    WORD m_wDeviceID; //播放设备ID
    CString m_strFilePath; //音频文件完整路径,包括文件名public:
    CWave();
    virtual ~CWave();
    DWORD Open(); //打开文件
    DWORD Close(); //关闭文件
    DWORD Play(); //播放
    void Stop(); //停止播放
    DWORD Record(); //录音
    DWORD Save(CString FileName); //保存到文件
    WORD GetBitLong(); //得到音频量化位长度
    DWORD GetSampleRate(); //得到采样率
    DWORD GetChannel(); //得到当前声道
    DWORD GetWaveLength(); //得到音频长度}二,实现文件:#include "stdafx.h"
    #include "waveaudio.h"
    #include <afxwin.h>
    #include <mmsystem.h>CWave::CWave()
    {
    m_bOpen = m_bIsPlaying = m_bIsRecording = false;
    m_wDeviceID = 0;
    m_strFilePath = NULL;
    }CWave::~CWave()
    {
    Close();
    }DWORD CWave::Open() //成功返回 NULL 否则返回失败号
    //先打开,然后设置时间格式为:
    // MCI_FORMAT_MILLISECONDS
    //这样才能正确播放 wave 文件
    {
    if(m_bOpen){
    Close();
    } DWORD OpenFlag;
    MCI_OPEN_PARMS OpenP;
    OpenP.lpstrDeviceType = "waveaudio";
    OpenP.lpstrElementName= m_strFilePath; OpenFlag = mciSendCommand(NULL,MCI_OPEN,
    MCI_OPEN_ELEMENT|MCI_OPEN_TYPE,
    (DWORD)(LPVOID)&OpenP);
    if(OpenFlag){
    return OpenFlag; //返回打开失败号 
    }
    m_wDeviceID = OpenP.wDeviceID;
    OpenFlag = NULL;
    MCI_SET_PARMS SetP;
    SetP.dwTimeFormat = MCI_FORMAT_MILLISECONDS;
    OpenFlag = mciSendCommand(m_wDeviceID,MCI_SET,
    MCI_SET_TIME_FORMAT,(DWORD)(LPVOID)&SetP);
    if(OpenFlag){
    return OpenFlag; //返回设置失败号
    } m_bOpen = true;
    return NULL;
    }DWORD CWave::Play() //功能:播放 wave 文件
    //实现:直接发送MCI_PALY消息
    //      成功将 m_bIsPlaying 设成 true
    //返回值:成功返回 NULL 
    //   失败返回 失败号
    {
    MCI_PALY_PARMS PlayP;
    DWORD PlayFlag; PlayFlag = mciSendCommand(m_wDeviceID,MCI_PLAY,NULL,
    (DWORD)(LPVOID)&PlayP);
    if(PlayFlag){
    return PlayFlag; //播放失败,返回失败号
    }
    else{
    m_bIsPlaying = true;
    return NULL;
    }
    }void CWave::Stop() //功能:停止播放
    //      将 m_bIsPlaying 设置 false
    {
    mciSendCommand(m_wDeviceID,MCI_STOP,NULL,NULL);
    m_bIsPlaying = false;
    return;
    }DWORD CWave::Record() //功能:录音
    //实现:先关闭原文件,然后录音
    //      最后将 m_bIsRecording 设置 true
    //             m_Open 设置 true
    //返回值:成功返回 NULL
    //        否则返回 失败号
    {
    if(m_bOpen){
    Close();
    }

    DWORD OpenFlag;
    MCI_OPEN_PARMS OpenP;
    OpenP.lpstrDeviceType = "waveaudio";
    OpenP.lpstrElementName= "";

    OpenFlag = mciSendCommand(NULL,MCI_OPEN,
    MCI_OPEN_ELEMENT|MCI_OPEN_TYPE|MCI_WAIT,&OpenP);
    if(OpenFlag){
    return OpenFlag;
    }
    m_wDeviceID = OpenP.wDeviceID;
    DWORD RecFlag;
    MCI_RECORD_PARMS RecP;

    RecFlag = mciSendCommand(m_wDeviceID,MCI_RECORD,
    MCI_RECORD_OVERWRITE,(DWORD)(LPVOID)&RecP);
    if(RecFlag){
    return RecFlag;
    }
    m_bIsRecording = true;
    m_Open = true;
    return NULL;
    }DWORD CWave::Save(CString FileName) //功能:保存录音到文件
    //      将 m_bIsRecording 置为 false
    //参数:FileName 保存文件名
    //返回值:成功返回 NULL
    //        失败返回 错误号
    //注释:如果当前没有录音,
    //      则没有必要保存,
    //      并且返回 NULL
    {
    if(!m_bIsRecord){
    return 0;
    }
    if(m_bOpen){
    Stop();
    } DWORD SaveFlag;
    MCI_SAVE_PARMS SaveP;
    SaveP.lpFileName = FileName;
    SaveFlag = mciSendCommand(m_wDeviceID,MCI_SAVE,
    MCI_SAVE_FILE|MCI_WAIT,&SaveP);
    if(SaveFlag){
    return SaveFlag;
    }
    else{
    m_bIsRecording = false;
    return NULL;
    }
    }DWORD CWave::Close() //关闭文件及设备
    //清空数据成员
    {
    DWORD CloseFlag;
    if(m_wDeviceID){
    mciSendCommand(m_wDeviceID,MCI_STOP,MCI_WAIT,NULL);
    CloseFlag = mciSendCommand(m_wDeviceID,MCI_CLOSE,NULL,NULL);
    }
    if(CloseFlag){
    AfxMessageBox("关闭出现错误!");
    return CloseFlag;
    }
    m_bOpen = m_bIsPlaying = m_bIsRecording = false;
    m_wDeviceID = 0;
    m_strFilePath = NULL;
    return;
    }DWORD CWave::GetSampleRate() //得到采样率
    //返回值:成功返回采样率
    //        失败返回错误号
    {
    DWORD GetFlag;
    MCI_STATUS_PARMS StatusP;
    StatusP.dwItem = MCI_WAV_STATUS_SAMPLESPERSEC;

    GetFlag = mciSendCommand(m_wDeviceID,MCI_STATUS,
    MCI_WAIT|MCI_STATUS_ITEM,(DWORD)(LPVOID)&StatusP);
    if(GetFlag){
    return GetFlag;
    }
    else{
    return StatusP.dwReturn;
    }
    }DWORD CWave::GetChannel() //获得音频通道数
    //返回值:成功返回通道数
    //        失败返回错误号{
    DWORD GetFlag;
    MCI_STATUS_PARMS StatusP;
    StatusP.dwItem = MCI_WAVE_STATUS_CHANNELS;

    GetFlag = mciSendCommand(m_wDeviceID,MCI_STATUS,
    MCI_WAIT|MCI_STATUS_ITEM,(DWORD)(LPVOID)&StatusP);
    if(GetFlag){
    return GetFlag;
    }
    else{
    return StatusP.dwReturn;
    }
    }DWORD CWave::GetBitLong() //得到音频量化位长
    //返回值:成功返回量化位长
    //        失败返回错误号
    {
    DWORD GetFlag;
    MCI_STATUS_PARMS StatusP;
    StatusP.dwItem = MCI_WAVE_STATUS_BITSPERSAMPLE; GetFalg = mciSendCommand(m_wDeviceID,MCI_STATUS,
    MCI_WAIT|MCI_STATUS_ITEM,(DWORD)(LPVOID)&StatusP);
    if(GetFlag){
    return GetFlag;
    }
    else{
    return StatusP.dwReturn;
    }
    }DWORD CWave::GetWaveLength() //得到波形文件长度
    //返回值:成功返回波形文件长度
    //        失败返回错误号
    {
    DWORD GetFlag;
    MCI_STATUS_PARMS StatusP;
    StatusP.dwItem = MCI_STATUS_LENGTH; GetFlag = mciSendCommand(m_wDeviceID,MCI_STATUS,
    MCI_WAIT|MCI_STATUS_ITEM,&StatusP);
    if(GetFlag){
    return GetFlag;
    }
    else{
    return StatusP.dwReturn;
    }
    }下面市错误:
    ompiling...
    Example7Wave.cpp
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2236: unexpected 'class' 'CExample7WaveDlg'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before ':'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before ':'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before 'public'
    d:\work spaces\mm\example7wave\example7wavedlg.h(17) : error C2143: syntax error : missing ';' before '{'
    d:\work spaces\mm\example7wave\example7wavedlg.h(17) : error C2447: missing function header (old-style formal list?)
    D:\Work Spaces\mm\Example7Wave\Example7Wave.cpp(57) : error C2065: 'CExample7WaveDlg' : undeclared identifier
    D:\Work Spaces\mm\Example7Wave\Example7Wave.cpp(57) : error C2146: syntax error : missing ';' before identifier 'dlg'
    D:\Work Spaces\mm\Example7Wave\Example7Wave.cpp(57) : error C2065: 'dlg' : undeclared identifier
    D:\Work Spaces\mm\Example7Wave\Example7Wave.cpp(58) : error C2440: '=' : cannot convert from 'int *' to 'class CWnd *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    D:\Work Spaces\mm\Example7Wave\Example7Wave.cpp(59) : error C2228: left of '.DoModal' must have class/struct/union type
    Example7WaveDlg.cpp
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2236: unexpected 'class' 'CExample7WaveDlg'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before ':'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before ':'
    d:\work spaces\mm\example7wave\example7wavedlg.h(16) : error C2143: syntax error : missing ';' before 'public'
    d:\work spaces\mm\example7wave\example7wavedlg.h(17) : error C2143: syntax error : missing ';' before '{'
    d:\work spaces\mm\example7wave\example7wavedlg.h(17) : error C2447: missing function header (old-style formal list?)
    D:\Work Spaces\mm\Example7Wave\Example7WaveDlg.cpp(8) : fatal error C1083: Cannot open include file: 'waveaudio.h': No such file or directory
    waveaudio.cpp
    D:\Work Spaces\mm\CWave\waveaudio.cpp(14) : error C2628: 'CWave' followed by 'char' is illegal (did you forget a ';'?)
    D:\Work Spaces\mm\CWave\waveaudio.cpp(14) : error C2538: new : cannot specify initializer for arrays
    D:\Work Spaces\mm\CWave\waveaudio.cpp(25) : error C2593: 'operator =' is ambiguous
    D:\Work Spaces\mm\CWave\waveaudio.cpp(75) : error C2065: 'MCI_PALY_PARMS' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(75) : error C2146: syntax error : missing ';' before identifier 'PlayP'
    D:\Work Spaces\mm\CWave\waveaudio.cpp(75) : error C2065: 'PlayP' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(114) : error C2664: 'mciSendCommandA' : cannot convert parameter 4 from 'struct tagMCI_OPEN_PARMSA *' to 'unsigned long'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Work Spaces\mm\CWave\waveaudio.cpp(130) : error C2065: 'm_Open' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(143) : error C2065: 'm_bIsRecord' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(152) : error C2039: 'lpFileName' : is not a member of 'tagMCI_SAVE_PARMSA'
            d:\program files\microsoft visual studio\vc98\include\mmsystem.h(2997) : see declaration of 'tagMCI_SAVE_PARMSA'
    D:\Work Spaces\mm\CWave\waveaudio.cpp(154) : error C2664: 'mciSendCommandA' : cannot convert parameter 4 from 'struct tagMCI_SAVE_PARMSA *' to 'unsigned long'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\Work Spaces\mm\CWave\waveaudio.cpp(178) : error C2593: 'operator =' is ambiguous
    D:\Work Spaces\mm\CWave\waveaudio.cpp(179) : error C2561: 'Close' : function must return a value
            d:\work spaces\mm\cwave\waveaudio.h(30) : see declaration of 'Close'
    D:\Work Spaces\mm\CWave\waveaudio.cpp(188) : error C2065: 'MCI_WAV_STATUS_SAMPLESPERSEC' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(222) : error C2556: 'unsigned long __thiscall CWave::GetBitLong(void)' : overloaded function differs only by return type from 'unsigned short __thiscall CWave::GetBitLong(void)'
            d:\work spaces\mm\cwave\waveaudio.h(35) : see declaration of 'GetBitLong'
    D:\Work Spaces\mm\CWave\waveaudio.cpp(222) : error C2371: 'GetBitLong' : redefinition; different basic types
            d:\work spaces\mm\cwave\waveaudio.h(35) : see declaration of 'GetBitLong'
    D:\Work Spaces\mm\CWave\waveaudio.cpp(227) : error C2065: 'GetFalg' : undeclared identifier
    D:\Work Spaces\mm\CWave\waveaudio.cpp(246) : error C2664: 'mciSendCommandA' : cannot convert parameter 4 from 'struct tagMCI_STATUS_PARMS *' to 'unsigned long'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Generating Code...
    Error executing cl.exe.Example7Wave.exe - 36 error(s), 0 warning(s)
    下面是Example7Wave.h :/ Example7Wave.h : main header file for the EXAMPLE7WAVE application
    //#if !defined(AFX_EXAMPLE7WAVE_H__C0281A01_6EF4_4276_AB4B_7805C829FB86__INCLUDED_)
    #define AFX_EXAMPLE7WAVE_H__C0281A01_6EF4_4276_AB4B_7805C829FB86__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000#ifndef __AFXWIN_H__
    #error include 'stdafx.h' before including this file for PCH
    #endif#include "resource.h" // main symbols/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveApp:
    // See Example7Wave.cpp for the implementation of this class
    //class CExample7WaveApp : public CWinApp
    {
    public:
    CExample7WaveApp();// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CExample7WaveApp)
    public:
    virtual BOOL InitInstance();
    //}}AFX_VIRTUAL// Implementation //{{AFX_MSG(CExample7WaveApp)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    ///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EXAMPLE7WAVE_H__C0281A01_6EF4_4276_AB4B_7805C829FB86__INCLUDED_)下面是Example7Wave.cpp文件:// Example7Wave.cpp : Defines the class behaviors for the application.
    //#include "stdafx.h"
    #include "Example7Wave.h"
    #include "Example7WaveDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveAppBEGIN_MESSAGE_MAP(CExample7WaveApp, CWinApp)
    //{{AFX_MSG_MAP(CExample7WaveApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG
    ON_COMMAND(ID_HELP, CWinApp::OnHelp)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveApp constructionCExample7WaveApp::CExample7WaveApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CExample7WaveApp objectCExample7WaveApp theApp;/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveApp initializationBOOL CExample7WaveApp::InitInstance()
    {
    AfxEnableControlContainer(); // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); // Call this when using MFC in a shared DLL
    #else
    Enable3dControlsStatic(); // Call this when linking to MFC statically
    #endif CExample7WaveDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    //  dismissed with Cancel
    } // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
    }
    下面是Example7WaveDlg.h文件:
    // Example7WaveDlg.h : header file
    //#if !defined(AFX_EXAMPLE7WAVEDLG_H__BCFFFD13_6984_40F0_BDDE_124A12FF5DA1__INCLUDED_)
    #define AFX_EXAMPLE7WAVEDLG_H__BCFFFD13_6984_40F0_BDDE_124A12FF5DA1__INCLUDED_
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveDlg dialog
    #include "..\CWAVE\waveaudio.h" // Added by ClassViewclass CExample7WaveDlg : public CDialog
    {
    // Construction
    public:
    CExample7WaveDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CExample7WaveDlg)
    enum { IDD = IDD_EXAMPLE7WAVE_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CExample7WaveDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    CWave m_Wave;
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CExample7WaveDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnButtonInfo();
    afx_msg void OnButtonOpen();
    afx_msg void OnButtonPlay();
    afx_msg void OnButtonRecord();
    afx_msg void OnButtonSave();
    afx_msg void OnButtonStop();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_EXAMPLE7WAVEDLG_H__BCFFFD13_6984_40F0_BDDE_124A12FF5DA1__INCLUDED_)
    下面是Example7WaveDlg.cpp文件:// Example7WaveDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "Example7Wave.h"
    #include "Example7WaveDlg.h"#include "waveaudio.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass 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()/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveDlg dialogCExample7WaveDlg::CExample7WaveDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CExample7WaveDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CExample7WaveDlg)
    // 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 CExample7WaveDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CExample7WaveDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CExample7WaveDlg, CDialog)
    //{{AFX_MSG_MAP(CExample7WaveDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON_INFO, OnButtonInfo)
    ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
    ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
    ON_BN_CLICKED(IDC_BUTTON_RECORD, OnButtonRecord)
    ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
    ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CExample7WaveDlg message handlersBOOL CExample7WaveDlg::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 CWnd *m_pWnd; //还没有文件打开,所以先禁止一些按钮
    m_pWnd = GetDlgItem(IDC_BUTTON_PLAY);
    m_pWnd->EnableWindow(false);
    m_pWnd = GetDlgItem(IDC_BUTTON_SAVE);
    m_pWnd->EnableWindow(false);
    m_pWnd = GetDlgItem(IDC_BUTTON_STOP);
    m_pWnd->EnableWindow(false);
    m_PWnd = GetDlgItem(IDC_BUTTON_INFO);
    m_pWnd->EnableWindow(false);
    //-----------------------完毕------- return TRUE;  // return TRUE  unless you set the focus to a control
    }void CExample7WaveDlg::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 CExample7WaveDlg::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 CExample7WaveDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CExample7WaveDlg::OnButtonInfo() 
    {
    // TODO: Add your control notification handler code here

    }void CExample7WaveDlg::OnButtonOpen() 
    {
    // TODO: Add your control notification handler code here
    CString Files;
    CString strStatus;
    char buf[128];
    DWORD dFlag;

    Files = "波形音频文件(*.wav)|*.WAV||";
    CFileDialog FileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,Files);
    if(FileDlg.DoModal()==IDOK){
    m_Wave.m_strFilePath = FileDlg.GetPathName();
    dFlag = m_Wave.Open();
    if(dFlag){
    mciGetErrorString(dFlag,buf,strlen(buf));
    AfxMessageBox(buf);
    return;
    }
    strStatus.Format("文件已经正确打开");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus); CWnd *pWnd;
    pWnd = GetDlgItem(IDC_BUTTON_PLAY);
    pWnd->EnableWindow(true);
    pWnd = GetDlgItem(IDC_BUTTON_INFO);
    pWnd->EnableWindow(true);
    }

    }void CExample7WaveDlg::OnButtonPlay() 
    {
    // TODO: Add your control notification handler code here
    CString strStatus;
    char buf[128];
    DWORD dFlag; dFlag = m_Wave.Play();
    if(dFlag){
    mciGetErrorString(dFlag,buf,strlen(buf));
    AfxMessageBox(buf);
    return;
    }

    strStatus.Format("正在播放……");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus); CWnd *pWnd;
    pWnd = GetDlgItem(IDC_BUTTON_RECORD);
    pWnd->EnableWindow(false);
    pWnd = GetDlgItem(IDC_BUTTON_STOP);
    pWnd->EnableWindow(true);}void CExample7WaveDlg::OnButtonRecord() 
    {
    // TODO: Add your control notification handler code here
    CString strStatus;
    char buf[128];
    DWORD dFlag;
    CWnd* pWnd;

    pWnd = GetDlgItem(IDC_BUTTON_PLAY);
    pWnd->EnableWindow(false);
    pWnd = GetDlgItem(IDC_BUTTON_OPEN);
    pWnd->EnableWindow(false);
    pWnd = GetDlgItem(IDC_BUTTON_SAVE);
    pWnd->EnableWindow(false); strStatus.Format("正在录音……");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus); m_Wave.Record();}void CExample7WaveDlg::OnButtonSave() 
    {
    // TODO: Add your control notification handler code here
    CString strStatus;
    char buf[128];
    DWORD dFlag;
    CString Filter; Filter = "波形文件(*.wav)|*.WAV||";
    CFileDialog FileDlg(false,NULL,NULL,OFN_OVERWRITEPROMPT,Filter);
    FileDlg.m_ofn.lpstrDefExt = "wav";
    if(FileDlg.DoModal()==IDOK){
    strStatus.Format("正在保存文件……");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus); dFlag = m_Wave.Save(FileDlg.GetPathName());
    if(dFlag){
    mciGetErrorString(dFlag,buf,strlen(buf));
    AfxMessageBox(buf);
    return;
    }

    strStatus.Empty();
    strStatus.Format("文件保存结束");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus);
    }

    }void CExample7WaveDlg::OnButtonStop() 
    {
    // TODO: Add your control notification handler code here
    CWnd *pWnd;
    pWnd = GetDlgItem(IDC_BUTTON_PLAY);
    pWnd->EnableWindow(true);
    pWnd = GetDlgItem(IDC_BUTTON_OPEN);
    pWnd->EnableWindow(true);
    pWnd = GetDlgItem(IDC_BUTTON_SAVE);
    pWnd->EnableWindow(true); m_Wave.Stop(); CString strStatus;
    strStatus.Format("停止");
    SetDlgItemText(IDC_STATIC_STATUS,strStatus);}希望诸位朋友能给予指点,谢谢!(请继续关注)
      

  5.   

    to jy(树):
       怎么我的ClassWizard 的基类列表中没有你所说的 Generic Class, 而只有generic CWnd,建立新类的步骤不是在ClassWizard\ 中按 Add Class... -> New...  然后在Name中写类名称,在Base Class 中选择其基类么?如果是的话,那怎么Base Class中没有Generic Class 基类呢?
      

  6.   

    朋友你要在你的CWave类的 .h文件中加入下面的项目
    #if !defined(_CWAVE_H)
    #define _CWAVE_H
    //下面是你的 .h的代码
    .
    .
    .
    #endif //预定义结束
    这样你编译就不会出错了,建立方法当然是可以随意的建了:)
      

  7.   

    对不起,对不起,不是基类,而是类类型Class Type。致歉。
      

  8.   

    问题的一个原因在于
    class CWave
    {
    ...
    }
    这个声明结尾应该有“;”的。(我用全角字符来强调)
      

  9.   

    谢谢大家的热心帮助,所以我决定给大家每人都加分,尤其要感谢yv(树),因为你的指点使我找到了原因所在,谢谢!
    但是,老问题去了,新问题又来了:
        class CWave
       {
           ...
       }
        这个声明结尾应加上“;”后,再改了一些字母一类的错误后(注意:没有改变任何#include语句)然后能顺利通过编译了,但连接时却出现了这样的错误提示:
    --------------------Configuration: Example7Wave - Win32 Debug--------------------
    Linking...
    LINK : fatal error LNK1104: cannot open file "mmwin.lib"
    Error executing link.exe.Example7Wave.exe - 1 error(s), 0 warning(s)我已经在project->seting->ling中设置了要连接 mmwin.lib ,但为什么还有错呢?