Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
-
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
-
Error Handling (2)
-
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Tutorial Main Page | Previous Page | Contents | Next Page

More Elaborate Sounds

• Beeps are nice, but many times you want to play more elaborate sounds. Most sounds you hear played in Windows applications are saved in WAV files (files with WAV extensions). These are the files formed when you record using one of the many sound recorder programs available.

• WAV files are easily played using DLL functions. There is more than one way to play such a file. We’ll use the sndPlaySound function. This is a long function that requires two arguments, a string argument with the name of the WAV file and a long argument indicating how to play the sound. The usage syntax is:

Dim WavFile As String, SndType as Long, RtnValue as Long
.
.
.
RtnValue = sndPlaysound(WavFile, SndType)

• SndType has many possible values. We’ll just look at two:

SND_SYNC - Sound is played to completion, then execution continues
SND_ASYNC - Execution continues as sound is played

Quick Example 7 - Playing WAV Files

  1. Start a new application. Add a command button and a common dialog box. Copy and paste the sndPlaySound Declare statement from the API Text Viewer program into your application. Also copy the SND_SYNC and SND_ASYNC constants. When done copying and making necessary scope modifications, you should have:

    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_SYNC = &H0

  2. Add this code to the Command1_Click procedure:

    Private Sub Command1_Click()
    Dim RtnVal As Integer
    'Get name of .wav file to play
    CommonDialog1.Filter = "Sound Files|*.wav"
    CommonDialog1.ShowOpen
    RtnVal = sndPlaySound(CommonDialog1.filename, SND_SYNC)
    End Sub

  3. Run the application. Find a WAV file and listen to the lovely results.


  

Tutorial Main Page | Previous Page | Contents | Next Page

   

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved