vb.net蜂鸣器,c语言蜂鸣器-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

vb.net蜂鸣器,c语言蜂鸣器

让电脑蜂鸣器响

Console.Beep() 可以叫一声

目前成都创新互联已为1000多家的企业提供了网站建设、域名、网页空间、网站托管运营、企业网站设计、平江网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

控制频率和时长什么的就得用api了。

用VB让计算机发出蜂鸣声

错!!!

用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

'发出声音频率值为2000,长度为300的蜂鸣器声音

End Sub

vb.net的一个问题

蜂鸣器编程的话,有个API函数,VB中的声明为

Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

调用方法是Beep 声音频率,持续时间(毫秒为单位)

比如 beep 2000,1000

如果是声卡编程的话,也有相应的API函数,比如你可以用DirectSound(也就是DirectX的一部分),功能比较强大,也很专业。事实上,如果你使用的是专业级的声卡和音响设备,它可以在一定范围内回放出超出人耳听觉范围的声音。当然也可以用简单一点的API,以下是几个需要的函数:

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结构描述了Musical Instrument Digital Interface(MIDI)输入设备的性能

Type MIDIOUTCAPS

wMid As Integer

wPid As Integer ' 产品 ID

vDriverVersion As Long ' 设备版本

szPname As String * 32 ' 设备 name

wTechnology As Integer ' 设备类型

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)

' 发音主函数。参数分别为通道编号,音调,速度

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


文章题目:vb.net蜂鸣器,c语言蜂鸣器
新闻来源:http://kswsj.cn/article/dsgshgh.html

其他资讯