让 C++ playSound 运行 与 main 函数同步

Let the C++ playSound run with the main function simultaneously

这是我的代码:

    DemoAMain oMain;
    char buf[1024];
    PlaySound(TEXT("bgm.wav"), NULL, SND_FILENAME);
    sprintf( buf, "My Demonstration Program : Size %d x %d", BASE_SCREEN_WIDTH, BASE_SCREEN_HEIGHT );
    iResult = oMain.Initialise( buf, BASE_SCREEN_WIDTH, BASE_SCREEN_HEIGHT, "Cornerstone Regular.ttf", 24 );
    iResult = oMain.MainLoop();
    oMain.Deinitialise();
    return iResult;

有个问题,只有PlaySound播放完音乐,程序才能继续。我应该怎么做才能让 PlaySound 运行 与以下代码同时进行?非常感谢。

您可以通过将 SND_ASYNC 标志添加到第三个参数来实现,如下所示:

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