C++控制台界面库_实例3: 记单词

这个博客介绍了如何使用C++和MFC库来创建一个控制台应用程序,专注于记单词功能。文章包含示例代码,涉及文件操作、音乐播放以及界面交互。主要函数包括MainInterface、SetQuestion、Answer和HistoryScore,用于实现不同阶段的界面和交互逻辑。
摘要由CSDN通过智能技术生成

需要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_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值