可以使用midi音色模拟,但效果没有beep好。
新建一工程,在窗口里放一个command控件,拷贝如下代码,可以从耳机里听到一个长声,两个短声的莫斯电码。
Private Declare Function MIDIOutOpen Lib "winmm.dll" Alias "midiOutOpen" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim sLen As Integer
'定义一个短电码时长,则长声为其3倍
Dim jLen As Integer
'定义码间间隔时长
Private Sub MosCode(Code As Integer)
Dim hMidi As Long, t As Long
Dim midi_err As Integer
midi_err = MIDIOutOpen(hMidi, -1, 0, 0, 0)
t = sLen
If Code = 1 Then t = 3 * sLen
If Not midi_error = 0 Then Exit Sub
midiOutShortMsg hMidi, 65 * &H100 + &HC0
'更换midi音色,65是次中音萨克斯,最接近电报声
midiOutShortMsg hMidi, &H90 + 80 * &H100 + 100 * &H10000 + 0
Sleep t
midiOutClose hMidi
Sleep jLen
End Sub
Private Sub Command1_Click()
sLen = 200: jLen = 10
MosCode 1
MosCode 0
MosCode 0
End Sub