C ++控制台应用程序中的PlaySound? [英] PlaySound in C++ Console application?

查看:97
本文介绍了C ++控制台应用程序中的PlaySound?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过修改,使代码正确无误(感谢ta.speot.is)-底部的新问题

EDITED SO THE CODE IS CORRECT (THANKS TO ta.speot.is) - NEW QUESTION AT BOTTOM

因此,我一直在使用该控制台,因此我们被要求制作第一个项目"进行评估.我已经完成了基本的应用程序..但想让它变得更加扎实,并添加一些声音.从控制台播放的声音.

So I have been playing with the console as I am at that level, ad we have been asked to make our first "project" for a assessment. I have the basic application all done.. but wanted to jaz it up a bit and add some sounds. Sounds that play form the console.

此测试有效.(有点),因为它将播放声音文件..但是我有2个问题... 1当声音播放时,应用程序冻结,直到声音100%完成...也尝试编译为发行版"时,将显示错误,并带有链接错误"-致命错误LNK1120:1未解决的外部问题.

This test works.. (kinda) as it will play a sound file.. but I have 2 problems... 1 when the sound plays the application freezes untill the sound is 100% finished... also when I try to compile as a "release" it errors with a "linking error" - fatal error LNK1120: 1 unresolved externals.

#include <iostream>
#include <windows.h>
#include <mmsystem.h>
using namespace std;

int main(){
    //PlaySound(TEXT("mywavsound.wav"), NULL, SND_FILENAME); - My erroring code
    PlaySound(TEXT("mywavsound.wav"), NULL, SND_FILENAME | SND_ASYNC);// - the correct code

    int test = 0;
    cin>>test;
    return 0;
}

所以我的问题是...

So my questions are...

  1. 如何在不冻结控制台的情况下播放声音,所以我可以 在整个项目过程中播放循环音乐文件的示例 打开.如果我还能在上面播放其他声音,那也很棒 它..所以当您按回车时,例如,它会播放没有声音的声音 停止音乐.
  2. 如何添加wav文件,以便将其作为发行版进行编译?
  1. How can I play sounds with out freezing the console, so I could for example play looping music file for the entire time the project was open. Also it would be great if I could play other sounds on top of it.. so when you press enter for example it plays a sound with out stopping the music.
  2. How do I add the wav file so it compiles as a release?

编辑

我知道SND_ASYNC的内容,但我不知道如何使用它,我无法缝制使用它而没有编译过的内容..是否有人有使用SND_ASYNC的代码示例?

I know about the SND_ASYNC thing but I do not know how to use it, I can not seam to use it with out the thing not compiling.. dose anyone have an example of the code using SND_ASYNC?

编辑2

所以我现在正在工作....使用

So I have this working now.... using the

"PlaySound(TEXT("mysound.wav"), NULL, SND_FILENAME | SND_ASYNC);"

现在,我想知道如何一次播放1个或多个声音,因为如果我用该标志调用playsound两次,它将停止第一个声音并播放第二个声音.一次有2个声音?

Now I am wondering how I can get 1 or more sounds to play at once, for if I call playsound twice with that flag it will stop the 1st one and play the 2econd.. Is there a way to play 2 sounds at once?

推荐答案

如何在不冻结控制台的情况下播放声音

How can I play sounds with out freezing the console

如果您使用Google搜索PlaySound 这是第一个结果:

If you Google for PlaySound this is the first result:

fdwSound

...

fdwSound

...

SND_ASYNC声音异步播放,并且PlaySound在开始播放声音后立即返回.要终止异步播放的波形声音,请在pszSound设置为NULL的情况下调用PlaySound.

SND_ASYNC The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL.

您应该熟悉搜索引擎及其功能.

You should familiarise yourself with search engines and what they are capable of.

我如何添加wav文件,以便将其编译为发行版?

How do I add the wav file so it compiles as a release?

您需要在Release和Debug配置中都链接winmm.lib.或者,添加

You need to link winmm.lib in both Release and Debug configurations. Alternatively, add

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

位于源代码的顶部.

这篇关于C ++控制台应用程序中的PlaySound?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆