标题:有谁熟悉playsound的帮下忙
只看楼主
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
结帖率:100%
已结贴  问题点数:20 回复次数:3 
有谁熟悉playsound的帮下忙
出现的问题是:
在menu1()函数中正常播放音乐,在按键后音乐关闭然后切换到menu2()后,不在播放下一个音乐
#include<Windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
void menu1()
{  
    IMAGE img_bk,img_1,img_2;
    static int speed=0;
   
    loadimage(&img_bk,_T(".\\beats\\201038580_1.jpg"));
    loadimage(&img_1,_T(".\\beats\\b1.bmp"));
    loadimage(&img_2,_T(".\\beats\\b1_mask.bmp"));
   
    putimage(0,0,&img_bk);
    PlaySound (TEXT (".\\Blu - MitiS.wav"), NULL,SND_FILENAME| SND_ASYNC|SND_LOOP) ;
    BeginBatchDraw();

    while(1)
    {      
        if(speed<=3000)
            speed++;
        if(speed==1)
            putimage(0,0,&img_bk);
        if(speed==1500)
        {  
            putimage(210, 430, &img_2,SRCAND);        
            putimage(210, 430, &img_1,SRCINVERT);
        
        }   
        if(speed==3000)
            speed=0;

        FlushBatchDraw();
        
        if(kbhit())
        {
            PlaySound(0,0,SND_FILENAME);
                break;
        }
    }
    EndBatchDraw();
}
void menu2()
{    int op=0;
    IMAGE img_1,img_2;
    TCHAR s1[] =_T("Play");
    TCHAR s2[]=_T("Write");
    TCHAR s3[]=_T("Options");
    TCHAR s4[]=_T("Exit");
   
    settextcolor(WHITE);
    settextstyle(16, 0, _T("黑体"));
    MOUSEMSG m;

    PlaySound (TEXT (".\\Fly - Ludovico Einaudi.wav"), NULL,SND_FILENAME| SND_ASYNC|SND_LOOP) ;
    loadimage(&img_1,_T(".\\beats\\2-1.jpg"));
    loadimage(&img_2,_T(".\\beats\\options.jpg"));
    putimage(0,0,&img_1);
    FlushBatchDraw();

    while(1)
    {
        m = GetMouseMsg();
        
        if((m.x>49&&m.x<89)&&(m.y>339&&m.y<409)&&op==0)
        {
            outtextxy(55,409,s1);
            setlight();
            FlushBatchDraw(48,339,92,430);
            if(m.uMsg==WM_LBUTTONDOWN)
            {   
                flag_m=1;
                PlaySound(0,0,SND_FILENAME);
                break;      
            }
        }
        
        else if((m.x>146&&m.x<198)&&(m.y>344&&m.y<399)&&op==0)
        {
            outtextxy(152,410,s2);
            setlight();
            FlushBatchDraw(146,344,199,429);
            if(m.uMsg==WM_LBUTTONDOWN)
            {
                flag_m = 2;
                PlaySound(0,0,SND_FILENAME);
                break;
            }
        }
        
        else if((m.x>482&&m.x<532)&&(m.y>349&&m.y<413)&&op==0)
        {  
            outtextxy(480,410,s3);
            setlight();
            FlushBatchDraw(480,349,534,433);
            if(m.uMsg==WM_LBUTTONDOWN)
             {
                 putimage(100,20,&img_2);
                 op=1;
             }
        }
        
        else if((m.x>573&&m.x<623)&&(m.y>358&&m.y<408)&&op==0)
        {
            outtextxy(580,413,s4);
            setlight();
            FlushBatchDraw(573,358,623,429);
            if(m.uMsg==WM_LBUTTONDOWN)
                break;
        }
        
        else if(op==1)
        {   
            if((m.x>500&&m.x<530)&&(m.y>29&&m.y<56))         
                if(m.uMsg==WM_LBUTTONDOWN)
                {
                    putimage(0,0,&img_1);
                    op=0;
                }   
        }
        
        else
        {
            putimage(0,0,&img_1);
            FlushBatchDraw();
        }
    }
    EndBatchDraw();
}
int main()
{
   int scene=0;
  if(scene==0)
   {menu1();}
  if(scene==1)
  {
    menu2();
   }
return 0;
}
搜索更多相关主题的帖子: break int 音乐 playsound jpg 
2021-09-04 16:29
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:20 
int main()
{
   int scene=0;
  if(scene==0)
   {menu1();}
  if(scene==1)
  {
    menu2();
   }
return 0;
}

看不懂,什么时候 scene 会等于 1 ?
2021-09-04 21:49
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
得分:0 

我把整个工程文件上传了,你下载帮我看下
2021-09-05 13:56
C00000001
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2021-5-8
得分:0 
已解决
2021-09-05 15:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506752-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074295 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved