其他分享
首页 > 其他分享> > 【GUI】【easyX】实现C语言课程设计可视化

【GUI】【easyX】实现C语言课程设计可视化

作者:互联网

为了整点花里胡哨,我容易吗
不够花?上啊兄弟一起干

控制台界面太硬核,一般人接受不了。

想让会用Windows的都能用

这次接到的活(课程设计)是KTV曲库信息查询系统。

在easyX官网下载扩展库(创建文件时后缀写成cpp)

有点意思

为了实现C语言可视化
我上网冲浪,浪花里翻出来一个EasyX(easy?)
不过毕竟是第一次,还不太熟练。

窗口设计

借鉴了win11设置的UI风格,我搞了一个1024X768的窗口
左右两个圆角矩形划分菜单栏和功能栏。

然后左上角加入一个圆打破横平竖直的平衡,实现视觉重心的偏置,从而提升观感
(胡扯)
这是启动页面

一些效果

一共设计了四种大小的字体
微软雅黑 细 中 粗三种粗细 高度20-27不等
对于按钮希望实现一个鼠标悬浮和点击时显示不一样颜色的效果


(对,是关闭按钮的红色)
点名表扬QQ,ctrl+alt+A可取色,懒人(我)狂喜

截至写稿时(2022-1-1)功能开发还没完全完成,后台数据操作交给队友了
(他们三天一定能学完结构体排序(确信)(逃))
关于本程序有不少隐私,就不截图了

贴上代码

函数的意思参照easyX官网随库的技术文档(好评)
也可以在VS中转到定义查看。
之后会更新

你知道我这几天是怎么过的吗?
绷不住就完事了
毕竟是第一次,通过函数实现模块化还是不太熟练
直接大块块无特效按钮和搞出来效果差的代码量是真TM大
我甚至写崩了好几次
还有
如果能跑起来,就跑吧,在BUG上运行也好(绷不住了)
永远,永远不要试图重构代码(!!!!!)

#include<stdio.h>
#include<graphics.h>

#define textsml settextstyle(20, 0, "微软雅黑", 0, 0, 400, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0)
#define textmid settextstyle(23, 0, "微软雅黑", 0, 0, 600, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0)
#define textlrg settextstyle(27, 0, "微软雅黑", 0, 0, 600, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0)
#define textElrg settextstyle(35, 0, "微软雅黑", 0, 0, 700, 0, 0, 0, 0, 0, 0, ANTIALIASED_QUALITY, 0)

#define Checkpos checkpos(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, msg.x, msg.y)

struct buttonbox {
	int lx, ly, rx, ry;
	int ava=false;
}butt[1000];

struct MusicInfo {
	char Title[100], Album[100], Author[50];
	int AlbumNum, LibNum;
};

char menu[6][20] = { "曲目查询","曲目浏览","曲目操作","使用指南","关于本程序" };
int step = 45, ButtNum, ClickFlag = -1;

void home();
void Click(int num);

int checkpos(int lx, int ly, int rx, int ry, int nowx, int nowy) {
	if (nowx >= lx && nowy >= ly && nowx <= rx && nowy <= ry)
		return true;
	else return false;
}

void SetButton(int lx, int ly, int rx, int ry, int num,int r,int g,int b) {
	
	textmid;
	setfillcolor(RGB(r,g,b));
	solidroundrect(lx, ly, rx, ry, 15, 15);
	setbkmode(TRANSPARENT);
	
	int ty = (ly + ly + (ry-ly) - textheight(menu[num])) / 2;
	outtextxy(lx+10, ty, menu[num]);

	return;
}

/*
void ButtonOperationClick(int lx, int ly, int rx, int ry, int i, ExMessage msg) {
	int tmp = true;
	//button-click-effect
	setfillcolor(RGB(47, 41, 41));
	solidroundrect(310, 15, 1014, 750, 15, 15);
	//check lb status
	while(1) {
		if (!msg.lbutton) {
			Click(i);
			break;
		}
		peekmessage(&msg, EM_MOUSE);
	}
	return;
}
*/

void ButtonOperationGen2() {
	//initialize data
	ExMessage msg;
	int OperationFlag = 0;
	int lx, ly, rx, ry;
	//go
	while (1) {
		//check which button is the mouse on
		for (int i = 0; i <= ButtNum; i++) {

			if (butt[i].ava == false) continue;
			lx = butt[i].lx, ly = butt[i].ly, rx = butt[i].rx, ry = butt[i].ry;

			//get check-messages
			peekmessage(&msg, EM_MOUSE);
			OperationFlag = Checkpos;

			//check hover on button_i
			if (OperationFlag) {

				//button-hover-effect
				SetButton(lx, ly, rx, ry, i, 50, 50, 50);

				//check hover on button_i
				do {
					//check click
					if (msg.lbutton) {
						SetButton(lx, ly, rx, ry, i, 196, 43, 28);
						//ButtonOperationClick(lx, ly, rx, ry, i, msg);
						//button-click-effect
						setfillcolor(RGB(43, 43, 45));
						solidroundrect(310, 15, 1014, 750, 15, 15);
						//check lb status
						while (1) {
							if (!msg.lbutton) {
								Click(i);
								break;
							}
							peekmessage(&msg, EM_MOUSE);
						}
						break;
					}
					//renew check-messages
					peekmessage(&msg, EM_MOUSE);
					OperationFlag = Checkpos;
				} while (OperationFlag);
				
				//button-default-effect
				SetButton(lx, ly, rx, ry, i, 43, 43, 45);
			}
		}
	}
		
}


int main() {
	home();
	return 0;
}

void home() {
	
	initgraph(1024,768,EW_NOMINIMIZE);
	
	setbkcolor(RGB(36, 30, 30));
	cleardevice();
	
	setfillcolor(RGB(43, 43, 45));
	solidroundrect(10, 15, 300, 750, 20, 20);
	solidroundrect(310, 15, 1014, 750, 20, 20);
	
	//account 10,25,370,125
	setfillcolor(RGB(149, 229, 149));
	solidcircle(66, 66, 36);//startx = 30

	setbkmode(TRANSPARENT);
	textlrg;
	outtextxy(120, 45, "曲库后台");
	textsml;
	outtextxy(120, 70, "Admin@outlook.com");
	
	Click(3);
	//menu-function classify 
	textmid;
	for (ButtNum = 0; ButtNum <= 4; ButtNum++) {

		butt[ButtNum].ava = true;

		butt[ButtNum].lx = 30;
		butt[ButtNum].ly = 130 + step * ButtNum;
		butt[ButtNum].rx = butt[ButtNum].lx + 250;
		butt[ButtNum].ry = butt[ButtNum].ly + 40;

		SetButton(butt[ButtNum].lx, butt[ButtNum].ly, butt[ButtNum].rx, butt[ButtNum].ry, ButtNum, 43, 43, 45);

	}
	//button operation
	ButtonOperationGen2();

	return;
}

void Click(int num) {
	switch (num)
	{
	case 0: {
		textElrg;
		outtextxy(360, 60, menu[num]);
		return;
	}
	case 1: {
		textElrg;
		outtextxy(360, 60, menu[num]);
		return;
	}
	case 2: {
		textElrg;
		outtextxy(360, 60, menu[num]);
		return;
	}
	case 3: {
		int txts = 130;
		textElrg;
		outtextxy(360, 60, menu[num]);
		textmid;
		outtextxy(400, txts, "本程序使用鼠标和键盘操作");
		outtextxy(400, txts += 65, "使用鼠标点击左侧菜单栏中的对应按钮,可进入功能界面");
		outtextxy(400, txts += 35, "在功能界面使用鼠标点击需要的功能按钮");
		outtextxy(400, txts += 35, "根据提示点击按钮或者在对话框中输入需要的信息");
		outtextxy(400, txts += 65, "信息录入结束后点击   -更新信息文件-   即可更新信息并支持查询");
		outtextxy(400, txts += 65, "对于硬件配置较差或运行环境不完备的用户");
		outtextxy(400, txts += 35, "我们提供了控制台操作界面的版本");
		outtextxy(400, txts += 65, "祝愿您使用愉快");
		return;
	}
	case 4: {
		int txts = 130;
		textElrg;
		outtextxy(360, 60, menu[num]);
		textmid;
		outtextxy(400, txts, "此程序是2021级C语言课程设计展示用程序");
		outtextxy(400, txts += 55, "制作人为:晁虎生 高朴祯 高婉清(姓名按学号排序)");
		outtextxy(400, txts += 55, "此程序的主要功能有:");
		textsml;
		outtextxy(400 + 20, txts += 35, "歌曲信息录入、修改、删除功能");
		outtextxy(400 + 20, txts += 35, "歌曲排序浏览功能");
		outtextxy(400 + 20, txts += 35, "按歌名查询、按演唱者查询等功能");
		textmid;
		outtextxy(400, txts += 55, "队员的主要分工如下:");
		textsml;
		outtextxy(400 + 20, txts += 35, "晁虎生:歌曲信息录入、修改、删除功能");
		outtextxy(400 + 20, txts += 35, "高朴祯:文件读取与写入操作,及主函数");
		outtextxy(400 + 20, txts += 35, "高婉清:歌曲信息排序、浏览、查询功能");
		return;
	}
	default:
		break;
	}
	return;
}
//bad attempt
/*
void ButtonOperation() {
	ExMessage msg;
	int HoverFlag = false;//avoid over-refreshing when hovering
	int PressFlag = false;//avoid over-refreshing when pressing
	int ClickNum = -1;
	while (1) {
		int i;
		for (i = 0; i <= ButtNum; i++) {
			peekmessage(&msg, EM_MOUSE);
			//hover-effect
			if (checkpos(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, msg.x, msg.y) && HoverFlag == false) {
				SetButton(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, i, 50, 50, 50);
				HoverFlag = true;
				//if mouse is still on
				while (1) {
					peekmessage(&msg, EM_MOUSE);
					//cancel hover-effect
					if (checkpos(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, msg.x, msg.y) == false) {
						SetButton(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, i, 47, 41, 41);
						HoverFlag = false;
						break;
					}
					//click effect
					if (msg.lbutton) {
						PressFlag = true;
						ClickNum = i;
						SetButton(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, i, 232, 17, 35);
						//if lb is still down
						while (1) {
							setfillcolor(RGB(47, 41, 41));
							solidroundrect(310, 15, 1014, 750, 15, 15);
							peekmessage(&msg, EM_MOUSE);
							if (!checkpos(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, msg.x, msg.y) && HoverFlag) {
								PressFlag = false;
								HoverFlag = false;
								SetButton(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, i, 50, 50, 50);

							}
							if (msg.lbutton == 0) {
								PressFlag = false;
								if (ClickNum == i) {
									break;
								}
								SetButton(butt[i].lx, butt[i].ly, butt[i].rx, butt[i].ry, i, 50, 50, 50);
								break;
							}

						}//if lb is still down
						Click(i);
					}//click effect

				}//if mouse is still on

			}//hover-effect

		}
		Sleep(20);
	}
	return;
}
*/

标签:课程设计,settextstyle,int,GUI,easyX,butt,ly,雅黑,define
来源: https://www.cnblogs.com/Jedi-Pz/p/15756482.html