GUI实现
#include <graphics.h>
#include <stdio.h>
static int r1[] = { 875, 255, 1110, 310 };
int r2[] = { 875, 355, 1110, 410 };
int r3[] = { 875, 455, 1110, 510 };
MOUSEMSG msg;
bool checkMouse(int rect[]);
int main() {
initgraph(1280, 720);
HWND hwnd;
hwnd = GetHWnd();
SetWindowText(hwnd, _T("校园导览系统V1.0"));
loadimage(NULL, _T("JPG"), _T("Homepage"), 1280, 720, true);
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 255, 255));
LOGFONT f1;
gettextstyle(&f1);
f1.lfHeight = 60;
_tcscpy_s(f1.lfFaceName, _T("思源黑体 CN Bold"));
f1.lfQuality = ANTIALIASED_QUALITY;
settextstyle(&f1);
outtextxy(860, 110, _T("校园导览系统"));
settextstyle(27, 0, _T("Gen Jyuu Gothic Bold"));
outtextxy(865, 170, _T("Campus Navigation System"));
RECT Button1 = { r1[0],r1[1],r1[2],r1[3] };
RECT Button2 = { r2[0],r2[1],r2[2],r2[3] };
RECT Button3 = { r3[0],r3[1],r3[2],r3[3] };
setbkmode(TRANSPARENT);
settextcolor(RGB(255, 255, 255));
LOGFONT f;
gettextstyle(&f);
f.lfHeight = 40;
_tcscpy_s(f.lfFaceName, _T("思源黑体 CN Bold"));
f.lfQuality = ANTIALIASED_QUALITY;
settextstyle(&f);
drawtext(_T("开始导航"), &Button1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("查询历史"), &Button2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
drawtext(_T("退出"), &Button3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
setlinecolor(RGB(255, 255, 255));
setlinestyle(PS_SOLID, 3);
roundrect(875, 255, 1110, 310, 15, 15);
roundrect(875, 355, 1110, 410, 15, 15);
roundrect(875, 455, 1110, 510, 15, 15);
if(checkMouse(r1))
{
cleardevice();
setbkcolor(WHITE);
cleardevice();
IMAGE img1,img2;
loadimage(&img1, _T("JPG"), _T("沙河地图"), 455, 397, true);
putimage(820, 60, &img1);
loadimage(&img2, _T("PNG"), _T("本部地图"), 837, 397, true);
putimage(0,60, &img2);
}
getchar();
closegraph();
return 0;
}
bool checkMouse(int rect[]) {
FlushMouseMsgBuffer();
while (true) {
while (MouseHit())
{
msg = GetMouseMsg();
if (WM_LBUTTONDOWN == msg.uMsg) {
if (msg.x>rect[0] && msg.x<rect[2] && msg.y>rect[1] && msg.y<rect[3])
{
return true;
}
}
}
}
}