How to Invoke MessageBeep API to Play System Alert .WAV SoundsID: Q110103
|
This article describes how to invoke the MessageBeep API function to play
the waveform sound associated with a given Windows system alert level.
This is useful for playing a sound such as when you display a message box
with the MsgBox statement.
The sound for each Windows alert level is identified by an entry in the
[sounds] section of the WIN.INI initialization file. You can use the
Windows Control Panel to change this [sounds] section.
The MessageBeep API function returns control to Visual Basic immediately
after queuing a sound. The Visual Basic program executes subsequent code
while the MessageBeep sound plays asynchronously.
The MessageBeep API function accepts one parameter, which can have one of
the following values:
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.
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 Sub MessageBeep Lib "User" (ByVal wType As Integer)
Default Beep
Exclamation
Windows Start
Windows Exit
Critical Stop
Question
Asterisk
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
Additional query words: 3.00
Keywords : kbcode
Version : 3.00
Platform : WINDOWS
Issue type :
Last Reviewed: June 24, 1999