MFC click button to make sound _playsound_ loop/Single Play _ Sound file join program

Source: Internet
Author: User

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 + + allows users to customize resources, so we can use the sound file as a user-defined resource into the program resource file, compiled connection generated EXE file, achieve none. WAV file for sound playback.

The steps are as follows:

1. Add in the 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 the resource. wav file

Open Explorer, right-click RC, Load resources, import. wav files

3. Add a button

Double-click the button generation function

4. In the generated function

PlaySound (Makeintresource (idr_wave1), AfxGetResourceHandle (), snd_async| snd_resource| Snd_nodefault);//one-time playback

PlaySound (Makeintresource (idr_wave1), AfxGetResourceHandle (), snd_async| snd_resource| Snd_nodefault| Snd_loop);//Loop play


Description: There are many ways to play sound, one is enough for me. What's the problem welcome to explore together.

MFC click button to make sound _playsound_ loop/Single Play _ Sound file join program

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.