MFC click the button to emit sound _playsound_ cycle/Single Play _ Sound file accession Program

Source: Internet
Author: User
Tags emit

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.

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.