为每个 Windows 警报级别声音的 WIN.INI 初始化文件 [声音] 部分中的项由标识。您可以使用 Windows 控制面板,若要更改此 [声音] 部分。
MessageBeep API 函数排队声音后立即将控制权返回给 vba。异步播放 MessageBeep 声音时,Visual Basic 程序执行后面的代码。
MessageBeep API 函数接受一个参数可以具有下列值之一:
Parameter Value Meaning
---------------------------------------------------------------------------
-1 Produces a standard beep sound by using the computer
speaker.
MB_ICONASTERISK Plays the sound identified by the SystemAsterisk
entry in the [sounds] section of WIN.INI.
MB_ICONEXCLAMATION Plays the sound identified by the SystemExclamation
entry in the [sounds] section of WIN.INI.
MB_ICONHAND Plays the sound identified by the SystemHand
entry in the [sounds] section of WIN.INI.
MB_ICONQUESTION Plays the sound identified by the SystemQuestion
entry in the [sounds] section of WIN.INI.
MB_OK Plays the sound identified by the SystemDefault
entry in the [sounds] section of WIN.INI.
示例: 如何调用 MessageBeep API 函数
- 在 Visual Basic 中开始新项目。默认情况下创建 Form1。
- 双击 Form1。将以下内容添加到窗体加载事件代码:
Sub Form_Load ()
Const MB_ICONQUESTION = 32 ' Warning query. See CONSTANTS.TXT.
Const MB_ICONEXCLAMATION = 48 ' Warning message.
Const MB_YESNO = 4 ' Yes and No buttons
MessageBeep MB_ICONEXCLAMATION ' Plays waveform sound.
MsgBox "Wow!", MB_ICONEXCLAMATION ' Displays message box.
MessageBeep MB_ICONQUESTION
MsgBox "Yes or No?", MB_ICONQUESTION + MB_YESNO
End
End Sub
NOTE: The MB_ICONQUESTION and MB_ICONEXCLAMATION values are the same for
both the MessageBeep API function and the MsgBox statement. See the
"Parameters for MsgBox Statement" section below.
- 从对象菜单中选择 (常规)。将以下 Declare 添加到常规声明节:
Declare Sub MessageBeep Lib "User" (ByVal wType As Integer)
- 启动程序,或按 F5 键。MessageBeep 播放相应声音波形文件为每个消息框显示。
不被标准 Windows 声音事件
Windows 3.1 版允许您将波形音频声音指派给某些事件通过控制面板。这些事件是:
默认蜂鸣
感叹号
Windows 开始
Windows 退出
关键停止
问题
星号
取决于应用程序在发生系统声音。若要一个发声应用程序需要通知 Windows 要发生,然后让 Windows 的系统声音的播放的声音。应用程序将指定的七个默认系统声音的一项或它已添加到此列表中的任何声音事件。
这意味着您不能将声音的事件添加到默认的列表并具有播放发音的应用程序,除非应用程序专门编写调用该声音的事件。
此外,windows 的应用程序具有不标准化时应发生这些声音的事件。因此,一个应用程序可能会默认蜂鸣时播放声音时另一个应用程序可能播放紧急停止声音,就会出错。
MsgBox 语句的参数
Const MB_ICONSTOP = 16 ' Critical message; displays STOP icon.
Const MB_ICONQUESTION = 32 ' Warning query; displays ? icon.
Const MB_ICONEXCLAMATION = 48 ' Warning message; displays ! icon.
Const MB_ICONINFORMATION = 64 ' Information message; displays i icon.
Const MB_OK = 0 ' OK button only
Const MB_OKCANCEL = 1 ' OK and Cancel buttons
Const MB_ABORTRETRYIGNORE = 2 ' Abort, Retry, and Ignore buttons
Const MB_YESNOCANCEL = 3 ' Yes, No, and Cancel buttons
Const MB_YESNO = 4 ' Yes and No buttons
Const MB_RETRYCANCEL = 5 ' Retry and Cancel buttons
Const MB_APPLMODAL = 0 ' Application Modal Message Box
Const MB_DEFBUTTON1 = 0 ' First button is default
Const MB_DEFBUTTON2 = 256 ' Second button is default
Const MB_DEFBUTTON3 = 512 ' Third button is default
Const MB_SYSTEMMODAL = 4096 'System Modal
上述参数为 MsgBox 的语句还可以在任何下列源中找到:
- Visual Basic 的帮助菜单,为 MsgBox 的语句的搜索。
- CONSTANTS.TXT 文件中。
- 页面 384 387 的"语言参考。