简体   繁体   English

如何使用混音器api控制Windows 7中的主混音器音量?

[英]How to control master mixer volume in windows 7 using mixer api?

In windows XP, it is quite easy to control master volume of a mixer device by setting volume of destination line using mixer api.It can be easily tested by sdk sample application provided by Microsoft.But in case of windows 7 whenever I open a mixer device in my application it shows it as new volume application and I am able to control only volume of my application.Not able to control complete sound of system.Can anyone suggest me how to control complete sound of speaker which will affect sound of all running application. 在Windows XP中,通过使用混音器api设置目标线的音量来控制混音器设备的主音量非常容易。可以通过Microsoft提供的sdk示例应用程序轻松测试。但是在Windows 7的情况下,每当我打开调音台时我的应用程序中的设备显示为新的卷应用程序,我只能控制我的应用程序的音量。无法控制系统的完整声音。任何人都可以建议我如何控制扬声器的完整声音,这将影响所有运行的声音应用。

在此输入图像描述

How can I change speakers volume using my application in windows 7 ? 如何在Windows 7中使用我的应用程序更改扬声器音量?

I believe that the method you're looking for is SetMasterVolumeLevelScalar . 我相信您正在寻找的方法是SetMasterVolumeLevelScalar

A short example in C (sorry for the lpVtbl s): C中的一个简短示例(抱歉lpVtbl ):

BOOL AddMasterVolumeLevelScalar(float fMasterVolumeAdd)
{
    IMMDeviceEnumerator *deviceEnumerator = NULL;
    IMMDevice *defaultDevice = NULL;
    IAudioEndpointVolume *endpointVolume = NULL;
    HRESULT hr;
    float fMasterVolume;
    BOOL bSuccess = FALSE;

    hr = CoCreateInstance(&XIID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &XIID_IMMDeviceEnumerator, (LPVOID *)&deviceEnumerator);
    if(SUCCEEDED(hr))
    {
        hr = deviceEnumerator->lpVtbl->GetDefaultAudioEndpoint(deviceEnumerator, eRender, eConsole, &defaultDevice);
        if(SUCCEEDED(hr))
        {
            hr = defaultDevice->lpVtbl->Activate(defaultDevice, &XIID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
            if(SUCCEEDED(hr))
            {
                if(SUCCEEDED(endpointVolume->lpVtbl->GetMasterVolumeLevelScalar(endpointVolume, &fMasterVolume)))
                {
                    fMasterVolume += fMasterVolumeAdd;

                    if(fMasterVolume < 0.0)
                        fMasterVolume = 0.0;
                    else if(fMasterVolume > 1.0)
                        fMasterVolume = 1.0;

                    if(SUCCEEDED(endpointVolume->lpVtbl->SetMasterVolumeLevelScalar(endpointVolume, fMasterVolume, NULL)))
                        bSuccess = TRUE;
                }

                endpointVolume->lpVtbl->Release(endpointVolume);
            }

            defaultDevice->lpVtbl->Release(defaultDevice);
        }

        deviceEnumerator->lpVtbl->Release(deviceEnumerator);
    }

    return bSuccess;
}

In case the GUIDs are not defined: 如果未定义GUID:

const static GUID XIID_IMMDeviceEnumerator = { 0xA95664D2, 0x9614, 0x4F35, { 0xA7, 0x46, 0xDE, 0x8D, 0xB6, 0x36, 0x17, 0xE6 } };
const static GUID XIID_MMDeviceEnumerator = { 0xBCDE0395, 0xE52F, 0x467C, { 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E } };
const static GUID XIID_IAudioEndpointVolume = { 0x5CDF2C82, 0x841E, 0x4546, { 0x97, 0x22, 0x0C, 0xF7, 0x40, 0x78, 0x22, 0x9A } };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM