Windows7下,用程序改变系统默认的播放设备?

江南烟雨梦 2011-04-07 11:52:29
Windows7下,用程序改变系统默认的播放设备,找了很久,很难找到这方面的资料,MSDN上说引用程序不允许改变默认的播放或者录音设备,不知道大家有什么好的办法?谢谢!
...全文
868 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
XIANXIEJIAN 2011-08-11
  • 打赏
  • 举报
回复
http://blog.csdn.net/xianxiejian/article/details/6669434
我这边的代码应该能解决你的问题
江南烟雨梦 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hideforever 的回复:]

引用 2 楼 jackson35296 的回复:
[/Quote]

这些接口我试过很多次,里面没有这样的函数,MSDN上面也描述这些接口实现不了这个功能,上面说应用程序不允许改变默认的播放或者录音设备.
hideforever 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jackson35296 的回复:]
vista和win7下是用MMDevice Api,DeviceTopology Api和WASAPI来管理声音的。
你可以在MSDN里查一下这三类api,我认为可能能解决问题的接口有以下几个
IMMDevice
IMMDeviceCollection
IMMDeviceEnumerator
IAudioSessionControl
IAudioSessionManager
IAud……
[/Quote]
一点建议:
用IMMDevice
IMMDeviceCollection
IMMDeviceEnumerator
这三个接口,可以枚举出播放下面的声卡设备(render),
找到你要设置的设备,你再看看有没有接口可以设置成默认的
jackson35296 2011-04-07
  • 打赏
  • 举报
回复
Enumerating Audio Devices
The first task of a client audio application is to find a suitable audio device to use. The MMDevice API lets clients discover the audio endpoint devices in the system and determine the suitability of the devices for use by the application. This API enables clients to retrieve collections of the available endpoint devices and get the capabilities of each device. Header file Mmdeviceapi.h defines the interfaces in the MMDevice API.

An audio adapter might contain several devices—for example, a wave-rendering device and a wave-capture device. These are adapter devices rather than endpoint devices. As mentioned previously, these devices are registered by the Plug and Play manager, in contrast with endpoint devices, which are registered by the endpoint manager. Each adapter device typically supports one or more endpoint devices. A rendering endpoint device (for example, headphones) can receive a stream of audio data from a client application, and a capture endpoint device (for example, a microphone) can send an audio stream to a client application.

Before enumerating the endpoint devices in the system, the client must first call the Windows CoCreateInstance function to create a device enumerator. A device enumerator is an object with an IMMDeviceEnumerator interface. For information about CoCreateInstance, see the Windows SDK documentation.

The client calls the IMMDeviceEnumerator::EnumAudioEndpoints method to create a collection of endpoint objects. Each endpoint object represents an audio endpoint device in the system. In this call, the client specifies whether the collection should contain all of the rendering devices in the system, all of the capture devices, or both.

A device collection is an object with an IMMDeviceCollection interface. Each item in a device collection is an endpoint object with at least the following two interfaces:

An IMMDevice interface. A client obtains a reference to the IMMDevice interface of an endpoint object in a device collection by calling the IMMDeviceCollection::Item method.
An IMMEndpoint interface. A client obtains a reference to the IMMEndpoint interface of an endpoint object by calling the IMMDevice::QueryInterface method.
After retrieving a collection of endpoint devices, the client can query the properties of the individual devices in the collection to determine their suitability for use. For more information, see Device Properties.

After selecting a suitable device, the client can call the IMMDevice::Activate method to activate the device-specific interfaces in WASAPI, the DeviceTopology API, and the EndpointVolume API.
jackson35296 2011-04-07
  • 打赏
  • 举报
回复
vista和win7下是用MMDevice Api,DeviceTopology Api和WASAPI来管理声音的。
你可以在MSDN里查一下这三类api,我认为可能能解决问题的接口有以下几个
IMMDevice
IMMDeviceCollection
IMMDeviceEnumerator
IAudioSessionControl
IAudioSessionManager
IAudioAutoGainControl
IAudioChannelConfig
IDeviceTopology
江南烟雨梦 2011-04-07
  • 打赏
  • 举报
回复
每次提问都没人来,晕...
江南烟雨梦 2011-04-07
  • 打赏
  • 举报
回复
还有大牛不?
江南烟雨梦 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hideforever 的回复:]

发送这个消息应该可以,你试试DRVM_MAPPER_PREFERRED_SET
[/Quote]
这个是Windows CE下的消息...
hideforever 2011-04-07
  • 打赏
  • 举报
回复
发送这个消息应该可以,你试试DRVM_MAPPER_PREFERRED_SET
hideforever 2011-04-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 beyond0824 的回复:]
这些接口我试过很多次,里面没有这样的函数,MSDN上面也描述这些接口实现不了这个功能,上面说应用程序不允许改变默认的播放或者录音设备.
[/Quote]

设置默认的声卡设备应该是可以的(以前在XP遇到过,WIN7应该也可以)
再给个思路:
使用wave系列的接口:
1.用waveOutGetNumDevs()得到所有的设备数;
2.在设备数的循环里,用waveOutGetDevCaps得到每个设备的名字
如果是你想要设置的那个名字,记录下它的device id;
3.用waveOutMessage给这个device id发消息,将它设置成默认的(或者当前切换到它)

16,472

社区成员

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

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

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