1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h> // link to winmm.lib
#include <iostream>
using namespace std;
void PlayMidiAndWait(const char* path)
{
char cmd[1024] = "";
sprintf(cmd, "play %s wait", path);
mciSendString(cmd, NULL, 0, NULL);
}
void PlayMidi(const char* path)
{
char cmd[1024] = "";
sprintf(cmd, "open %s alias tune", path);
mciSendString(cmd, NULL, 0, NULL);
mciSendString("play tune", NULL, 0, NULL);
}
void StopMidi()
{
const char cmd[] = "stop tune";
mciSendString(cmd, NULL, 0, NULL);
}
int main()
{
const char path[] = "C:\\WINDOWS\\Media\\town.mid";
cout << "Play" << endl;
PlayMidi(path);
Sleep(3000);
cout << "Stop" << endl;
StopMidi();
Sleep(3000);
cout << "Play" << endl;
PlayMidi(path);
Sleep(3000);
cout << "Stop" << endl;
StopMidi();
return 0;
}
|