MFC根据进程名独立的进行音量控制——仅限于windows vista之后的版本
来源:互联网 发布:淘宝美工笨的人难学吗 编辑:程序博客网 时间:2024/05/20 18:20
{
HRESULT hr = S_OK;
IMMDevice* pDevice = NULL;
IMMDeviceEnumerator* pEnumerator = NULL;
IAudioSessionControl* pSessionControl = NULL;
IAudioSessionControl2* pSessionControl2 = NULL;
IAudioSessionManager* pSessionManager = NULL;
IAudioSessionManager2* pSessionManager2 = NULL;
IAudioSessionEnumerator* pSessionEnumerator = NULL;
AudioSessionState mAudiosessionState;
ISimpleAudioVolume* pSimpleAudioVolume = NULL;
int counts = 0;
WCHAR name2[512];
DWORD puid;
GUID pGuid;
float fVol;
wchar_t ProcessNamef[MAX_PATH] = L"unknown";
hr = CoInitialize(NULL);
// Create the device enumerator.
hr = CoCreateInstance(
__uuidof(MMDeviceEnumerator),
NULL, CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator),
(void**)&pEnumerator);
// Get the default audio device.
hr = pEnumerator->GetDefaultAudioEndpoint(
eRender, eConsole, &pDevice);
// Get the audio client.
hr = pDevice->Activate(
__uuidof(IAudioSessionManager), CLSCTX_ALL,
NULL, (void**)&pSessionManager);
hr = pDevice->Activate(
__uuidof(IAudioSessionManager2), CLSCTX_ALL,
NULL, (void**)&pSessionManager2);
hr = pSessionManager2->GetSessionEnumerator(&pSessionEnumerator);
pSessionEnumerator->GetCount(&counts);
for (int i = 0; i < counts; i++)
{
pSessionEnumerator->GetSession(i, &pSessionControl);
hr = pSessionControl->QueryInterface(
__uuidof(IAudioSessionControl2), (void**)&pSessionControl2);
// Check whether this is a system sound.
hr = pSessionControl2->IsSystemSoundsSession();
if (hr)
{
hr = pSessionControl2->SetDuckingPreference(TRUE);
pSessionControl2->GetState(&mAudiosessionState);
if (mAudiosessionState == AudioSessionStateActive)
{
pSessionControl2->GetProcessId(&puid);
hr = pSessionControl->QueryInterface(
__uuidof(ISimpleAudioVolume), (void**)&pSimpleAudioVolume);
//pSimpleAudioVolume->GetMasterVolume(&fVol);
fVol = C_G_Balance / 100;
//index_Lync_updata();
// pSimpleAudioVolume->SetMasterVolume(0.1, &pGuid);
// PidToProcessName(puid, ProcessNamef);
bool findCPN = 0;
for (int j = 0; j < ChatProcessName_count; j++)
{
if (puid == AudioPID_Name_List[index_Lync[j]].puid)
{
pSimpleAudioVolume->SetMasterVolume(fVol, &pGuid);
findCPN = 1;
break;
}
}
if (findCPN == 0)
{
pSimpleAudioVolume->SetMasterVolume((1 - fVol), &pGuid);
}
//printf("puid=%d vol=%f\r\n", puid,fVol);
}
}
}
if (num_for_out)
pSimpleAudioVolume->Release();
pSessionEnumerator->Release();
pSessionControl2->Release();
pSessionControl->Release();
pSessionManager2->Release();
pSessionManager->Release();
pEnumerator->Release();
pDevice->Release();
return hr;
HRESULT hr = S_OK;
IMMDevice* pDevice = NULL;
IMMDeviceEnumerator* pEnumerator = NULL;
IAudioSessionControl* pSessionControl = NULL;
IAudioSessionControl2* pSessionControl2 = NULL;
IAudioSessionManager* pSessionManager = NULL;
IAudioSessionManager2* pSessionManager2 = NULL;
IAudioSessionEnumerator* pSessionEnumerator = NULL;
AudioSessionState mAudiosessionState;
ISimpleAudioVolume* pSimpleAudioVolume = NULL;
int counts = 0;
WCHAR name2[512];
DWORD puid;
GUID pGuid;
float fVol;
wchar_t ProcessNamef[MAX_PATH] = L"unknown";
hr = CoInitialize(NULL);
// Create the device enumerator.
hr = CoCreateInstance(
__uuidof(MMDeviceEnumerator),
NULL, CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator),
(void**)&pEnumerator);
// Get the default audio device.
hr = pEnumerator->GetDefaultAudioEndpoint(
eRender, eConsole, &pDevice);
// Get the audio client.
hr = pDevice->Activate(
__uuidof(IAudioSessionManager), CLSCTX_ALL,
NULL, (void**)&pSessionManager);
hr = pDevice->Activate(
__uuidof(IAudioSessionManager2), CLSCTX_ALL,
NULL, (void**)&pSessionManager2);
hr = pSessionManager2->GetSessionEnumerator(&pSessionEnumerator);
pSessionEnumerator->GetCount(&counts);
for (int i = 0; i < counts; i++)
{
pSessionEnumerator->GetSession(i, &pSessionControl);
hr = pSessionControl->QueryInterface(
__uuidof(IAudioSessionControl2), (void**)&pSessionControl2);
// Check whether this is a system sound.
hr = pSessionControl2->IsSystemSoundsSession();
if (hr)
{
hr = pSessionControl2->SetDuckingPreference(TRUE);
pSessionControl2->GetState(&mAudiosessionState);
if (mAudiosessionState == AudioSessionStateActive)
{
pSessionControl2->GetProcessId(&puid);
hr = pSessionControl->QueryInterface(
__uuidof(ISimpleAudioVolume), (void**)&pSimpleAudioVolume);
//pSimpleAudioVolume->GetMasterVolume(&fVol);
fVol = C_G_Balance / 100;
//index_Lync_updata();
// pSimpleAudioVolume->SetMasterVolume(0.1, &pGuid);
// PidToProcessName(puid, ProcessNamef);
bool findCPN = 0;
for (int j = 0; j < ChatProcessName_count; j++)
{
if (puid == AudioPID_Name_List[index_Lync[j]].puid)
{
pSimpleAudioVolume->SetMasterVolume(fVol, &pGuid);
findCPN = 1;
break;
}
}
if (findCPN == 0)
{
pSimpleAudioVolume->SetMasterVolume((1 - fVol), &pGuid);
}
//printf("puid=%d vol=%f\r\n", puid,fVol);
}
}
}
if (num_for_out)
pSimpleAudioVolume->Release();
pSessionEnumerator->Release();
pSessionControl2->Release();
pSessionControl->Release();
pSessionManager2->Release();
pSessionManager->Release();
pEnumerator->Release();
pDevice->Release();
return hr;
}
直接上代码,注意pSimpleAudioVolume的获取是关节点
0 0
- MFC根据进程名独立的进行音量控制——仅限于windows vista之后的版本
- mfc根据进程名删除后台运行的可执行文件
- delphi根据不同图片生成不规则窗口的实现(仅限于BMP格式)
- 早期教育的内容绝不仅限于智育
- 仅限于文件系统的 SWF 文件和仅限于网络的 SWF 文件不能彼此加载
- Windows 下 根据进程名获取进程ID 以及该进程下所有窗口的句柄
- [翻译]VISTA音量控制
- VISTA音量控制
- 【MFC】根据进程名结束进程学习
- jdk6的新东东--java DB--仅限于知道即可.
- 自己整理的java泛型(仅限于自己使用)
- android studio 常见问题(仅限于鄙人遇到的)
- 提示仅限于文件系统的 SWF 文件和仅限于网络的 SWF 文件不能彼此加载?的解决办法
- 根据应用的包名杀死进程
- 根据Handle获取进程名的方法
- 控制音量的大小
- 最简单的windows程序——MFC版本
- Linux上根据进程名kill掉指定的进程
- 基于XMPP协议的聊天 详解
- 那些被遗漏的Objective-C保留字
- Xcode统计代码量
- WEB前端开发工程师的随记–黑妞HAHA
- 判断两个对象是否相等的js函数
- MFC根据进程名独立的进行音量控制——仅限于windows vista之后的版本
- 关于android Master 和 Stream 静音
- 淘宝如何跨域获取Cookie分析
- SVM学习—Improvements to Platt’s SMO Algorithm
- 《精通Linux设备驱动程序开发》——内核
- 有道云笔记--500篇笔记纪念
- poj 3233 Matrix Power Series(矩阵二分,快速幂)
- LeetCode 102 N-Queens
- Android ScrollViewy与HorizontalScrollView实现上下左右滚动