【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;
}
*/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM