/***********************************************************
实现一个登陆界面
1 输出一个登陆界面
2 用户名能够实现邮箱验证,regex库,密码要不可见
3 进度条的模拟实现
4 音乐播放
***************************************************************/
首先对此功能使用到的函数进行简单的介绍。
int system(const char *command) 把 command 指定的命令名称或程序名称传给要被命令处理器执行的主机环境,并在命令完成后返回。使用此函数需要包含头文件:#include
*<1>调整窗口
system函数+dos指令
标题:title 标题名
颜色:color f0
大小:mode con cols = 40 lins =8;//此处可自己定义cols和lins大小
例如:
system("calc");打开计算器“”里面是计算机的命令。
system("pause");//防止闪屏
实现
void setWindosStyle(void)
{
system("title 邮箱验证");
system("color f0");
system("mode con cols=40 lines=8");
}
此处要实现密码不可见,故使用到了_getch()函数,可自行百度。
void setUserNamPass(uin8_t* username, uin8_t* userpassword)
{
cout << "\t用户名:";
cin >> username;
cout << "\t密 码:";
//cin >> userpassword;
// 密码不可见:字符串当做字符处理
// 每次按键输出一个*号就可以,然后把所有按键保存到password里面
char key;
uin32_t i = 0;
while ((key = _getch()) != '\r')
{
if (i < 6)
{
userpassword[i++] = key;
putchar('*');
}
else
{
cout << "密码过长" << endl;
system("pause");
return;
}
}
//字符串结束标记:\0;
userpassword[i] = '\0';
}
此功能是用来判断输入需要构造正则表达式对象,然后调用regex_match()函数来判断输入字符串是否满足要求;使用到C++头文件#include 。
bool checkEmail(uin8_t* username)
{
bool result = false;
//ctb @163 .com.cn
regex object("(\\w+)@(\\w+)(\\.(\\w+))+");
/*1. 字母a-z A-Z 或者下划线或者0-9,正则表达式*/
//+ 多个
result = regex_match(username, object);
return result;
}
此功能使用到了#include
void proc(void)
{
string str("-");
for (uin32_t i = 0; i <= 20; i++)
{
system("cls");
cout << str << endl;
cout << i * 5 << "%" << endl;
str += "-";
Sleep(500);
}
printf("sucess....!\n");
}
此功能使用到 #include(mmsystem.h)头文件里的mciSendString()函数,可百度了解此函数功能。
首先下载一个音乐MPS文件,然后将其拷贝到此过程工程目录下。注意:实现此功能需加载静态包,
void palyMusic(void)
{
mciSendString("open 1.mp3 alias music", 0, 0, 0);
mciSendString("play music repeat", 0, 0, 0);
}
//#pragma once
#ifndef _TEST_H_
#define _TEST_H_
typedef int uin32_t;
typedef char uin8_t;
#include
#include //c++引用中标准,一般是c+原来的文件名字
#include //_getch()
#include //正则表达式
#include
#include
#include
using namespace std;
void setWindosStyle();
void setUserNamPass(uin8_t* username, uin8_t*userpassword);
bool checkEmail(uin8_t* username);
void proc(void);
void palyMusic(void);
#endif // !_TEST_H_
#include "test.h"
uin32_t main(void)
{
//用户名+密码
uin8_t username[20] = "";
uin8_t userpassword[7] = "";
setWindosStyle();
setUserNamPass(username,
userpassword);
if ((checkEmail(username)) == true)
{
if (!(strcmp(username, "[email protected]")&&strcmp(userpassword,"12345")))
{
//弹出进度条
proc();
cout << "music begin!!!" << endl;
//在播放音乐
palyMusic();
}
else
{
cout << "用户名或者密码错误" << endl;
}
}
else
{
printf("inpute email name no standard\n");
}
system("pause");
return 0;
}