1 #include<graphics.h>
2 #include<iostream>
3 #include <conio.h>
4
using
namespace std;
5
class botton{
6
public:
7
int x,y,w,h;
//
起点坐标,宽度和高度
8
char s[
100];
//
显示文字
9
botton(
int xx,
int yy,
int ww,
int hh,
char s[])
//
建立按钮
10
{
11 x=xx;
12 y=yy;
13 w=ww;
14 h=hh;
15 setlinestyle(PS_SOLID,NULL,
1);
16 setcolor(WHITE);
17 line(x,y,x+w,y);
18 line(x,y,x,y+h);
19 setcolor(BLACK);
20 line(x+w,y+h,x+w,y);
21 line(x+w,y+h,x,y+h);
22
23 outtextxy(x+
2,y+
2,s);
24 }
25
void LBOTTON_DOWN()
//
鼠标左键按下
26
{
27 setlinestyle(PS_SOLID,NULL,
1);
28 setcolor(BLACK);
29 line(x,y,x+w,y);
30 line(x,y,x,y+h);
31 setcolor(WHITE);
32 line(x+w,y+h,x+w,y);
33 line(x+w,y+h,x,y+h);
34 }
35
void LONTTON_UP()
//
鼠标左键松开
36
{
37 setlinestyle(PS_SOLID,NULL,
1);
38 setcolor(WHITE);
39 line(x,y,x+w,y);
40 line(x,y,x,y+h);
41 setcolor(BLACK);
42 line(x+w,y+h,x+w,y);
43 line(x+w,y+h,x,y+h);
44 }
45 };
46
int main()
47 {
48 initgraph(
600,
600);
49 setbkcolor(RGB(
230,
230,
230));
50 cleardevice();
51 setcolor(BLACK);
52 botton b1(
100,
100,
35,
20,
"
文件
");
53 getch();
54 b1.LBOTTON_DOWN();
55 getch();
56 b1.LONTTON_UP();
57 getch();