C# 在 WinCE 中发出哔哔声,这可能吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/476290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
beep in WinCE , it possible ?
提问by Gold
is it possible to make beep in WinCE ?
是否可以在 WinCE 中发出哔哔声?
i try and i get an error
我尝试,但出现错误
采纳答案by JaredPar
The .net framework methods for beeing are not available in the CF version of the framework. The best way to get a beep sound is to PInvoke into the MessageBeep function. The PInvoke signature for this method is pretty straight forward
用于蜜蜂的 .net 框架方法在框架的 CF 版本中不可用。获得提示音的最佳方法是 PInvoke 进入 MessageBeep 函数。此方法的 PInvoke 签名非常简单
[DllImport("CoreDll.dll")]
public static extern void MessageBeep(int code);
public static void MessageBeep() {
MessageBeep(-1); // Default beep code is -1
}
This blog post has an excellent more thorough example: http://blog.digitforge.com/?p=4 (on archive.org)
这篇博文有一个非常好的更彻底的例子:http: //blog.digitforge.com/?p=4(在archive.org上)
回答by ctacke
Yes. P/Invoke PlaySoundor sndPlaySoundor MessageBeep. See thisor thisor this. It's amazing what 30 seconds with a search engine can turn up.
是的。P/调用PlaySound或sndPlaySound或MessageBeep。看到这个或这个或这个。令人惊讶的是,搜索引擎可以显示 30 秒。
回答by zomf
If you're looking to play one of the default system sounds and using .net runtime 2.0+ (and framework v 3.5+), then you can use the System.Media.SystemSoundsclass (no need for PInvoke or WinAPI calls), like so:
如果您想播放默认系统声音之一并使用 .net 运行时 2.0+(和框架 v 3.5+),那么您可以使用System.Media.SystemSounds类(不需要 PInvoke 或 WinAPI 调用),例如所以:
//available system sounds
System.Media.SystemSounds.Asterisk.Play();
System.Media.SystemSounds.Beep.Play();
System.Media.SystemSounds.Exclamation.Play();
System.Media.SystemSounds.Hand.Play();
System.Media.SystemSounds.Question.Play();
Note that the user won't hear anything if they have disabled or muted system sounds.
请注意,如果用户禁用或静音系统声音,他们将听不到任何声音。
However, if you are looking to play an arbitrary tone, then the above answers involving WinAPI or PInvoke are what you need to look at.
但是,如果您想播放任意音调,则需要查看以上涉及 WinAPI 或 PInvoke 的答案。
回答by Justin Emlay
For a simple beep in Compact Framework you don't need all that import nonsense. Besides, depending on the hardware you'll only have access to the default beep anyway. Just use:
对于 Compact Framework 中的一个简单的哔哔声,您不需要所有导入的废话。此外,根据硬件,您无论如何只能访问默认的哔哔声。只需使用:
Microsoft.VisualBasic.Interaction.Beep()