How to Use the vbprogram to play WAV files

Source: Internet
Author: User

Wednesday, September 24 2003 PM when an event is completed, the program sends a specific signal to add the user interface features of the program, such as when the download is completed or a command is selected. Using a multimedia function and using a vbprogram to run WAV files is a breeze. However, the system must install a sound card for this operation.
The API function you need is called PlaySound. The following is the declaration of this function:
Public Declare Function PlaySound Lib "winmm. dll "_
Alias "PlaySoundA" (ByVallpszName As String ,_
ByValhModule As Long, ByValdwFlags As Long )_
As Long
In this function, the first variable is the name, including the path of the running Wave file. The second variable is usually not used when running the file, so you can assign it to zero. The last variable contains a tag that controls how a function works.
For the current needs, two tags are required. They are:
SND_ASYNC (value = 1): runs in asynchronous mode, which means that the function is running when the sound is played.
SND_FILENAME (value = & H20000): The first variable is a file name.
The following code marks the sound in the dingdong.wav file:
PlaySound "dingdong.wav", CLng (0 ),_
SND_ASYNC Or SND_FILENAME
When running audio files in a program, there are two other points worth noting. First, you must ensure that a specific audio file exists. Otherwise, an error may occur. This process can be completed using a simple function:
Public Function FileExists (FullFileName) As Boolean
'Passed a filename (with path) returns
'True if the file exists, False if not.
Dim s
S = dir (FullFileName)
   
If s = "" Then
FileExists = False
Else
FileExists = True
End If
End Function
Second, the program must provide users with the option to turn off the sound. This process can be achieved by using a global Boolean variable such as gProgramSoundsEnabled.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.