【实例说明】
使用VB中的Beep语句只能发出一种声音。可以使用API函数,发出不同声音。
【编程思路】 VB程序中背景音乐的制作就是调用API函数。
【设计步骤】 1.新建一个标准工程,创建一个新窗体,默认名为Form1。
2.在Form1上添加一个CommandButton控件和一个TextBox控件。
3.源程序 [素材源程序下载]
Option Explicit
'API函数声明
Private Declare Function APIBeep Lib "kernel32" Alias "Beep" _
(ByVal dwFreq As Long, _
ByVal dwDuration As Long) As Long
'PC发出声音
'在Text1中输入不同的数据会发出不同的声音
Private Sub Command1_Click()
Dim i As Long
i = CLng(Text1.Text)
APIBeep i, 500
End Sub
|