演示
代码:
manageSystem.h头文件:
#pragma once
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<Windows.h>
#include<time.h>
#include<process.h>
#include<graphics.h>
class manageSystem
{
public:
void startInterface();
int button_judge(int x,int y);
int layer = 1;
};
manageSystem.cpp部分:
#include "manageSystem.h"
#include "superMarket.h"
#define WIDTH 1000
#define HEIGHT 600
IMAGE bk1,bk2;
int drawroundrect[2][6] =
{ {WIDTH / 6 - 80, 3 * HEIGHT / 4 - 100, WIDTH / 6 + 70, 3 * HEIGHT / 4 - 20, 40, 40},
{WIDTH / 6 - 80, 3 * HEIGHT / 4 + 20, WIDTH / 6 + 70, 3 * HEIGHT / 4 + 100, 40, 40}
};
void manageSystem::startInterface()
{
int event = 0;
RECT rect1,rect2,rect3,rect4,rect5;
ExMessage m;
manageSystem layer;
setbkcolor(RGB(200,200,255));
cleardevice();
setfillcolor(WHITE);
solidroundrect(WIDTH / 6 - 80, 3 * HEIGHT / 4 - 100, WIDTH / 6 + 70, 3 * HEIGHT / 4 - 20, 40, 40);
solidroundrect(WIDTH / 6 - 80, 3 * HEIGHT / 4 + 20, WIDTH / 6 + 70, 3 * HEIGHT / 4 + 100, 40, 40);
settextstyle(40, 25, "微软雅黑");
settextcolor(RGB(128,0,128));
setbkmode(TRANSPARENT);
rect1 = { WIDTH / 6 - 80, 3 * HEIGHT / 4 - 100, WIDTH / 6 + 70, 3 * HEIGHT / 4 - 20 };
drawtext("进入", &rect1, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
settextstyle(40, 25, "微软雅黑");
settextcolor(RGB(128, 0, 128));
setbkmode(TRANSPARENT);
rect2 = { WIDTH / 6 - 80, 3 * HEIGHT / 4 + 20, WIDTH / 6 + 70, 3 * HEIGHT / 4 + 100 };
drawtext("退出", &rect2, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
settextstyle(70, 50, "微软雅黑");
settextcolor(RGB(255, 255, 0));
setbkmode(TRANSPARENT);
rect3 = { 50 , 50, WIDTH - 100, 150 };
drawtext("超市管理系统", &rect3, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
loadimage(&bk1, "超市1.png", 600, 400);
loadimage(&bk2, "超市2.png", 600, 400);
putimage(WIDTH / 6 + 150, 3 * HEIGHT / 4 - 250, &bk2, SRCAND);
putimage(WIDTH / 6 + 150, 3 * HEIGHT / 4 - 250, &bk1, SRCPAINT);
while (true)
{
if (layer.layer == 1)
{
m = getmessage(EM_MOUSE);
switch (m.message)
{
case WM_MOUSEMOVE:
setrop2(R2_XORPEN);
setlinecolor(RED);
setfillcolor(WHITE);
if (button_judge(m.x, m.y) != 0)
{
if (event != button_judge(m.x, m.y))
{
event = button_judge(m.x, m.y);
solidroundrect(drawroundrect[event - 1][0], drawroundrect[event - 1][1], drawroundrect[event - 1][2], drawroundrect[event - 1][3], 40, 40);
}
}
else
{
if (event != 0)
{
solidroundrect(drawroundrect[event - 1][0], drawroundrect[event - 1][1], drawroundrect[event - 1][2], drawroundrect[event - 1][3], 40, 40);
event = 0;
}
}
break;
case WM_LBUTTONDOWN:
setrop2(R2_NOTXORPEN);
for (int i = 0; i <= 10; i++)
{
setlinecolor(RGB(25 * i, 25 * i, 25 * i));
circle(m.x, m.y, 2 * i);
Sleep(25);
circle(m.x, m.y, 2 * i);
}
flushmessage(EM_MOUSE);
if (button_judge(m.x, m.y) == 2)
{
setbkcolor(RGB(200, 200, 255));
cleardevice();
settextstyle(60, 30, "微软雅黑");
settextcolor(RGB(255, 0, 0));
setbkmode(TRANSPARENT);
rect4 = { 100 , HEIGHT / 2 - 50, WIDTH - 70, HEIGHT / 2 + 50 };
drawtext("欢迎下次使用超市管理系统!", &rect4, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
settextstyle(30, 10, "微软雅黑");
settextcolor(RGB(255, 0, 0));
setbkmode(TRANSPARENT);
rect5 = { 100 , HEIGHT / 2 + 50, WIDTH - 70, HEIGHT / 2 + 80 };
drawtext("(系统将于5秒钟后关闭)", &rect5, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
Sleep(5000);
exit(0);
}
if (button_judge(m.x, m.y) == 1)
{
superMarket market;
layer.layer = 2;
market.mainInterface();
}
break;
default:
break;
}
}
}
}
int manageSystem::button_judge(int x, int y)
{
if (x > WIDTH / 6 - 80 && x < WIDTH / 6 + 70 && y>3 * HEIGHT / 4 - 100 && y < 3 * HEIGHT / 4 - 20)
{
return 1;
}
if (x > WIDTH / 6 - 80 && x < WIDTH / 6 + 70 && y>3 * HEIGHT / 4 + 20 && y < 3 * HEIGHT / 4 + 100)
{
return 2;
}
return 0;
}
superMarket.h头文件部分:
#pragma once
#include"manageSystem.h"
class superMarket
{
public:
void mainInterface();
};
superMarket.cpp部分:
#include "superMarket.h"
#define WIDTH 1000
#define HEIGHT 600
void superMarket::mainInterface()
{
setbkcolor(WHITE);
cleardevice();
}
主函数:
#include"manageSystem.h"
#define WIDTH 1000
#define HEIGHT 600
int main()
{
manageSystem supershop;
initgraph(WIDTH, HEIGHT,EW_NOMINIMIZE);
supershop.startInterface();
while (1);
closegraph();
}
其余图片资源(与源文件在同一个文件夹里):
|