📄 setmute.cpp
字号:
// SetMute.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "SetMute.h"
#include "CFG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
DWORD WINAPI GetVolume(int dev);
bool WINAPI SetVolume(int dev,int vol);
bool WINAPI IsMute(int dev);
bool WINAPI SetMute(int dev,int vol);
int WINAPI GetVolumeInt(DWORD d_vol);
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CSetMuteApp
BEGIN_MESSAGE_MAP(CSetMuteApp, CWinApp)
//{{AFX_MSG_MAP(CSetMuteApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSetMuteApp construction
/**
* 得到音量值分为左右音量
* @param dev 整型参数 当前无效
* @return DWORD 类型 高16位为右声道的音量的值,低16位为左声道值,值的范围为0-65535,如果得到的值为-2,表示设置错误
*/
DWORD WINAPI GetVolume(int dev)
{
DWORD vol;
if(waveOutGetVolume(0,&vol)==MMSYSERR_NOERROR){
return vol;
}else{
return -2;
}
}
/**
* 设置音量的值
* @param dev 整型参数 当前版本无效
* @param vol 整型参数 设置音量的值 范围为0-100
* @return bool 类型 表示是否设置成功 TRUE设置成功 , FALSE 设置失败
*/
bool WINAPI SetVolume(int dev,int vol)//vol为0-100
{
long l,r;
DWORD volu;
l=(0xFFFF*vol/100);
r=(0xFFFF*vol/100);
volu=r*0x10000+l;
if(waveOutSetVolume(0,volu)==MMSYSERR_NOERROR){
return TRUE;
}else{
return FALSE;
}
}
/**
* 判断是否是静音
* @param dev 整型参数 当前版本无效
* @return bool 类型 表示是否设置成功 TRUE 静音 , FALSE 非静音
*/
bool WINAPI IsMute(int dev)//检查设备是否静音
{
CCFG fg;
DWORD t_mute;
fg.GetXmlCfgInt("mute",t_mute);
if(t_mute==0)
return TRUE;
else
return FALSE;
}
/**
* 设置静音
* @param dev 整型参数 当前版本无效
* @param vol 整型参数 0表示设置静音,非0表示恢复静音前的值
* @return bool 类型 表示是否设置成功 TRUE 成功 , FALSE 失败
*/
bool WINAPI SetMute(int dev,int vol)//设置设备静音
{
CCFG fg;
fg.SetXmlCfgInt("mute",vol);//保存当前静音设置
if(vol==0){
fg.SetXmlCfgInt("lastvol",GetVolumeInt(GetVolume(0)));//保存当前音量设置
if(waveOutSetVolume(0,0)==MMSYSERR_NOERROR){
return TRUE;
}else{
return FALSE;
}
}else{
DWORD t_vol;
fg.GetXmlCfgInt("lastvol",t_vol);//读出最后的音量
return SetVolume(0,t_vol);
}
}
/**
* 得到0-100的音量值
* @param DWORD d_vol 包括双声道音量的32位值 高16位为左声道,低16位为右声道
* @return int 0-100的音量值
*/
int WINAPI GetVolumeInt(DWORD d_vol){
return (min(HIWORD(d_vol),LOWORD(d_vol))*100)/0xFFFF;
}
CSetMuteApp::CSetMuteApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CSetMuteApp::~CSetMuteApp(){
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSetMuteApp object
CSetMuteApp theApp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -