如何通知我的应用程序默认声音播放设备已更改?

发布于 2024-11-01 04:20:37 字数 409 浏览 2 评论 0原文

我的 Win XP SP3 计算机上有两个声卡,并且我编写了一个 C++ 应用程序,通过编辑以下注册表项来更改默认播放设备:

regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia\Sound Mapper", true);

我的应用程序更改了“Playback”键值以便使用将第一或第二声卡作为默认播放设备。

问题是当我更改默认设备时,应用程序仍然使用旧设备(程序启动时设置为默认设备)。如果更改后,我再次启动应用程序,一切正常,我可以使用“新”默认播放设备。

我如何“告诉”我的应用程序我已经更改了默认设备?应用程序通过什么方式读取并存储 Windows 中默认声音设备启动时的变量?我的问题有什么解决办法吗?

I have two sound cards on my Win XP SP3 computer, and I've written a C++ app, with which I change the default playback device by editing the following Registry entry:

regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia\Sound Mapper", true);

My app changes the "Playback" key value for the purposes of using the first or second sound card as the default playback device.

The problem is when I change the default device, the application still uses the old one (which was set as the default when the program starts). If after change, I launch the application again, everything works fine and I can use the "new" default playback device.

How can I "tell" for my application that I have changed the default device? By what way does the application read and store the variable on starting up which sound device is default in Windows? Is there any solution for my problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2024-11-08 04:20:37

注册表本质上是一个存储默认设置的数据库。修改注册表中的值不会导致任何应用程序或 Windows 本身使用新的更新值重新初始化其设置。 Raymond Chen 参考用户界面设置讨论了这一问题

还要考虑到类似的事情很可能在更高版本的 Windows 中发生变化。如果您决定更新到 Windows Vista 或 7,您将再次回到这里询问更多问题,因为您的声音切换器应用程序将不再工作。更高版本处理音频设备的方式与 XP 中的处理方式非常不同。首先,它们现在基于核心音频 API

因此,出于显而易见的原因,修改注册表值并不是修改计算机配置的首选方法。

但是,如果您只是想让特定应用程序注意到您已更改注册表中的值,则简单的解决方案是 RegNotifyChangeKeyValue 函数。这本质上是订阅应用程序,以便在每次特定注册表项的值发生更改时接收通知。

此处提供了适用于 Windows Vista 及更高版本的正确解决方案

The Registry is essentially a database that stores the default settings. Modifying the values in the registry does not cause any application, nor Windows itself, to re-initialize its settings with the new, updated values. Raymond Chen discusses this very thing with reference to user interface settings.

Also consider that things like this are very likely to change in later versions of Windows. If you ever decide to update to Windows Vista or 7, you'll be back here again asking more questions because your sound-switcher application won't work anymore. The later versions handle audio devices very differently than they were handled in XP; for starters, they're now based around the Core Audio APIs.

Therefore, for reasons that should be obvious, modifying registry values is not the preferred way to modify your computer's configuration.

But if you're just trying to make a particular application notice that you've changed the value in the registry, the simple solution is the RegNotifyChangeKeyValue function. This essentially subscribes the application to receive notifications each time the value of a particular registry key changes.

The correct solution for Windows Vista and later is available here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文