广州linux

当前位置:   网站首页 >> 未命名

圣诞节发一段用电脑主板蜂鸣器发声的vb源码(不需要音响耳机)

 电脑开机会嘀的一声,那是电脑主板上的蜂鸣器发出的,于是百度了音乐中1 2 3 4 5 6 7 i 的频率,又搜索了圣诞节的一首铃声的曲谱,转换成频率发声,于是有了下面代码,运行之后电脑主板蜂鸣器会发出声音,不用外置音响也能听到

Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
Dim music As String
Dim c, c2 As Integer
Private Sub Form_Load()
music = "333 333 35123 444 4433 3332232 5 333 333 35123 444 4433 3355421 53215 5553216 64327 55423 53215 5553216 6432555 565421 5 333 333 35123 444 4433 3332232 5 333 333 35123 444 4433 3355671"
c = Len(music)
c2 = 1
End Sub

Function playsnd(ByVal x As String, y As Long)
Select Case x
Case ""
Beep 0, y
Case 11
Beep 1040, y
Case 1
Beep 520, y
Case 2
Beep 585, y
Case 3
Beep 650, y
Case 4
Beep 693, y
Case 5
Beep 780, y
Case 6
Beep 867, y
Case 7
Beep 975, y
End Select
DoEvents
End Function

Private Sub Timer1_Timer()
If c2 < c Then
bf = Mid(music, c2, 1)
c2 = c2 + 1
playsnd bf, 200
DoEvents
End If
End Sub

发表我的评论

Hi,您需要填写昵称和邮箱!

  • 必填项