MIDI播放:
首先在工程头文件中加入:
#include “mmsystem.h”
#pragma comment (lib,”WINMM.LIB”)
然后在程序初始化部分中加入:
UINT wMIDIDeviceID;
MCI_OPEN_PARMS mciOpenParams;
MCI_PLAY_PARMS mciPlayParams;
DWORD dwError;
mciOpenParams.lpstrDeviceType = “sequencer”;
mciOpenParams.lpstrElementName = “main.mid”; //要播放的MIDI
if(dwError=mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_OPEN_TYPE,(DWORD)(LPVOID)&mciOpenParams))
; // 播放
else
wMIDIDeviceID=mciOpenParams.wDeviceID;
if(dwError=mciSendCommand(wMIDIDeviceID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPlayParams))
{
mciSendCommand(wMIDIDeviceID,MCI_CLOSE,0,NULL); //关闭
}
WAVE播放:
首先在工程头文件中加入:
#include “mmsystem.h”
#pragma comment (lib,”WINMM.LIB”)
然后在需要播放的地方加入:
sndPlaySound(“sound_file.name”,SND_ASYNC|SND_LOOP);
SND_ASYNC: 在背景播放
SND_LOOP: 连续播放