GET主音量在Windows XP / VISTA / 7例(一个通过键盘车轮增加正常) [英] GET Master volume in Windows XP/Vista/Seven (the one increased through keyboard wheel normally)

查看:213
本文介绍了GET主音量在Windows XP / VISTA / 7例(一个通过键盘车轮增加正常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多人问过这一点,但我没看过任何回答,是否有任何的lib /为GET(未​​设置,我并不需要它)主音量(当前的音量一个通用的方法对于声音输出的来源,而不是语音),它同时适用于XP / VISTA /七来着?

I know a lot of people asked this but I didn't read any answer, are there any lib/a generic way to GET (not set, I don't need it) the master volume (the volume of the current source of output for sounds, not voice) which works for both xp/vista/seven ?

如果不行,怎么办呢为XP,VISTA,七(我会写我的通用包装)

If not, how to do it for xp, vista, seven (I'll write my generic wrapper)

我需要出示巴(进度条)来说明如何设置当前音量(WinForm控件)

I need to show a bar (progress bar) to show how is set the current volume (winform control)

编辑:

我发现了一个有益的联系,我测试它,但我不会检查答案',我拿东西的作品
http://www.$c$cproject.com/KB/audio-video/mixerSetControlDetails.aspx?display=Print

I found a useful link, I'm testing it but I won't check the answer 'till I get something that works http://www.codeproject.com/KB/audio-video/mixerSetControlDetails.aspx?display=Print

编辑2:

这是重要的事情:在previous的方法来分析量将不会在Windows Vista上工作或更高版本,使用LIB来代替:
HTTP://www.$c$cproject.com/KB/vista/CoreAudio的.aspx

An important thing: the previous way to analyze volume won't work on windows vista or later, use this lib instead: http://www.codeproject.com/KB/vista/CoreAudio.aspx

我不知道是否真的有用,因为我没有VISTA /七大分时刻

I don't know if really works well because I don't have vista/seven at the moment

推荐答案

确实的 mixerGetNumDevs 和相关的API帮助? (你必须去通过所有与 mixerGetLineControls 的设备等,看看哪些 MIXERC​​ONTROL 说:卷为名;还有一个方法来检查该标志这就是你要找的人)

Does mixerGetNumDevs and the related API help? (You have to go through all the devices with mixerGetLineControls, etc. and see which MIXERCONTROL says "Volume" for the name; there's also a way to check the flag. That's the one you're looking for.)

编辑:

下面是一些老的code我有一个片段;我不认为它编译,并且它不是很大code(我只是需要得到的东西做的),但它应该是有帮助的:

Here's a snippet of some old code I had; I don't think it compiles, and it's not great code (I just needed to get stuff done), but it should be helpful:

MMRESULT mmResult = mixerOpen(&hMixer, 0, (DWORD_PTR)hWnd, NULL, CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
if (MMSYSERR_NOERROR == mmResult)
{
    MIXERLINE mxl;
    mxl.cbStruct = sizeof(MIXERLINE);
    mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
    MMRESULT mmResult = mixerGetLineInfo((HMIXEROBJ)hMixer, &mxl, MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);
    if (mmResult == MMSYSERR_NOERROR)
    {
        MIXERLINECONTROLS controls;
        memzero(&controls, sizeof(controls));
        controls.cbStruct = sizeof(controls);
        controls.cControls = 1;
        controls.dwLineID = mxl.dwLineID;
        controls.cbmxctrl = sizeof(MIXERCONTROL); //one element only!!
        MIXERCONTROL controlsArray[2]; //First element: volume, second element: mixer
        memzero(&controlsArray, sizeof(controlsArray));
        for (int i = 0; i < sizeof(controlsArray) / sizeof(*controlsArray); i++) { controlsArray[0].cbStruct = sizeof(controlsArray[0]); }

        controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
        controls.pamxctrl = &controlsArray[0]; //NOTE: this is ZERO
        mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
        if (mmResult == MMSYSERR_NOERROR)
        {
            controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
            controls.pamxctrl = &controlsArray[1]; //NOTE: this is ONE
            mmResult = mixerGetLineControls((HMIXEROBJ)hMixer, &controls, MIXER_GETLINECONTROLSF_ONEBYTYPE | MIXER_OBJECTF_HMIXER);
            if (mmResult == MMSYSERR_NOERROR)
            {
                bool isVolume = controls[0].dwControlID == (DWORD)lParam;
                bool isMute = controls[1].dwControlID == (DWORD)lParam;
                if (isVolume | isMute)
                {
                    MIXERCONTROLDETAILS details;
                    memzero(&details, sizeof(details));
                    details.cbStruct = sizeof(details);
                    details.cChannels = 1;
                    details.dwControlID = (DWORD)lParam;
                    MIXERCONTROLDETAILS_UNSIGNED controlDetail;
                    memzero(&controlDetail, sizeof(controlDetail));
                    details.paDetails = &controlDetail;
                    details.cbDetails = sizeof(controlDetail);
                    MMRESULT mmResult = mixerGetControlDetails((HMIXEROBJ)hMixer, &details, MIXER_GETCONTROLDETAILSF_VALUE | MIXER_OBJECTF_HMIXER);
                    if (mmResult == MMSYSERR_NOERROR)
                    {
                    }
                }
            }
        }
    }
}

这篇关于GET主音量在Windows XP / VISTA / 7例(一个通过键盘车轮增加正常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆