How to make a sound exe c+



  • He wrote a walk that reproduces the sound when she presses the keyboards, but that she's working on the music files with her. How do you add the sound directly in the exe?


  • QA Engineer

    Create a resource file..rc) and inside, define all the sounds you use.

    Example: I want to reproduce the sound from the file. back.wav I added the file. sound.rc (name arbitrary) and edited it in a text editor backsound WAVE back.wav (right is the current name of the sound file, on the left, how you're gonna point it in the project)

    In the end, my project looks like:

    введите сюда описание изображения

    Where? back.wav - Melo.
    asd.rc - a file containing the line backsound WAVE back.wav
    Source.cpp - Code itself:

    #include <stdio.h>
    #include <conio.h>
    #include <windows.h>
    #include <mmsystem.h>
    

    #pragma comment (lib , "winmm.lib")

    int main(void)
    {
    printf("Playback in progress.\nPress any key to exit...");
    PlaySoundA((LPCSTR)"backsound", NULL, SND_RESOURCE | SND_ASYNC);
    getchar();
    return 0;
    }

    After all, the sound is reproduced in the collection and launch of the performing file.

    I'm not denying that my method is probably costyle, because I've been doing this for the first time, and I've studied everything I've found as soon as possible, but it's functioning and hopefully helpful.
    The Saitas I used to study: https://www.cyberforum.ru/cpp-beginners/thread2787049.html ♪ https://docs.microsoft.com/ru-ru/cpp/windows/resource-files-visual-studio?view=msvc-160 ♪ https://docs.microsoft.com/en-us/previous-versions/dd743680(v=vs.85) ♪ https://stackoverflow.com/questions/1565439/how-to-playsound-in-c-using-windows-api ♪ https://docs.microsoft.com/ru-ru/cpp/windows/resource-files-visual-studio?view=msvc-160



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2