PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC -
the scope of the language as well as it's specific capabilities.
PowerBASIC has only one function to create a sound, the
function BEEP. There are no built-in function to play
standard sound files (*.wav) nor midi files (*.mid).
There are several Windows API which can be used to play
sounds, including the sndPlaySound and WinBeep API.
Both of these are included in the Win32API.inc that is
distributed with PowerBASIC, so the declaration statements
do not need to be put in the application as long as the
#INCLUDE "Win32API.inc" compiler directive is included.
Here is an example of using the WinBeep API.
DECLARE FUNCTION WinBeep LIB "KERNEL32.DLL" ALIAS "Beep" _
(BYVAL dwFreq AS DWORD, BYVAL dwDuration AS DWORD) AS LONG
WinBeep 1000, 2000 'play 1000Hz sound for two seconds
And here are several sndPlaySound API example.
Declare Function sndPlaySound Lib "winmm.dll"
Alias "sndPlaySoundA" (ByVal lpszSoundName As String,
ByVal uFlags as Long) as Long
Dim iReturn As Long, SoundFile As String
SoundFile = "sound.wav" 'set filename of sound to play
iReturn = sndPlaySound(SoundFile, &H1) 'once, in background
iReturn = sndPlaySound(SoundFile, &H0) 'once, wait until done
iReturn = sndPlaySound(SoundFile, &H8) 'play continuously
iReturn = sndPlaySound(vbNullString, False) 'stop playing sound
Not shown here, the mciSendString API can be used to play
Unlike Visual Basic, PowerBASIC does not come with a built in
control to play sounds. If the use of API, as discussed above,
doesn't satisfy your need, you have two other choices.
- 3rd Party COM Control
Several vendors have created COM controls which can play sounds,
either by providing a VCR-style interface for the user or by allowing
the programmer to supply command strings to control the sounds
generated by the control.
- Control of Installed User Application
If you know a user has an installed sound player, such as the
built-in Windows sound recorder, you can use PowerBASIC to start
the application and play the sound.
Sound Function Reference
Here's a quick reference of the available sound functions, in alphabetical
Note that the default Windows sound can be changed using the
control panel, or by using an API call.
If you have any suggestions or corrections, please let me know.