问题
is it possible to make beep in WinCE ?
i try and i get an error
回答1:
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
[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)
回答2:
Yes. P/Invoke PlaySound or sndPlaySound or MessageBeep. See this or this or this. It's amazing what 30 seconds with a search engine can turn up.
回答3:
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.SystemSounds class (no need for PInvoke or WinAPI calls), like so:
//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.
回答4:
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:
Microsoft.VisualBasic.Interaction.Beep()
来源:https://stackoverflow.com/questions/476290/beep-in-wince-it-possible