# Re: 如何利用 wav 档播放声音 (好像 ICQ 的 Message 功能一样)

Posted by 战豪 on July 20, 1999 at 00:57:32:

In Reply to: 如何利用 wav 档播放声音 (好像 ICQ 的 Message 功能一样) posted by 南昌 on July 17, 1999 at 19:25:17:

: 如何利用 wav 档播放声音

: type.wav (打字机声音)
: 包括一个 Rich Text Box 或 Text Box
: 当发生 keypress 时，如何 load type.wav 使它产生打字机声音
: ※ 好像 ICQ 的 Message 功能一样，当用 Message 时，一路都可以听到打字机声音一样。

手头上有个做好的小程式刚刚合你之要求,不过要用到API.希望有点帮助!

于公用模组:
Public Const SND_ASYNC = &H1&
Public Const SND_LOOP = &H8&
Public Const SND_MEMORY = &H4&
Public Const SND_NODEFAULT = &H2&
Public Const SND_NOSTOP = &H10&
Public Const SND_SYNC = &H0&

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

于表单的元件之上:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim x As String, y As String, z As String

x = App.Path & "\Sound\MsgBell.wav"
y = App.Path & "\Sound\MsgBack.wav"
z = App.Path & "\Sound\MsgType.wav"

Select Case KeyCode
Case vbKeyReturn, vbKeySeparator, vbKeySpace, vbKeyTab
sndPlaySound x, SND_ASYNC
Case vbKeyDelete, vbKeyBack
sndPlaySound y, SND_ASYNC
Case vbKeyControl, vbKeyShift, vbKeyMenu, vbKeyCapital
'no sound
Case Else
sndPlaySound z, SND_ASYNC
End Select
End Sub

至于应用在其它元件,你老兄便要动点脑筋.... :-P

Follow Ups: