#ifdef SPEAKERDEVMUTECONTROL
# define SPEAKERDEVMUTECONTROL_EXPORT __declspec(dllexport)
#else
# define SPEAKERDEVMUTECONTROL_EXPORT __declspec(dllimport)
#endif
SPEAKERDEVMUTECONTROL_EXPORT bool setSpeakerDevName(const chConstStringA& strDevName);
SPEAKERDEVMUTECONTROL_EXPORT bool cancleSpeakerDevMute();
SPEAKERDEVMUTECONTROL_EXPORT bool returnSpeakerDevMute();

SPEAKERDEVMUTECONTROL_EXPORT int GetDevIDByName(chStringA strDevName);
SPEAKERDEVMUTECONTROL_EXPORT BOOL getSystemMuteStatusLaterWindowVista(BOOL& bMuted);
SPEAKERDEVMUTECONTROL_EXPORT BOOL setSystemMuteLaterWindowVista(BOOL bMuted = FALSE);
SPEAKERDEVMUTECONTROL_EXPORT BOOL setSystemMuteLaterWindowVistaByDevID(UINT devID, BOOL bMuted = FALSE);
SPEAKERDEVMUTECONTROL_EXPORT BOOL getSystemMuteStatusLaterWindowVistaByDevID(UINT devID, BOOL& bMuted);

//////////////////////

#include "../ETLLib/ETLLib.hpp"
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0600
#include <Windows.h>
#include <endpointvolume.h>
#include <mmdeviceapi.h>
#include <devicetopology.h>
#include <FunctionDiscoveryKeys_devpkey.h>
#include "SpeakerDevMuteControl.h"

#define SAFE_RELEASE(punk) \
if ((punk) != NULL) \
{ (punk)->Release(); (punk) = NULL; }

#define INIT_DEFAULT_IAUDIOENDPOINT \
CoInitialize(NULL);\
hr = S_OK;\
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),\
NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator),(void**)&m_pEnumerator);\
if(SUCCEEDED(hr))\
{\
hr = m_pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &m_pDevice);\
if (SUCCEEDED(hr))\
{\
hr = m_pDevice->Activate(__uuidof(IAudioEndpointVolume),\
CLSCTX_ALL, NULL, (void**)&m_pEndptVolCtrl);\
}\
}
#define INIT_IAUDIOENDPOINT_BYID(devID) \
CoInitialize(NULL);\
hr = S_OK;\
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),\
NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator),(void**)&m_pEnumerator);\
if(SUCCEEDED(hr))\
{\
hr = m_pEnumerator->EnumAudioEndpoints(eAll, DEVICE_STATEMASK_ALL, &m_pCollection);\
if (SUCCEEDED(hr))\
{\
hr = m_pCollection->Item(devID, &m_pDevice);\
if (SUCCEEDED(hr))\
{\
hr = m_pDevice->Activate(__uuidof(IAudioEndpointVolume),\
CLSCTX_ALL, NULL, (void**)&m_pEndptVolCtrl);\
}\
}\
}

#define INIT_DEVICECOLLECTION \
CoInitialize(NULL);\
hr = S_OK;\
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),\
NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator),(void**)&m_pEnumerator);\
if(SUCCEEDED(hr))\
{\
hr = m_pEnumerator->EnumAudioEndpoints(eAll, DEVICE_STATEMASK_ALL, &m_pCollection);\
}
#define UNINIT_IAUDIOENDPPINTVOLUME \
SAFE_RELEASE(m_pEndptVolCtrl);\
SAFE_RELEASE(m_pDevice);\
SAFE_RELEASE(m_pEnumerator);\
SAFE_RELEASE(m_pCollection);\
CoUninitialize();

int GetDevIDByName(chStringA strDevName)
{
if (strDevName.empty())
{
return -1;
}
chStringW strDevNameW = chUTF82W(strDevName);
IAudioEndpointVolume *m_pEndptVolCtrl = NULL;
IMMDevice *m_pDevice = NULL;
IMMDeviceCollection *m_pCollection = NULL;
IMMDeviceEnumerator *m_pEnumerator = NULL;
HRESULT hr = S_OK;
INIT_DEVICECOLLECTION;
if (SUCCEEDED(hr))
{
UINT nDevCounts = 0;
m_pCollection->GetCount(&nDevCounts);
for (int i = 0; i < (int)nDevCounts; i++)
{
hr = m_pCollection->Item(i, &m_pDevice);
DWORD state;
m_pDevice->GetState(&state);
if (state == DEVICE_STATE_NOTPRESENT )
{
continue;
}
IPropertyStore* pRopertyStore;
hr = m_pDevice->OpenPropertyStore(STGM_READ, &pRopertyStore);
if (SUCCEEDED(hr))
{
PROPVARIANT varName;
PropVariantInit(&varName);
hr = pRopertyStore->GetValue(PKEY_Device_FriendlyName, &varName);
typedef uCTextHelper<WCHAR, false> WCI;
if (WCI::strncmp(strDevNameW.c_ptr(), varName.pwszVal, strDevNameW.length()) == 0)
{
return i;
}
}
}
}
return -1;
}
BOOL setSystemMuteLaterWindowVista(BOOL bMuted /*= FALSE*/)
{
BOOL bReresult = FALSE;
IAudioEndpointVolume *m_pEndptVolCtrl = NULL;
IMMDevice *m_pDevice = NULL;
IMMDeviceCollection *m_pCollection = NULL;
IMMDeviceEnumerator *m_pEnumerator = NULL;
HRESULT hr = S_OK;
INIT_DEFAULT_IAUDIOENDPOINT;
if (SUCCEEDED(hr))
{
hr = m_pEndptVolCtrl->SetMute(bMuted, NULL);
if (SUCCEEDED(hr))
{
bReresult = TRUE;
}
}
UNINIT_IAUDIOENDPPINTVOLUME;
return bReresult;
}

BOOL getSystemMuteStatusLaterWindowVista(BOOL& bMuted)
{
BOOL bReresult = FALSE;
IAudioEndpointVolume *m_pEndptVolCtrl = NULL;
IMMDevice *m_pDevice = NULL;
IMMDeviceCollection *m_pCollection = NULL;
IMMDeviceEnumerator *m_pEnumerator = NULL;
HRESULT hr = S_OK;
INIT_DEFAULT_IAUDIOENDPOINT;
if (SUCCEEDED(hr))
{
hr = m_pEndptVolCtrl->GetMute(&bMuted);
if (SUCCEEDED(hr))
{
bReresult = TRUE;
}
}
UNINIT_IAUDIOENDPPINTVOLUME;
return bReresult;
}

BOOL setSystemMuteLaterWindowVistaByDevID(UINT devID, BOOL bMuted /*= FALSE*/)
{
if (devID == -1)
{
return setSystemMuteLaterWindowVista(bMuted);
}

BOOL bReresult = FALSE;
IMMDeviceCollection *m_pCollection = NULL;
IMMDevice *m_pDevice = NULL;
IAudioEndpointVolume *m_pEndptVolCtrl = NULL;
IMMDeviceEnumerator *m_pEnumerator = NULL;
HRESULT hr = S_OK;
INIT_IAUDIOENDPOINT_BYID(devID);
if (SUCCEEDED(hr))
{
hr = m_pEndptVolCtrl->SetMute(bMuted, NULL);
if (SUCCEEDED(hr))
{
bReresult = TRUE;
}
}
UNINIT_IAUDIOENDPPINTVOLUME;
return bReresult;
}

BOOL getSystemMuteStatusLaterWindowVistaByDevID(UINT devID, BOOL& bMuted)
{
if (devID == -1)
{
return getSystemMuteStatusLaterWindowVista(bMuted);
}

BOOL bReresult = FALSE;
IMMDevice *m_pDevice = NULL;
IMMDeviceCollection *m_pCollection = NULL;
IAudioEndpointVolume *m_pEndptVolCtrl = NULL;
IMMDeviceEnumerator *m_pEnumerator = NULL;
HRESULT hr = S_OK;
INIT_IAUDIOENDPOINT_BYID(devID);
if (SUCCEEDED(hr))
{
hr = m_pEndptVolCtrl->GetMute(&bMuted);
if (SUCCEEDED(hr))
{
bReresult = TRUE;
}
}
UNINIT_IAUDIOENDPPINTVOLUME;
return bReresult;
}

static chStringA s_strDevName;
static BOOL bMuted = FALSE;
static bool bCancelMuted = false;
bool setSpeakerDevName(const chConstStringA& strDevName)
{
if (strDevName != s_strDevName)
{
s_strDevName = strDevName;
return true;
}
return false;
}

bool cancleSpeakerDevMute()
{
if (s_strDevName.empty())
{
return false;
}
bCancelMuted = true;
UINT iDevID = GetDevIDByName(s_strDevName);
getSystemMuteStatusLaterWindowVistaByDevID(iDevID, bMuted);
setSystemMuteLaterWindowVistaByDevID(iDevID, FALSE);
}

bool returnSpeakerDevMute()
{
if (s_strDevName.empty() || !bCancelMuted)
{
return false;
}
bCancelMuted = false;
UINT iDevID = GetDevIDByName(s_strDevName);
setSystemMuteLaterWindowVistaByDevID(iDevID, bMuted);
}

解除win7系统静音的更多相关文章

  1. win7系统VPN设置

    为了解除公司上网策略限制,或者为了上Google,Facebook,都可以通过设置VPN实现. 要使用VPN需要到VPN服务商注册,链接VPN服务商. ======================== ...

  2. 解除win7网络限速.

    在电脑刚买或者系统重装了的时候,win7系统会默认限制20%的网络速度,限制了我们的上网速度,我们可以解决这个限制,让上网变得更快 下面是操作步骤 1.开始>运行 2.输入以下命令,然后确定 g ...

  3. 最新win7系统64位和32位系统Ghost装机稳定版下载

    系统来自转载:系统妈 一.主要更新:========================== * 更新了系统补丁和Office2007 SP2所有补丁 通过微软漏洞扫描* 更新QQ至7.1  官方正式版* ...

  4. win7系统下python安装numpy,matplotlib,scipy和scikit-learn

    1.安装numpy,matplotlib,scipy和scikit-learn win7系统下直接采用pip或者下载源文件进行安装numpy,matplotlib,scipy时会遇到各种问题,这是因为 ...

  5. win7系统网卡驱动正常,网线连接设备正常,但电脑右下角网络图片显示一直在转圈或者显示一个黄色感叹号的解决办法

    今天遇到一个问题是电脑的win7系统一直都可以连接有线,但今天突然连接不了.在我的电脑右键-->管理--->设备管理器-->网络适配器,里面查看了网络适配器安装正常.但是电脑右下角的 ...

  6. Win8换成Win7系统问题小结(修改主板BIOS方法)

    问题描述: 笔记本电脑W8系统使用不习惯,想要换成W7系统,但不管是用光盘安装亦或是用U盘安装,在设置系统启动项的时候,选择从光盘启动或从U盘启动,但是回车点了之后没反应. 下面就说说问题的原因及解决 ...

  7. win7系统下如何配置php-Apache-mysql环境

    如何在win7系统下配置php环境呢,php+Apache+mysql都是在配置过程中必不可少的元素,php负责解析php代码,apache负责服务器端而mysql是数据交互的中转站. 那么如何将ph ...

  8. 深度技术GHOST WIN7系统32.64位j极速安装版 V2016年

    系统来自系统妈:http://www.xitongma.com 深度技术GHOST win7系统64位j极速安装版 V2016年3月 系统概述 深度技术ghost win7系统64位j极速安装版  版 ...

  9. win7系统中如何使文件显示出扩展名

    win7系统中如何使文件显示出扩展名-------------------- 1.点击计算机-->>点击组织,然后选择"文件夹及搜索选项"-->> ---- ...

随机推荐

  1. Winform中调用js函数

    var wb = new WebBrowser(); wb.AllowNavigation = true; wb.ScriptErrorsSuppressed = false; wb.Navigate ...

  2. windbg

    1, symbols  : srv*c:\symbols*http://msdl.microsoft.com/download/symbols 2,.loadby sos mscorwks  or   ...

  3. jquery选择器之内容选择器

    HTML示例代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  4. 一步步构建自己的AngularJS(2)——scope之$watch及$digest

    在上一节项目初始化中,我们最终得到了一个可以运行的基础代码库,它的基本结构如下: 其中node_modules文件夹存放项目中的第三方依赖模块,src存放我们的项目代码源文件,test存放测试用例文件 ...

  5. Property ClientHeight does not exist 问题解决

    delphi的TFrame继承自另一个TFrame时,最好通过File->New->Other...->Delphi Projects->Inheritable Items 的 ...

  6. 自动 点击切换 按钮切换 轮播无缝选项卡 ----原生js

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  7. JAVA_Java常用核心包(概念)

    20150802 Created By BaoXinjian

  8. OpenGL 学习

    一.红宝书学习资料汇集 第八版的图书源码 源代码: http://opengl-redbook.com/Code/oglpg-8th-edition.zip 第九版的图书源码 http://www.o ...

  9. [家里蹲大学数学杂志]第013期2010年西安偏微分方程暑期班试题---NSE,非线性椭圆,平均曲率流,非线性守恒律,拟微分算子

    Navier-Stokes equations 1 Let $\omega$ be a domain in $\bbR^3$, complement of a compact set $\mathca ...

  10. sharedPreference

    http://blog.csdn.net/yong199105140/article/details/8425247 SharedPreferences 分类: Android2012-12-24 1 ...