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

编程入门 行业动态 更新时间:2024-10-10 23:18:57
本文介绍了如何通知我的应用程序默认声音播放设备已更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

如何为我的应用程序告诉"我已更改了默认设备?应用程序在启动Windows时默认使用哪种声音设备时通过哪种方式读取和存储变量?我的问题有什么解决办法吗?

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?

推荐答案

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

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.

还要考虑到类似的事情很可能在更高版本的Windows中发生变化.如果您决定更新到Windows Vista或Windows 7,您将再次回到这里询问更多问题,因为您的声音切换器应用程序将无法再使用.更高版本的音频设备与XP中的音频设备完全不同.对于初学者来说,它们现在基于核心音频API .

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.

但是,如果您只是想让某个特定的应用程序注意到已更改了注册表中的值,则简单的解决方案是 RegNotifyChangeKeyValue函数.基本上,每次特定注册表项的值更改时,这都会订阅该应用程序以接收通知.

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.

适用于Windows Vista和更高版本的正确解决方案是在此处可用.

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

更多推荐

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

本文发布于:2023-11-12 13:24:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   声音   通知   设备

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!