Console.Beep() 可以叫一聲
目前成都創(chuàng)新互聯(lián)已為1000多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站托管運(yùn)營、企業(yè)網(wǎng)站設(shè)計(jì)、平江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
控制頻率和時(shí)長什么的就得用api了。
錯?。?!
用API...
'在Form1中。。。
Private Declare Function Beep Lib "kernel32.dll" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
'多給我:zhs490770些分哦
Private sub Form_Load()
msgbox" 下一步你就會聽到聲音,按確定吧 ",VBOKONLY,"給我分哦"
Beep 2000 , 300
'發(fā)出聲音頻率值為2000,長度為300的蜂鳴器聲音
End Sub
蜂鳴器編程的話,有個API函數(shù),VB中的聲明為
Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
調(diào)用方法是Beep 聲音頻率,持續(xù)時(shí)間(毫秒為單位)
比如 beep 2000,1000
如果是聲卡編程的話,也有相應(yīng)的API函數(shù),比如你可以用DirectSound(也就是DirectX的一部分),功能比較強(qiáng)大,也很專業(yè)。事實(shí)上,如果你使用的是專業(yè)級的聲卡和音響設(shè)備,它可以在一定范圍內(nèi)回放出超出人耳聽覺范圍的聲音。當(dāng)然也可以用簡單一點(diǎn)的API,以下是幾個需要的函數(shù):
Private Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long
Private Declare Function midiOutGetNumDevs Lib "winmm" () As Integer
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 Function midiOutGetErrorText Lib "winmm.dll" Alias "midiOutGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
Private Const MAXERRORLENGTH = 128 ' max error text length (including NULL)
Private Const MIDIMAPPER = (-1)
Private Const MIDI_MAPPER = (-1)
'MIDIOUTCAPS結(jié)構(gòu)描述了Musical Instrument Digital Interface(MIDI)輸入設(shè)備的性能
Type MIDIOUTCAPS
wMid As Integer
wPid As Integer ' 產(chǎn)品 ID
vDriverVersion As Long ' 設(shè)備版本
szPname As String * 32 ' 設(shè)備 name
wTechnology As Integer ' 設(shè)備類型
wVoices As Integer
wNotes As Integer
wChannelMask As Integer
dwSupport As Long
End Type
Public Sub note_on(ch As Integer, ByVal kk As Integer, v As Integer)
' 發(fā)音主函數(shù)。參數(shù)分別為通道編號,音調(diào),速度
Call midi_outshort(H90 + ch, kk, v)
End Sub
Sub midi_outshort(b1 As Integer, b2 As Integer, b3 As Integer)
Dim midi_error As Integer
midi_error = midiOutShortMsg(hMidi, b3 * H10000 + b2 * H100 + b1)
If Not midi_error = 0 Then
Call midi_outerr(midi_error)
End If
End Sub
Sub midi_outerr(ByVal midi_error As Integer)
Dim s As String
Dim x As Integer
s = Space(MAXERRORLENGTH)
x = midiOutGetErrorText(midi_error, s, MAXERRORLENGTH)
MsgBox s
End Sub