Playing a Sound File
Adding Sound to your application can be a great way of whiling away a few extra days at the end of a project that's ahead of schedule :)

Adding sound to a PowerBuilder application is as easy as adding an external function declaration. One such function call to play a wave file is:

FUNCTION INT SndPlaySound( &
   '*.wav fn(STRING)', modeofplay(INT)) &
   library "mmsystem.dll"

Under Win32 you will need to use a different set of DLL calls:

Function boolean sndPlaySoundA( &
   string SoundName, uint Flags ) Library "WINMM.DLL"
Function uint waveOutGetNumDevs() Library "WINMM.DLL"

You can play a sound with the following code:

uint lui_NumDevs

lui_NumDevs = WaveOutGetNumDevs()
IF lui_NewDevs > 0 THEN
    sndPlaySound( "filename.wav", modeofplay(INT) )
END IF

where: modeofplay
0 - play synchronously
1 - play asynchronously
2 - don't use default sound if u can't find file
3 - 1&2
8 - loop the sound until next sndPlaysound
10- don't stop any correctly playing sound

Return Values:
0 error(usually file not found)
1 success


This previous method is fine but under Windows NT and Windows 95 you can also play sounds using OLE:

ole_snd.InsertFile("snd.wav")
ole_snd.Activate(InPlace!)
Back