In VC + + program design, you can use a variety of standard resources, such as bitmaps, menus, dialog boxes and so on. At the same time, VC + + also allows users to customize resources, so we can use the sound file as a user-defined resource to add to the program resource file, compile the connection to generate EXE file, achieve none. WAV file for sound playback.
The specific steps are as follows:
1. Add in Dlg.h
#include <windows.h>
#include <mmsystem.h>//Plus, otherwise the PlaySound function cannot be used
#pragma comment (lib, "winmm.") LIB ")//Plus, otherwise the PlaySound function cannot be used
2. Load resources. wav files
Open Explorer, right-click. rc, load resources, import. wav file (if not shown, you can change the file type to. wav, the file can be displayed, and select Open)
3. Add button
Double-click the button generation function
4. In the generated function
PlaySound (Makeintresource (idr_wave1), AfxGetResourceHandle (),
snd_async| snd_resource| Snd_nodefault);//Single Play
PlaySound (Makeintresource (idr_wave1), AfxGetResourceHandle (),
snd_async| snd_resource| Snd_nodefault| Snd_loop);/loop Playback
Description: There are many ways to play sound, one is enough, for me. What's the problem? Welcome to discuss it together.