100分再次请教怎么关闭系统音量(静音)

msvbvm60 2003-07-17 02:13:12
我想在程序中直接控制系统音量到 静音,招了很多资料都不行,VC编译不能通过
...全文
382 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
msvbvm60 2003-07-20
  • 打赏
  • 举报
回复
偶的信箱:

msvcp60@tom.com

谢谢! 收到你的代码后就给分!!!
CreaTive1911 2003-07-20
  • 打赏
  • 举报
回复
给你发了
harrypotter 2003-07-20
  • 打赏
  • 举报
回复
study
slimsymphony 2003-07-19
  • 打赏
  • 举报
回复
syl08341(沈阳老零)
这个人还真是可怕嘞
CreaTive1911 2003-07-19
  • 打赏
  • 举报
回复
CMuteDlg::CMuteDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMuteDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMuteDlg)
m_bMute = FALSE;
m_strStat1 = _T("");
m_strStat2 = _T("");
m_strStat3 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMuteDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMuteDlg)
DDX_Check(pDX, IDC_CHECK, m_bMute);
DDX_Text(pDX, IDC_STATIC1, m_strStat1);
DDX_Text(pDX, IDC_STATIC2, m_strStat2);
DDX_Text(pDX, IDC_STATIC3, m_strStat3);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMuteDlg, CDialog)
//{{AFX_MSG_MAP(CMuteDlg)
ON_WM_DESTROY()
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CHECK, OnMute)
ON_MESSAGE(MM_MIXM_CONTROL_CHANGE, OnMixerCtrlChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMuteDlg message handlers

BOOL CMuteDlg::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
if (this->amdInitialize())
{
// display the number of mixer devices present in the system
m_strStat1.Format(IDS_FMTNUMMIXERS, m_nNumMixers);

// display the information about the first mixer
m_strStat2.Format(IDS_FMTCAPS,
m_mxcaps.szPname, m_mxcaps.cDestinations);

// get the Control ID and the names
this->amdGetMasterMuteControl();

// display the line and control name
m_strStat3.Format(IDS_FMTNAMES,
m_strDstLineName, m_strMuteControlName);

// get the initial value of the mute control
LONG lVal;
if (this->amdGetMasterMuteValue(lVal))
m_bMute = lVal;

this->UpdateData(FALSE);
}

return TRUE; // return TRUE unless you set the focus to a control
}

void CMuteDlg::OnDestroy()
{
this->amdUninitialize();

CDialog::OnDestroy();
}

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

void CMuteDlg::OnMute()
{
// TODO: Add your control notification handler code here
// set the master mute value according to the state of the check box
m_bMute = !m_bMute;
this->amdSetMasterMuteValue(m_bMute);
}

LONG CMuteDlg::OnMixerCtrlChange(UINT wParam, LONG lParam)
{
if ((HMIXER)wParam == m_hMixer && (DWORD)lParam == m_dwMuteControlID)
{
// The state of the master mute control has changed. Refresh it.
LONG lVal;
if (this->amdGetMasterMuteValue(lVal))
m_bMute = lVal;

this->UpdateData(FALSE);
}

return 0L;
}

BOOL CMuteDlg::amdInitialize()
{
// get the number of mixer devices present in the system
m_nNumMixers = ::mixerGetNumDevs();

m_hMixer = NULL;
::ZeroMemory(&m_mxcaps, sizeof(MIXERCAPS));

// open the first mixer
// A "mapper" for audio mixer devices does not currently exist.
if (m_nNumMixers != 0)
{
if (::mixerOpen(&m_hMixer,
0,
(DWORD)this->GetSafeHwnd(),
NULL,
MIXER_OBJECTF_MIXER | CALLBACK_WINDOW)
!= MMSYSERR_NOERROR)
return FALSE;

if (::mixerGetDevCaps((UINT)m_hMixer, &m_mxcaps, sizeof(MIXERCAPS))
!= MMSYSERR_NOERROR)
return FALSE;
}

return TRUE;
}

BOOL CMuteDlg::amdUninitialize()
{
BOOL bSucc = TRUE;

if (m_hMixer != NULL)
{
bSucc = ::mixerClose(m_hMixer) == MMSYSERR_NOERROR;
m_hMixer = NULL;
}

return bSucc;
}

BOOL CMuteDlg::amdGetMasterMuteControl()
{
m_strDstLineName.Empty();
m_strMuteControlName.Empty();

if (m_hMixer == NULL)
return FALSE;

// get dwLineID
MIXERLINE mxl;
mxl.cbStruct = sizeof(MIXERLINE);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
if (::mixerGetLineInfo((HMIXEROBJ)m_hMixer,
&mxl,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINEINFOF_COMPONENTTYPE)
!= MMSYSERR_NOERROR)
return FALSE;

// get dwControlID
MIXERCONTROL mxc;
MIXERLINECONTROLS mxlc;
mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
mxlc.dwLineID = mxl.dwLineID;
mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
mxlc.cControls = 1;
mxlc.cbmxctrl = sizeof(MIXERCONTROL);
mxlc.pamxctrl = &mxc;
if (::mixerGetLineControls((HMIXEROBJ)m_hMixer,
&mxlc,
MIXER_OBJECTF_HMIXER |
MIXER_GETLINECONTROLSF_ONEBYTYPE)
!= MMSYSERR_NOERROR)
return FALSE;

// record dwControlID
m_strDstLineName = mxl.szName;
m_strMuteControlName = mxc.szName;
m_dwMuteControlID = mxc.dwControlID;

return TRUE;
}

BOOL CMuteDlg::amdGetMasterMuteValue(LONG &lVal) const
{
if (m_hMixer == NULL ||
m_strDstLineName.IsEmpty() || m_strMuteControlName.IsEmpty())
return FALSE;

MIXERCONTROLDETAILS_BOOLEAN mxcdMute;
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = m_dwMuteControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = &mxcdMute;
if (::mixerGetControlDetails((HMIXEROBJ)m_hMixer,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_GETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
return FALSE;

lVal = mxcdMute.fValue;

return TRUE;
}

BOOL CMuteDlg::amdSetMasterMuteValue(LONG lVal) const
{
if (m_hMixer == NULL ||
m_strDstLineName.IsEmpty() || m_strMuteControlName.IsEmpty())
return FALSE;

MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { lVal };
MIXERCONTROLDETAILS mxcd;
mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
mxcd.dwControlID = m_dwMuteControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = 0;
mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
mxcd.paDetails = &mxcdMute;
if (::mixerSetControlDetails((HMIXEROBJ)m_hMixer,
&mxcd,
MIXER_OBJECTF_HMIXER |
MIXER_SETCONTROLDETAILSF_VALUE)
!= MMSYSERR_NOERROR)
return FALSE;

return TRUE;
}
CreaTive1911 2003-07-19
  • 打赏
  • 举报
回复
算了,我把两个重要的给你帖出来
// MuteDlg.h : header file
//

#if !defined(AFX_MUTEDLG_H__39694507_F4A0_11D1_9F80_006008984DF6__INCLUDED_)
#define AFX_MUTEDLG_H__39694507_F4A0_11D1_9F80_006008984DF6__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

/////////////////////////////////////////////////////////////////////////////
// CMuteDlg dialog

class CMuteDlg : public CDialog
{
// Construction
public:
CMuteDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CMuteDlg)
enum { IDD = IDD_MUTE_DIALOG };
BOOL m_bMute;
CString m_strStat1;
CString m_strStat2;
CString m_strStat3;
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMuteDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
//{{AFX_MSG(CMuteDlg)
virtual BOOL OnInitDialog();
afx_msg void OnDestroy();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnMute();
afx_msg LONG OnMixerCtrlChange(UINT wParam, LONG lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
UINT m_nNumMixers;
HMIXER m_hMixer;
MIXERCAPS m_mxcaps;

CString m_strDstLineName, m_strMuteControlName;
DWORD m_dwMuteControlID;

BOOL amdUninitialize();
BOOL amdInitialize();
BOOL amdGetMasterMuteControl();
BOOL amdGetMasterMuteValue(LONG &lVal) const;
BOOL amdSetMasterMuteValue(LONG lVal) const;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MUTEDLG_H__39694507_F4A0_11D1_9F80_006008984DF6__INCLUDED_)
CreaTive1911 2003-07-19
  • 打赏
  • 举报
回复
我有源程序,你告诉我你的EMAIL,我打包发给你
msvbvm60 2003-07-19
  • 打赏
  • 举报
回复
不行的,这种办法不能让系统静音。。。。。。
bjzhaoxiao 2003-07-19
  • 打赏
  • 举报
回复
up
Tseek 2003-07-19
  • 打赏
  • 举报
回复
将m_ActiveMovie.SetVolume(-4000);
这一条改为:
m_ActiveMovie.SetVolume(-8000);
msvbvm60 2003-07-18
  • 打赏
  • 举报
回复
我作了个 DIALOG,一个 BUTTON,

m_ActiveMovie.SetVolume(-4000);


后 ,WINAMP照样能放出声音。。。。。 有其他好的类马?
无敌魔仙 2003-07-17
  • 打赏
  • 举报
回复
关注
Tseek 2003-07-17
  • 打赏
  • 举报
回复
m_ActiveMovie.SetVolume(-4000);
这一条改为:
m_ActiveMovie.SetVolume(-8000);
即可
msvbvm60 2003-07-17
  • 打赏
  • 举报
回复
我试验了下,不行。。。
双杯献酒 2003-07-17
  • 打赏
  • 举报
回复
Up
syl08341 2003-07-17
  • 打赏
  • 举报
回复
:
bugfree 2003-07-17
  • 打赏
  • 举报
回复
对不起, 我贴晚了, 分不要了, 楼主可以读读这个连接
http://www.ccw.com.cn/htm/produ/special/vc/jiqiao/01_9_13_22.asp
bugfree 2003-07-17
  • 打赏
  • 举报
回复
读读这段文字:

在声卡的控制菜单上给出了“静音”操作,那么能否为我们自己制作的媒体播放器加上 “静音”功能呢?回答是肯定的。虽然ActiveMovie控件并没有直接提供“静音”函数,但可以通过控制函数SetVolume()的参数来实现“静音”的效果。笔者经过反复试验,当 SetVolume()的参数设为-4000使效果比较理想。要实现静音功能,应先为“音量控制”加入菜单项“静音”,并添加消息响应函数OnMute(),代码如下:

void CVcdDlg::OnMute()
{
// TODO: Add your command handler code here
m_ActiveMovie.Pause ();
m_ActiveMovie.SetVolume(-4000);
m_ActiveMovie.Run ();
}
zxyin1 2003-07-17
  • 打赏
  • 举报
回复
---- 在声卡的控制菜单上给出了“静音”操作,那么能否为我们自
己制作的媒体播放器加上 “静音”功能呢?回答是肯定的。虽然
ActiveMovie控件并没有直接提供“静音”函数,但可以通过控制函
数SetVolume()的参数来实现“静音”的效果。笔者经过反复试验,
当 SetVolume()的参数设为-4000使效果比较理想。要实现静音功能,应先为“
音量控制”加入菜单项“静音”,并添加消息响应函数OnMute(),
代码如下:
void CVcdDlg::OnMute()
/ TODO: Add your command handler code here
m_ActiveMovie.Pause ();
_ActiveMovie.SetVolume(-4000);
_ActiveMovie.Run ();

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧