基于easyx图形库的ATM图形界面

//======================================================
//项目名称:ATM用户界面
//环境:vs2019,easy x图形库
//作者:jack shi
//开始时间:2019.6.3
//完成时间:2019.6.20
//======================================================
//======================================================


#include <graphics.h>
#include <conio.h>//_kbhit()函数(重点:不会清空缓冲区)、getch()函数
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>//sleep()头文件
#include "页面绘制.h"
#define MAX 10//该银行系统能读取用户的最多条数
//==================================================

int c;//用户结构体变量下标
int count = 0;//读入用户条数
extern FILE* fp;
char filename[] = "123.txt"; //文件路径

typedef struct user
{
	char id[20];
	char name[20];//一个汉字为2个字节 
	char password[7];//需用字符串存放密码,若用int,则002022为2022 
	char money[20];
}AC;
AC a[MAX];

//函数声明=========================================
void system_ready(FILE* fp);//读取用户文件
int system();
int login();
int moneyadd();
int moneycut();
int moneytransfer();
int moneysee();
int passwordreset();
int findid(char* id_);//查找id
void update(FILE* fp);//用户文件写入
AC typeChang(char* ch);
void gbiao(int x, int y);//绘制光标
void check(int t,int flog);//判断功能函数执行状态,从而确定下一步操作。

int main()
{
	errno_t fp_p;//接收fopen_返回值
	fp_p= fopen_s(&fp,filename, "r+");
	if (fp_p!=0)
	{
		puts("文件打开失败");
		printf("%d",fp_p);//打印fopen_s返回值
		exit(0);
	}
	system_ready(fp);//系统初始化
	/*-----------------------------------------------------
	for(p=0;p<count;p++)//在控制台打印改变前的用户信息
	{
		printf("%s\n",a[p].id);
		printf("%s\n",a[p].name);
		printf("%s\n",a[p].password);
		printf("%f\n",a[p].money);
	}
	-------------------------------------------------------*/
	if (login() == 1)
		system();
	/*-----------------------------------------------------
	for(p=0;p<count;p++)//在控制台打印改变后的用户信息
	{
		printf("%s\n",a[p].id);
		printf("%s\n",a[p].name);
		printf("%s\n",a[p].password);
		printf("%f\n",a[p].money);
	}
	-------------------------------------------------------*/
	update(fp);//更新用户信息
	fclose(fp);
	closegraph();
	return 0;
}

void check(int t,int function)//1取款、2存款、3转账、4改密码//t接收1代表对应的功能函数执行成功,相反t接收0执行失败.int flog确定是何种功能函数
{
	if (t == 1)
		T(function);
	else
		F(function);
}

void gbiao(int x, int y)
{
	while (!_kbhit())//判断是否有键盘事键,若无,光标闪烁
	{
		setlinecolor(RGB(0, 0, 0));
		setlinestyle(PS_SOLID | PS_ENDCAP_SQUARE, 1);
		//setrop2(R2_XORPEN); //设置异或绘图方式
		line(x, y, x, y + 20);
		Sleep(400);
		setlinecolor(WHITE);
		line(x, y, x, y + 20);
		Sleep(400);
	}
}

int findid(char* id_)
{
	int i;
	for (i = 0; i < count; i++)
	{
		if (strcmp(a[i].id, id_) == 0)
			return i;
	}
	return -1;
}

int passwordreset()
{
	int i, x = 312, y = 165;
	char ch_p;
	char xh[20];
	static char password_s[7], password_1[7], password_2[7];
	RECT r_1 = { 310,160,475,190 };//输入原密码区域
	RECT r_2 = { 310,210,475,240 };//输入新密码区域
	RECT r_3 = { 310,260,475,290 };//再次输入新密码区域
	graph_draw(5);
	i = 0;
	setfillcolor(BLUE);		
	while (i < 6)//密码长度6位
	{
		gbiao(x, y);
		ch_p = _getch();
		if (ch_p >= '0' && ch_p <= '9')//密码的输入只能为数字 
		{
			password_s[i] = ch_p;
			xh[i] = '*';
			password_s[i + 1] = '\0';
			xh[i + 1] = '\0';
			drawtext(xh, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
			i++;
			x = x + 15;
		}
		if (ch_p == 8 && i > 0)//退格
		{
			i--;
			password_s[i] = '\0';//删去一个字符
			xh[i] = '\0';//删去一个*
			clearrectangle(310, 160, 475, 190);
			drawtext(xh, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			x = x - 15;//光标后退14个像素
		}
	}		
	//----------------------------------------------------------------------
	x = 312; y = 215;//移动光标位置到输入新密码处
	i = 0;
	while (i < 6)//密码长度6位
	{
		gbiao(x, y);
		ch_p = _getch();
		if (ch_p >= '0' && ch_p <= '9')//密码的输入只能为数字 
		{
			password_1[i] = ch_p;
			xh[i] = '*';
			password_1[i + 1] = '\0';
			xh[i + 1] = '\0';
			drawtext(xh, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			i++;
			x = x + 15;
		}
		if (ch_p == 8 && i > 0)//退格
		{
			i--;
			password_1[i] = '\0';//删去一个字符
			xh[i] = '\0';//删一个*
			clearrectangle(310, 210, 475, 240);
			drawtext(xh, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			x = x - 15;//光标后退15个像素	
		}
	}
	//-----------------------------------------------------------------
	x = 312; y = 265;//移动光标位置到再次输入新密码处
	i = 0;
	while (i < 6)//密码长度6位
	{
		gbiao(x, y);	
		ch_p = _getch();
		if (ch_p >= '0' && ch_p <= '9')//密码的输入只能为数字 
		{
			password_2[i] = ch_p;
			xh[i] = '*';
			password_2[i + 1] = '\0';
			xh[i + 1] = '\0';
			drawtext(xh, &r_3, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
			i++;
			x = x + 15;
		}
		if (ch_p == 8 && i > 0)//退格
		{
			i--;
			password_1[i] = '\0';//删去一个字符
			xh[i] = '\0';//删一个*
			clearrectangle(310, 260, 475, 290);
			drawtext(xh, &r_3, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			x = x - 15;//光标后退14个像素
		}
	}
	//---------------------------------------------------------------------------------------------------------
	if (strcmp(password_1, password_2) == 0&& strcmp(password_s, a[c].password) == 0)//原密码正确,两次新密码相同
	{
		strcpy_s(a[c].password, password_1);
		return 1;
	}
	else
		return 0;
}

int moneytransfer()
{
	char ch_i;
	int i, x = 312, y = 215;
	int hisc;//他的结构体变量下标
	char hisid[20];
	char money_c[20] = { 1 };
	double money_my, money_his, money_t;
	RECT r_2 = { 310,210,475,240 };//输入转账id区域
	RECT r_3 = { 310,260,475,290 };//输入转账金额区域
	graph_draw(3);
	//---------------------------------------------------------------------
	i = 0;
	while (1)//输入转账id
	{
		gbiao(x, y);
		ch_i = _getch();
		if (ch_i >= '0' && ch_i <= '9')
		{
			hisid[i] = ch_i;
			hisid[i + 1] = '\0';
			drawtext(hisid, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			i++;
			x = x + 15;
		}
		if (ch_i == 8 && i > 0)//退格
		{
			i--;
			hisid[i] = '\0';//删去一个字符
			clearrectangle(310, 210, 450, 240);
			drawtext(hisid, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
			x = x - 15;//光标后退14个像素
		}
		if (ch_i == 13)//回车键ascll值
		{
			hisc = findid(hisid);
			if (hisc == -1)
			{
				i = 0;
				x = 312;//光标回到初始位置
				clearrectangle(310, 210, 475, 240);
			}
			else
				break;
		}
	}
	//----------------------------------------------------------------------------------------
	y = y + 50;//移动光标位置
	x = 312;
	while (1)
	{
		i = 0;
		while (1)//此循环输入转账金额
		{
			gbiao(x, y);
			ch_i = _getch();
			if (ch_i >= '0' && ch_i <= '9')
			{
				money_c[i] = ch_i;
				money_c[i + 1] = '\0';
				drawtext(money_c, &r_3, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				i++;
				x = x + 15;
			}
			if (ch_i == 8 && i > 0)//退格
			{
				i--;
				money_c[i] = '\0';//删去一个字符
				clearrectangle(310, 260, 475, 290);
				drawtext(money_c, &r_3, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				x = x - 15;//光标后退14个像素
			}
			if (ch_i == 13)//回车键ascll值
				break;
		}
		money_t = atof(money_c);
		money_his = atof(a[hisc].money);
		money_my = atof(a[c].money);
		if (money_t > 0 && money_t <= money_my)
		{
			money_his = money_his + money_t;
			money_my = money_my - money_t;
			sprintf_s(a[c].money,sizeof(a[c].money), "%lf", money_my);
			sprintf_s(a[hisc].money,sizeof(a[hisc].money), "%lf", money_his);
			return 1;
		}
		return 0;
		x = 312;//光标回到前面
		clearrectangle(310, 260, 475, 290);
	}
}
//===================================================================
int moneysee()//查询界面
{
	graph_draw(4);
	RECT r_1 = { 310,160,475,190 };//输入name区域
	RECT r_2 = { 310,210,475,240 };//输入id区域
	RECT r_3 = { 310,260,475,290 };//输入money区域
	drawtext(a[c].name, &r_1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	drawtext(a[c].id, &r_2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	drawtext(a[c].money, &r_3, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
	_getch();
	return 0;
}
//===================================================================
int moneyadd()//存款
{
	char money_c[20] = { 1 };
	double money_a, money_my;
	int i, x = 312, y = 215;
	char ch=0;//字符中间变量
	RECT r_1 = { 310,210,475,240 };//输入存款金额区域
	while (1)
	{
		graph_draw(2);//绘制存款界面
		i = 0;
		while (ch!=13)
		{
			gbiao(x, y);
			ch = _getch();
			if (ch >= '0' && ch <= '9')
			{
				money_c[i] = ch;
				money_c[i + 1] = '\0';
				drawtext(money_c, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				i++;
				x = x + 15;
			}
			if (ch == 8 && i > 0)//退格
			{
				i--;
				money_c[i] = '\0';//删去一个字符
				clearrectangle(310, 210, 450, 240);
				drawtext(money_c, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				x = x - 15;//光标后退14个像素
			}
		}
		money_a = atof(money_c);
		money_my = atof(a[c].money);
		if (money_a > 0)
		{
			money_my = money_my + money_a;
			sprintf_s(a[c].money,sizeof(a[c].money), "%lf", money_my);
			return 1;
		}
		return 0;
	}
}
//===================================================================
int moneycut()//取款界面
{
	char money_c[20];
	double money_a, money_my;
	int i, x = 312, y = 215;
	char ch=0;//字符中间变量
	RECT r_1 = { 310,210,475,240 };//输入取款金额区域
	graph_draw(1);
	while (1)
	{
		i = 0;
		while (ch!=13)
		{
			gbiao(x, y);
			ch = _getch();
			if (ch >= '0' && ch <= '9')
			{
				money_c[i] = ch;
				money_c[i + 1] = '\0';
				drawtext(money_c, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				i++;
				x = x + 15;
			}
			if (ch == 8 && i > 0)//退格
			{
				i--;
				money_c[i] = '\0';//删去一个字符
				clearrectangle(310, 210, 450, 240);
				drawtext(money_c, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				x = x - 15;//光标后退14个像素
			}
		}
		
		money_a = atof(money_c);
		money_my = atof(a[c].money);
		if (money_a <= money_my && money_a > 0)
		{
			money_my = money_my - money_a;
			printf("%f\n", money_my);
			sprintf_s(a[c].money,sizeof(a[c].money), "%lf", money_my);
			return 1;
		}
		return 0;
	}
}
//======================================================================
int login()//登陆界面
{
	static char id[20];//static定义,后续无需手动添加\0
	char ch = 0;//输入字符的中间变量
	static char password_s[7];
	static char xh[7];//星号数组
	int t = 0, i = 0, x = 312, y = 215;//t为错误次数,(x,y)为光标位置
	//-------------------------------------------------------------------
	RECT r_1 = { 310,210,450,240 };//输入id区域
	RECT r_2 = { 310,260,450,290 };//输入密码区域
	//-------------------------------------------------------------------
	
	while (t < 3)
	{
		graph_login();//绘制登陆界面
		i = 0;
		while (ch != 13)
		{
			gbiao(x, y);//绘制光标
			ch = _getch();
			if (ch >= '0' && ch <= '9')
			{

				id[i] = ch;
				id[i + 1] = '\0';
				drawtext(id, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				i++;
				x = x + 15;
			}
			if (ch == 8 && i > 0)//退格
			{
				i--;
				id[i] = '\0';//删去一个字符
				clearrectangle(310, 210, 450, 240);
				drawtext(id, &r_1, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				x = x - 15;//光标后退15个像素
			}
		}
		i = 0;
		x = 312, y = 265;
		while (i < 6)//密码长度6位
		{
			gbiao(x, y);//绘制光标
			ch = _getch();
			if (ch >= '0' && ch <= '9')//密码的输入只能为数字 
			{
				x = x + 15;
				password_s[i] = ch;
				xh[i] = '*';
				//password_s[i + 1] = '\0';
				xh[i + 1] = '\0';
				drawtext(xh, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				i++;
			}
			if (ch == 8 && i > 0)//退格
			{
				i--;
				password_s[i] = '\0';//删去一个字符
				xh[i] = '\0';//删去一个*
				clearrectangle(310, 260, 450, 290);
				drawtext(xh, &r_2, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
				x = x - 15;//光标后退15个像素
			}
		}
		//-------------------------------------------------------------------------------
		c = findid(id);
		if (c == -1 || strcmp(password_s, (a[c].password)) != 0)
		{
			t++;
			if (t == 3)
				return 0;
			x = 312; y = 215;//光标位置回到输入账号处
			F(5);//登陆失败提示
		}
		else
			return 1;
	}
}
//=================================================================== 
//读取用户信息 (系统初始化)
//功能:将文件内容读入结构体变量
void system_ready(FILE * fp)
{
	int i = 0;
	char ch[80];
	char* t;
	while (!feof(fp))
	{
		t = fgets(ch, sizeof(ch), fp);
		if (count >= MAX)
		{
			printf("该系统只能读取%d个用户信息\n", MAX);
			break;
		}
		//----------------------------------------------
		if (t != NULL)//将用户信息读入结构体变量 
		{
			a[i] = typeChang(t);
			i++;
			count++;
		}
	}
}
//===================================================================
//功能:将字符串转换成一个结构体变量
//时间:2019.5.13 
AC typeChang(char* ch)//用字符型指针接收字符数组(字符数组首地址) 
{
	AC t;
	char* p;
	char* buf;
	p = strtok_s(ch, ";",&buf);
	sscanf_s(p, "%s", t.id,sizeof(t.id));
	//----------------------------------------------------------------
	p = strtok_s(NULL, ";", &buf);
	sscanf_s(p, "%s", t.name, sizeof(t.name));
	//----------------------------------------------------------------
	p = strtok_s(NULL, ";", &buf);
	sscanf_s(p, "%s", t.password, sizeof(t.password));
	//----------------------------------------------------------------
	p = strtok_s(NULL, ";", &buf);
	sscanf_s(p, "%s", t.money, sizeof(t.money));
	return t;
}
//====================================================================
//功能选择
int system()
{
		int temp=0;//按钮填充颜色,0是未点击时的颜色
		char i;
		MOUSEMSG m;
		while (1)//选择功能
		{

			graph_system(temp);//绘制功能选择界面
			while(MouseHit())//用if不行有bug,详见:https://codeabc.cn/zhaoh/post/handle-mouse-messages-correctly
			{
				m = GetMouseMsg();
				switch (m.uMsg)
				{
				case WM_LBUTTONDOWN:
				{
					if (m.x > 150 && m.x < 300 && m.y>200 && m.y < 250)//点击取款区域
						check(moneycut(), 1);
					if (m.x > 500 && m.x < 650 && m.y>200 && m.y < 250)//点击存款区域
						check(moneyadd(), 2);
					if (m.x > 150 && m.x < 300 && m.y>300 && m.y < 350)//点击转账区域
						check(moneytransfer(), 3);
					if (m.x > 500 && m.x < 650 && m.y>300 && m.y < 350)//点击查询区域
						moneysee();
					if (m.x > 150 && m.x < 300 && m.y>400 && m.y < 450)//点击改密码区域
						check(passwordreset(), 4);
					if (m.x > 500 && m.x < 650 && m.y>400 && m.y < 450)//点击退出区域
						return 0;
				}break;
				case WM_MOUSEMOVE://鼠标点击效果
				{
					if (m.x > 150 && m.x < 300 && m.y>200 && m.y < 250)//移动到取款区域
					{
						temp = 1;
						break;
					}
					if (m.x > 500 && m.x < 650 && m.y>200 && m.y < 250)//移动到存款区域
					{
						temp = 2;
						break;
					}
					if (m.x > 150 && m.x < 300 && m.y>300 && m.y < 350)//移动到转账区域					
					{
						temp = 3;
						break;
					}
					if (m.x > 500 && m.x < 650 && m.y>300 && m.y < 350)//移动到查询区域
					{
						temp = 4;
						break;
					}
					if (m.x > 150 && m.x < 300 && m.y>400 && m.y < 450)//移动到改密码区域区域
					{
						temp = 5;
						break;
					}
					if (m.x > 500 && m.x < 650 && m.y>400 && m.y < 450)//移动到退出区域
					{
						temp = 6;
						break;
					}
					temp = 0;
				}break;
				}
			}	
			if (_kbhit())//_kbhit()在执行时,检测是否有按键按下,有按下返回非0值,没有按下则返回0,是非阻塞函数
			{
				i = _getch();
				if (i >= '1' && i <= '6')
				{
					switch (i)
					{
					case '1':check(moneycut(),1); break;//check函数在此处判断功能函数的执行情况
					case '2':check(moneyadd(),2); break;
					case '3':check(moneytransfer(),3); break;
					case '4':moneysee(); break;
					case '5':check(passwordreset(),4); break;
					case '6':return 0;
					}
				}
				else
				{
					settextstyle(30, 0, "宋体");
					outtextxy(150, 50, "请根据提示选择正确的业务!");
				}
			}
		}
}
//==================================================================
//功能:退出系统功能函数(更新用户信息) 
void update(FILE * fp)
{
	rewind(fp);
	for (c = 0; c < count - 1; c++)
	{
		fprintf(fp, "%s;%s;%s;%s\n", a[c].id, a[c].name, a[c].password, a[c].money);
	}
	fprintf(fp, "%s;%s;%s;%s", a[count - 1].id, a[count - 1].name, a[count - 1].password, a[count - 1].money);
	graph_draw(6);//感谢使用
}
#pragma once
#include <graphics.h>
#include <conio.h>
FILE* fp;
char t;
//====================================================================================================================
//声明
void update(FILE* fp);
void now_t();

//提示界面(业务的成功和失败)
int T(int function);//成功提示
int F(int function);//失败提示
void graph_draw(int function);//int function代表将要绘制的功能界面:1取款,2存款,3转账,4查询,5改密码
void graph_login();//绘制登陆界面

//绘制登陆界面和系统界面
void graph_login()
{
	initgraph(800, 500);
	IMAGE img;
	loadimage(&img,_T("D:\\人影.jpg"), 800, 500);
	putimage(0,0,&img);
	//-----------------------------------
	settextcolor(BLACK);//设置字体颜色
	setbkmode(TRANSPARENT);
	settextstyle(30, 0, "宋体");
	outtextxy(260, 210, "ID:");
	outtextxy(230, 260, "密码:");
	setbkcolor(WHITE);//设置当前背景颜色
	clearrectangle(310, 210, 450, 240);//根据当前背景颜色清空(如setbkcolor(WHITE))
	clearrectangle(310, 260, 450, 290);
}
void graph_system(int temp)
{
	BeginBatchDraw();//开始批量绘图
	IMAGE img;
	loadimage(&img, _T("D:\\城市.jpg"), 800, 500);
	putimage(0, 0, &img);
	//-------------------------------------
	setbkmode(TRANSPARENT);//设置背景模式
	now_t();//当前时间
	settextstyle(40, 0, "宋体");
	outtextxy(250, 50, "欢迎进入国际银行");
	//------------------------------------
	settextcolor(BLACK);
	settextstyle(20, 0, "宋体");
	setfillcolor(RGB(250,250,250));
	if (temp == 1)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(150, 200, 300, 250);
	RECT r_1 = { 150,200,300,250 };
	drawtext("1、取款", &r_1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	//-------------------------------------------------------------------
	setfillcolor(RGB(250, 250, 250));
	if (temp == 2)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(500, 200, 650, 250);
	RECT r_2 = { 500,200,650,250 };
	drawtext("2、存款", &r_2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	//------------------------------------------------------------------
	setfillcolor(RGB(250, 250, 250));
	if (temp == 3)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(150, 300, 300, 350);
	RECT r_3 = { 150,300,300,350 };
	drawtext("3、转账", &r_3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	//-----------------------------------------------------------------
	setfillcolor(RGB(250, 250, 250));
	if (temp == 4)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(500, 300, 650, 350);
	RECT r_4 = { 500,300,650,350 };
	drawtext("4、查询", &r_4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	//-----------------------------------------------------------------
	
	setfillcolor(RGB(250, 250, 250));
	if (temp == 5)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(150, 400, 300, 450);
	RECT r_5 = { 150,400,300,450 };
	drawtext("5、修改密码", &r_5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	//----------------------------------------------------------------
	setfillcolor(RGB(250, 250, 250));
	if (temp == 6)
	{
		setfillcolor(RGB(106, 95, 109));
	}
	solidrectangle(500, 400, 650, 450);
	RECT r_6= { 500,400,650,450 };
	drawtext("6、退出", &r_6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	
	//----------------------------------------------------------------
	//FlushBatchDraw();
	EndBatchDraw();//结束批量绘图
}
//绘制功能界面
void graph_draw(int function)//int function代表将要绘制的功能界面:1取款,2存款,3转账,4查询,5改密码,6退出
{
	IMAGE img;
	loadimage(&img, _T("D:\\风景.jpg"), 800, 500);
	putimage(0, 0, &img);
	//-------------------------------------------------------
	setbkmode(TRANSPARENT);//设置背景模式
	settextstyle(30, 0, "宋体");
	setfillcolor(WHITE);//输入框颜色
	//-------------------------------------------------------
	switch (function)
	{
	case 1:	outtextxy(175, 210, "取款金额:");
			solidrectangle(310, 210, 475, 240); break;
	case 2:	outtextxy(175, 210, "存款金额:");
			solidrectangle(310, 210, 475, 240); break;//用当前背景颜色(white)清空输入金额区域
	case 3:	outtextxy(200, 210, "转账ID:");
			outtextxy(170, 260, "转账余额:"); 
			solidrectangle(310, 260, 475, 290); 
			solidrectangle(310, 210, 475, 240); break;
	case 4:	outtextxy(220, 160, "姓名:");
			outtextxy(230, 210, "I D:");
			outtextxy(220, 260, "余额:");
			solidrectangle(310, 160, 475, 190);
			solidrectangle(310, 210, 475, 240);
			solidrectangle(310, 260, 475, 290); break;
	case 5:	outtextxy(200, 160, "原密码:");
			outtextxy(200, 210, "新密码:");
			outtextxy(80, 260, "再次输入新密码:");
			solidrectangle(310, 160, 475, 190);
			solidrectangle(310, 210, 475, 240);
			solidrectangle(310, 260, 475, 290); break;
	case 6: outtextxy(250, 200, "感谢使用该ATM系统");
			system("pause"); break;
	}
}
//绘制提示界面,并选择下一步操作(返回或退出)
int T(int function)
{
	IMAGE img;
	loadimage(&img, _T("D:\\人影.jpg"), 800, 500);
	putimage(0, 0, &img);
	settextstyle(30, 0, "宋体");
	switch (function)
	{
	case 1:outtextxy(300, 200, "取款成功!"); break;
	case 2:outtextxy(300, 200, "存款成功!"); break;
	case 3:outtextxy(300, 200, "转账成功!"); break;
	case 4:outtextxy(300, 200, "密码修改成功!"); break;
	}
	while (1)
	{
		if (_kbhit() || MouseHit())
		{
			_getch();
			return 0;
		}
	}
}
int F(int function)
{
	//setbkcolor(BLUE);//设置当前填充颜色
	//cleardevice();
	//settextstyle(30, 0, "宋体");
	IMAGE img;
	loadimage(&img, _T("D:\\人影.jpg"), 800, 500);
	putimage(0, 0, &img);
	settextstyle(30, 0, "宋体");
	switch (function)
	{
		case 1:outtextxy(270, 200, "您的余额不足!"); break;
		case 2:outtextxy(240, 200, "存款金额有误,请重新输入!"); break;
		case 3:outtextxy(230, 200, "转账失败!请您仔细核对信息!"); break;
		case 4:outtextxy(240, 200, "密码修改失败!请核对信息!"); break;
		case 5:outtextxy(150, 200, "登陆失败,请检测您的账号和密码!"); break;
	}
	//--------------------------------------
	setbkcolor(WHITE);
	RECT r_4 = { 50,25,150,80 };//返回主菜单区域
	clearrectangle(50, 25, 150, 80);
	drawtext("1.返回", &r_4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	RECT r_5 = { 675,25,775,80 };//退出区域
	clearrectangle(675, 25, 775, 80);
	drawtext("2.退出", &r_5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	MOUSEMSG m;
	while (1)
	{
		if (MouseHit())
		{
		m = GetMouseMsg();
		if (m.uMsg == WM_LBUTTONDOWN)
		{
			if (m.x > 50 && m.x < 150 && m.y>25 && m.y < 80)
			{
				return 0;
			}
				if (m.x > 675 && m.x < 775 && m.y>25 && m.y < 80)
				{
					update(fp);
					exit(0);
				}
			}
		}
		if (_kbhit())//_kbhit()在执行时,检测是否有按键按下,有按下返回非0值,没有按下则返回0,是非阻塞函数
		{
			t = _getch();
			if (t == '1' || t == '2')
			{
				switch (t)
				{
					case '1':return 0;
					case '2':update(fp); exit(0);
				}
			}
		}
	}
}
//绘制当前时间
void now_t()
{
	struct tm t;
	int sec = 60;
	char ch[128];
	time_t nowtime;//time_t -- 时间类型(time.h 定义是typedef long time_t; 追根溯源,time_t是long)
	time(&nowtime);//获取时间,以秒计,从1970年1月一日起算,存于nowtime
	localtime_s(&t, &nowtime);//转为当地时间,存放在t 时间结构
	sprintf_s(ch, sizeof(ch), "%02d:%02d:%02d   %4d.%02d.%02d", t.tm_hour, t.tm_min, t.tm_sec, t.tm_year + 1900, t.tm_mon, t.tm_mday);
	settextstyle(20, 0, "宋体");
	outtextxy(580, 25, ch);
}

运行效果:

  • 15
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值