是否可以让 vb.net 程序使 PC 的内部扬声器发声?你知道产生 C 的那个 \a
钟
我试过 beep()
,但这只会在声卡上产生错误声音。
我也试过
<Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Beep", SetLastError:=True, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _
Public Shared Function _
aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer) _
As Boolean
End Function
显然,它在 Vista 及更高版本上唯一的好处没有任何乐趣。
有什么建议?
最佳答案
使用 My
VB.NET 中的命名空间,你可以通过 My.Computer.Audio
访问音频.这有一个 Play
具有许多重载的方法,允许您按文件位置或作为字节数组或流传递 .wav 声音,但它也有 PlaySystemSound
采用 enum 的方法,其中之一是 Beep
.所以播放这个声音的完整行是:
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
没有保证,但由于它是 .Net 框架的一部分,我认为这应该适用于 XP 和 Vista ......
关于.net - XP上的vb.net系统提示音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10110911/