需要MFC支持。
示例代码:
// Sample2.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h”
#include “console.h”
#pragma comment(lib,“console.lib”)
#include <time.h>
#include <Mmsystem.h>
#include <direct.h>
#include <io.h>
int circulation=1;
int interface_num=0;
extern COORD mouse;
void MainInterface(); // 0
void SetQuestion(); // 1
void Answer(); // 2
void HistoryScore(); // 3
char *Date_Time();
void SaveScore(char *,int,int);
char *SelectFile(HWND hwnd);
class PlayMusic
{
private:
TCHAR fileName[MAX_PATH+100];
TCHAR shortName[MAX_PATH];
TCHAR cmd[MAX_PATH+250];
char buf1[260];
public:
int volume; // 范围: 1~1000
PlayMusic(void);
PlayMusic(char mu[]);
~PlayMusic(void);
void OpenEquipment();
void CloseEquipment();
void AssignCurrentMusic(char mu[]);
void Play();
void Stop();
void SetVolume();
void RepeatPlay();
};
PlayMusic::PlayMusic(void)
{
OpenEquipment();
}
PlayMusic::PlayMusic(char mu[])
{
OpenEquipment();
wsprintf(fileName,"%s",mu);
GetShortPathName(fileName,shortName,sizeof(shortName)/sizeof(TCHAR));
}
PlayMusic::~PlayMusic(void)
{
CloseEquipment();
}
void PlayMusic::OpenEquipment()
{
wsprintf(cmd,“open %s”,“waveaudio”);
mciSendString(cmd,buf1,sizeof(buf1),NULL);
}
void PlayMusic::CloseEquipment()
{
wsprintf(cmd,“close %s”,“waveaudio”);
mciSendString(cmd,buf1,sizeof(buf1),NULL);
}
void PlayMusic::AssignCurrentMusic(char mu[])
{
wsprintf(fileName,"%s",mu);
GetShortPathName(fileName,shortName,sizeof(shortName)/sizeof(TCHAR));
}
void PlayMusic::Play()
{
wsprintf(cmd,“play %s”,shortName);
mciSendString(cmd,"",NULL,NULL);
}
void PlayMusic::Stop()
{
wsprintf(cmd,“stop %s”,shortName);
mciSendString(cmd,"",NULL,NULL);
}
void PlayMusic::SetVolume()
{
wsprintf(cmd,“setaudio %s volume to %d”,shortName,volume);
mciSendString(cmd,"",NULL,NULL);
}
void PlayMusic::RepeatPlay()
{
wsprintf(cmd,“play %s repeat”,shortName);
mciSendString(cmd,"",NULL,NULL);
}
int main()
{
Screen screen;
screen.SetTitle(“记单词”);
screen.ShowOrHideCursor(0);
Event event;
event.AddMouseMode();
while(circulation)
{
screen.Clear_screen();
switch(interface_num)
{
case 0:
MainInterface();
break;
case 1:
SetQuestion();
break;
case 2:
Answer();
break;
case 3:
HistoryScore();
break;
}
}
event.RestoreMode();
//screen.Pause();
screen.Close_handle();
return 0;
}
void MainInterface()
{
File file;
file.Getcwd();
if(_access("word.txt",0)==-1)
{
FILE *dhb;
fopen_s(&dhb,"word.txt","a");
fclose(dhb);
}
if(_access("score.txt",0)==-1)
{
FILE *dhb;
fopen_s(&dhb,"score.txt","a");
fclose(dhb);
}
Screen screen;
screen.SetSize(80,25);
Button EXIT_button=Button(50,16,"退出");
EXIT_