C++程序中如何播放背景音乐?

1: Playsound功能不佳

案例代码如下

# include & ltwindows.h & gt

# include & ltstdio.h & gt

#pragma注释(lib," WinMM。Lib”)

void main()

{

PlaySound("c:\\dui12.wav ",NULL,SND _ FILENAME | SND _ ASYNC);

}

2.功能和Playsound功能一样差undplaysound。

# include & ltwindows.h & gt

# include & ltstdio.h & gt

#pragma注释(lib," WinMM。Lib”)

void main()

{

undPlaySound(" c:\ \ du i12 . wav ",NULL,SND _ FILENAME | SND _ ASYNC);

}

3.功能强大,MCI类支持混音。

案例代码如下

# include & ltwindows.h & gt

#include "mmsystem.h"//导入声音头文件。

# pragma comment (lib," winmm . lib ")//导入声音头文件库。

# include & ltstdio.h & gt

void play MP3();

void main()

{

play MP3();

PlaySound("C:\\Normal2.wav ",NULL,SND _ FILENAME | SND _ ASYNC | SND _ LOOP);

系统(“暂停”);

}

void PlayMp3()

{

char buf[128];

char str[128]= { 0 };

int I = 0;

//使用mciSendCommand

MCI _ OPEN _ PARMS mciOpen

MCIERROR mciError

//SetWindowText(NULL," 12345 ");

MCI open . lpstrdevicetype = " mpeg video ";

MCI open . lpstrelementname = " c:\ \ WELCOME。WAV ";

mciError = mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,(DWORD)& amp;MCI open);

if(mciError)

{

mciGetErrorString(mciError,buf,128);

printf("发送MCI_OPEN命令失败:%s\n ",buf);

返回;

}

UINT device id = MCI open . wdeviceid;

MCI _ PLAY _ PARMS mciPlay

MCI error = mciSendCommand(device id,MCI_PLAY,0,(DWORD)& amp;MCI play);

if(mciError)

{

printf("发送MCI_PLAY命令失败\ n ");

返回;

}

}

4.功能垃圾的方法是启动电脑的一个播放软件播放音乐。

# include & ltiostream & gt

# include & ltfstream & gt

使用命名空间std

int main()

{

System("D:\\我的音乐\ \ 01 . MP3 ");

CIN . get();

返回0;

}

5:更强大的DX

我不想介绍这个。太多了,就不打代码了。我好累啊!网上有解释