| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 259 人关注过本帖
标题:各位大虾帮忙看一下,如何改调用WAV的函数
只看楼主 加入收藏
tctculture
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-9-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
各位大虾帮忙看一下,如何改调用WAV的函数
代码如下

// mytextDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mytext.h"
#include "mytextDlg.h"

//
#include <Windows.h>
#include <Winuser.h>
//


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMytextDlg dialog

CMytextDlg::CMytextDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMytextDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CMytextDlg)
    m_strEditRXData = _T("");
    m_strEditTXData = _T("");
    m_volume = 50;
    m_speed = 3;
    m_showMessage = _T("普通状态");
    flag1 = false;
    flag2 = false;
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMytextDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMytextDlg)
    DDX_Text(pDX, IDC_EDIT_RXDATA, m_strEditRXData);
    DDX_Text(pDX, IDC_EDIT_TXDATA, m_strEditTXData);
    DDX_Control(pDX, IDC_MSCOMM1, m_crtlComm);
    DDX_Text(pDX, IDC_SHOWMESSAGE, m_showMessage);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMytextDlg, CDialog)
//{{AFX_MSG_MAP(CMytextDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_MANUALSEND, OnButtonManualsend)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMytextDlg message handlers
BOOL CMytextDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
   
    // 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
      
       m_crtlComm.SetCommPort(3);   //选择COM4
       m_crtlComm.SetInputMode(1); //输入方式为二进制方式
       m_crtlComm.SetInBufferSize(1024); //设置输入缓冲区大小
       m_crtlComm.SetOutBufferSize(512); //设置输出缓冲区大小
       //波特率9600,无校验,8个数据位,1个停止位
       m_crtlComm.SetSettings("9600,n,8,1");
       if(!m_crtlComm.GetPortOpen())
           m_crtlComm.SetPortOpen(TRUE);//打开串口   
       m_crtlComm.SetRThreshold(1); //参数1表示每当串口接收缓冲区中有多于
       //或等于1个字符时将引发一个接收数据的OnComm事件
       m_crtlComm.SetInputLen(0);  //设置当前接收区数据长度为0
       m_crtlComm.GetInput();    //先预读缓冲区以清除残留数据   
      
       return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CMytextDlg::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 CMytextDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

BEGIN_EVENTSINK_MAP(CMytextDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CMytextDlg)
ON_EVENT(CMytextDlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CMytextDlg::OnComm()
{
    // TODO: Add your control notification handler code here
   
    VARIANT variant_inp;
    COleSafeArray safearray_inp;
    LONG len,k;
    BYTE rxdata[2048]; //设置BYTE数组
    CString strtemp;
    CString show;
    if(m_crtlComm.GetCommEvent()==2) //事件值为2表示接收缓冲区内有字符
    {
        variant_inp=m_crtlComm.GetInput(); //读缓冲区
        safearray_inp=variant_inp;  //VARIANT型变量转换为ColeSafeArray型变量
        len=safearray_inp.GetOneDimSize(); //得到有效数据长度
        for(k=0;k<len;k++)
        {
            safearray_inp.GetElement(&k,rxdata+k);//转换为BYTE型数组
        }
        for(k=0;k<len;k++)             //将数组转换为Cstring型变量
        {   
            int bt = (int)*(char*)(rxdata+k);    //字符型            
            
            switch(bt){
                case 49: Beep(987  ,500);break;
                case 50: Beep(1108  ,500);break;
                case 51: Beep(1244  ,500);break;   
                case 52: Beep(1318  ,500);break;
                case 53: Beep(1479  ,500);break;
                case 54: Beep(1660  ,500);break;
                case 55: Beep(1863  ,500);
            }

            strtemp.Format("%d-",*(char*)(rxdata+k)-48);    //将字符送入临时变量strtemp存放
            m_strEditRXData+=strtemp;  //加入接收编辑框对应字符串  
        }
    }
    UpdateData(FALSE);  //更新编辑框内容
   
   
}

void CMytextDlg::OnButtonManualsend()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE); //读取编辑框内容
    m_crtlComm.SetOutput(COleVariant(m_strEditTXData));//发送数据   
}
我想把switch(bt){
                case 49: Beep(987  ,500);break;
                case 50: Beep(1108  ,500);break;
                case 51: Beep(1244  ,500);break;   
                case 52: Beep(1318  ,500);break;
                case 53: Beep(1479  ,500);break;
                case 54: Beep(1660  ,500);break;
                case 55: Beep(1863  ,500);
中的BEEP改为播放一个c:\新建文件夹的wav声音,是不是把beep改为直接改为 PlaySound("c:\新建文件夹\n.wav", NULL, SND_FILENAME | SND_ASYNC); 就可以了?就像这样
                case 49:  PlaySound("c:\新建文件夹\1.wav", NULL, SND_FILENAME | SND_ASYNC);break;
                case 50: PlaySound("c:\新建文件夹\2.wav", NULL, SND_FILENAME | SND_ASYNC);break;
                case 51:  PlaySound("c:\新建文件夹\3.wav", NULL, SND_FILENAME | SND_ASYNC);break;   
                case 52:  PlaySound("c:\新建文件夹\4.wav", NULL, SND_FILENAME | SND_ASYNC);break;
                case 53:  PlaySound("c:\新建文件夹\5.wav", NULL, SND_FILENAME | SND_ASYNC);break;
                case 54:  PlaySound("c:\新建文件夹\6.wav", NULL, SND_FILENAME | SND_ASYNC);break;
                case 55:  PlaySound("c:\新建文件夹\7.wav", NULL, SND_FILENAME | SND_ASYNC);
?恳请大家指点
搜索更多相关主题的帖子: include 如何 file 
2011-09-08 10:34
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:20 
这边用c多一些,可以贴到c++版块

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2011-09-08 18:05
快速回复:各位大虾帮忙看一下,如何改调用WAV的函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024261 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved