大致的效果如上,这个小程序可以更改打字的颜色,通过配置文件读取。
/* 时间: 2019/2/29, 作者: Y.W.R */
// TypeWriting Program -pseudocode(伪代码)
// First it reads the configuration file, and load configuration information
// This includes (ambient color, article path). Then provide a selection of
// articles, Enter typing mode. Finally, collect relevant information.
// 首先读取配置文件,读取配置信息,这包括(环境颜色,文章路径)。
// 然后提供可选择的文章,进入打字模式。最后统计相关信息。
#include <io.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#define MAXLEN 4801 // 最大长度: 4800
#define PAGELEN 960 // 页长度: 80 * 12
#define MAXCOLOR 5 // 颜色总数
#define LINE 40 // 菜单行长度
#define COLS 10 // 菜单列长度
const char Version[] =
{"Copyright by Ms.Y.r version: v0.0.1"};
const char * MATCH_FILE = ".\\default.conf";
const char * ARTICLE = ".\\paper\\";
typedef struct information {
int length;
int n_complete;
float n_correct;
float n_wrong;
} Infor;
typedef struct environment {
WORD BACK_COLOR;
WORD TRUE_COLOR;
WORD FALSE_COLOR;
WORD UNLABLED_COLOR;
WORD TEXT_COLOR;
} Envir;
/** 控制台可配置属性
* #define FOREGROUND_BLUE 1
* #define FOREGROUND_GREEN 2
* #define FOREGROUND_RED 4
* #define FOREGROUND_INTENSITY 8
-----------------------------------
* #define BACKGROUND_BLUE 16
* #define BACKGROUND_GREEN 32
* #define BACKGROUND_RED 64
* #define BACKGROUND_INTENSITY 128
*/
HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
char words[MAXLEN];
char article[COLS][LINE - 2];
int mark = 1;
/* 显示方框 */
void Orthgon();
/* 显示文章 */
void ShowArtice(int n_list, Infor * wString);
/* 获取选择 */
int ChoiceArtice(int n_list);
/* 查找文章 */
int FindFile();
/* 载入颜色配置 */
bool MatchText(Envir * wColor);
/* 载入文章数据 */
bool LoadFile(char * pFile, Infor * wString);
/* 设置光标模式 */
void SetCurInfo(BOOL isVisible);
/* 进入打字模式 */
bool TypeWrite(Envir * wColor, Infor * wString);
/* 显示文章数据 */
void ShowText(int * flags, WORD cColor);
/* 设置屏幕颜色 */
void SetScreen(WORD cColor, COORD coordScreen, DWORD dwConSize);
/* 显示打字数据 */
void ShowWriting(Envir * wColor, Infor * wString);
void ShowVer(COORD cPos);
int main()
{
Infor wString = { 0 };
Envir wColor = { 0 };
SetConsoleTitle("TypeWriting - 无文章");
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdout == INVALID_HANDLE_VALUE ||
hStdin == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "GetStdHandle", "Error", MB_OK);
return 1;
}
COORD coordHome = { 0,0 };
COORD coordSize = { 80,25 };
SetConsoleScreenBufferSize(hStdout, coordSize);
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
return 1;
if(! MatchText(&wColor))
{
MessageBox(NULL, "Read configuration", "Error", MB_OK);
return 1;
}
int select, f_number;
if (! (f_number = FindFile()))
{
MessageBox(NULL, "No File", "Error", MB_OK);
return 1;
}
int choices;
char * pq = NULL;
char szTitle[81] = { 0 };
while (1)
{
SetCurInfo(fa