你好,游客 登录
背景:
阅读新闻

VC++之多媒体编程之左右声道控制 - Augusdi的专栏

[日期:2013-04-05] 来源:  作者: [字体: ]


一、创建对话框应用程序


二、编辑对话框资源

控件ID与标题(红色部分)

IDC_SLIDER_LEFT                                           (左声道控制滑块)
IDC_SLIDER_RIGHT                                         (右声道控制滑块)
IDOK                          退出


三、添加变量、函数

        1、添加变量


       2、添加消息响应函数


四、添加代码

       1、于“stdafx.h”文件内添加包含语句

// stdafx.h : include file for standard system include files,
...
#endif // _AFX_NO_AFXCMN_SUPPORT
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
//{{AFX_INSERT_LOCATION}}
#endif

       2、添加初始化代码

BOOL CSoundDlg::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
m_left.SetRange(0,200);
m_right.SetRange(0,200); 
return TRUE; // return TRUE unless you set the focus to a control
}

       3、为函数添加代码

void CSoundDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
// TODO: Add your message handler code here and/or call default
DWORD pos;
int scrollpos;
if(pScrollBar->m_hWnd==m_left.m_hWnd) //移动左声道控件
{
   scrollpos=m_left.GetPos();
   ::waveOutGetVolume(0,&pos); //获得当前信息
   pos=pos&0x0000ffff|(scrollpos<<8);
   ::waveOutSetVolume(0,pos);   //设置声音信息
}
if(pScrollBar->m_hWnd==m_right.m_hWnd) //移动右声道控件
{
   scrollpos=m_right.GetPos();
   ::waveOutGetVolume(0,&pos);    //修改音量
   pos=pos&0xffff0000|(scrollpos<<24);
   ::waveOutSetVolume(0,pos);
}

CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

五、编译

六、运行


七、函数说明

       1、WaveOutGetVolume函数声明

        MMRESULT waveOutGetVolume(HWAVEOUT hwo,LPDWORD pdwVolume)

        hwo:指向一打开的音频输出设备句柄。

        pdwVolume:指向一个包含当前音频设备句柄的变量。

        功能:获取当前音频输出设备的信息。函数调用成功,返回MMSYSERR_NOERROR。

       2、WaveOUtSetvolume函数声明

       waveOutSetVolume(HWAVEOUT hwo,DWORD pdwVolume)

        how:指向一打开的音频输出设备句柄。

       pdwVolume:新音频设备设置信息。

        功能:重新设置当前音频输出设备的信息。函数调用成功,返回MMSYSERR_NOERROR。





收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻