#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#include <windows.h>
#include <Digitalv.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
void getMusic();
void getLyric();
int main()
{
getLyric();
getMusic();
return 0;
}
void getLyric()
{
FILE *fp;
char ch;
fp = fopen("lyric.txt", "r");
while ((ch = fgetc(fp)) != EOF)
{
fputc(ch, stdout);
}
fclose(fp);
}
void getMusic()
{
char buf[128];
MCI_OPEN_PARMS mciOpen;
MCIERROR mciError;
UINT DeviceID;
MCI_PLAY_PARMS mciPlay;
mciOpen.lpstrDeviceType = L"mpegvideo";
mciOpen.lpstrElementName = L"IF.wma";
mciError = mciSendCommand(0, MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)&mciOpen);
if(mciError)
{
mciGetErrorString(mciError, (LPWSTR)buf, 128);
MessageBox(NULL, TEXT("send MCI_OPEN command failed"), TEXT("ERROR"), 0);
return;
}
DeviceID = mciOpen.wDeviceID;
mciError = mciSendCommand(DeviceID, MCI_PLAY, MCI_WAIT | MCI_DGV_PLAY_REPEAT, (DWORD)&mciPlay);
if(mciError)
{
mciGetErrorString(mciError, (LPWSTR)buf, 128);
MessageBox(NULL, TEXT("send MCI_PLAY command failed"), TEXT("ERROR"), 0);
return;
}
}
VC简单实现播放音乐
最新推荐文章于 2024-03-09 14:57:48 发布