## 爱斯湾(帕皮拉)

－－http://www.papi.la －－

# 用C语言实现按钮新技术

@@T5S11500.GIF;
1@@
1和图2给出了按钮两种状态和图示,1为按钮弹起时的状态图,其右边及下边的边框色为黑色(0X00),而左边及上边的边框颜色置为亮白(0x0f),而图2则恰恰相反,右边及下边的边框色为亮白,左边及上边为黑色,它反映了按钮被按下的状态。

1.

short X1;
short Y1;
short X2;
short Y1;
} button
(X1,Y1)
(X2,Y2)分别为按钮左上角和右下角的位置坐标,用于确定按钮的位置和大小。

#define START-X bt→X1
#define START-Y bt→Y1
#define END-X bt→X2
#define END-Y bt→Y2
#define Grap 1(Grap

#define Button White 0x0f
#define Button Black 0x00
2.

(1)void Button Define(button *bt,Short X1,Short Y,short X2,short Y2)

START-X=X1;
START-Y=Y1;
END-X=X2;
END-Y=Y2;
(2)Void Release Button(button *bt)

(3)Put Down Button(button *bt)

button.c
#include<graphics.h>
#include<conio.h>
#include<alloc.h>
#include<stdio.h>
#include<process.h>
#include"button.h"
#define START-X bt->x1
#define START-Y bt->y1
#define END-X bt->x2
#define END-Y bt->y2
#define Grap 1
#defile ScreenBkColor 2
#define release-color 7
#define put-color 3
#define ButtonWhite 0x0f
#define ButtonBlack 0x00
#define delay 50000
#define dis 10
void ButtonDefine (button *bt.shout.short.short.short);
void ReleaseButton(button *bt);
void PutDownButton(button *bt);
void delay-time(long int);
main()
{
int gdriver=DETECT.gmode=VGAHI:
button *but,*but1.*but2. *bt,*but3,*but4,*but5,*but6,*but7;
int ch;
initgraph(&gdriver,&gmode,"d:/tc");
setcolor(ScreenBkColor);
setbkcolor(2);
clrscr();
ButtonDefine(but,50,50,600,400);
putDownButton(but);
ButtonDefine(but1,150,200,200,250);
ButtonDefine(but2,200+dis,200,250+dis,250);
ButtonDefine(but3,250+2*dis,200,300+2*dis,250);
ButtonDefine(but4,300+3*dis,200,350+3*dis,250);
ButtonDefine(but5,350+4*dis,200,400+4*dis,250);
ButtonDefine(but6,400+5*dis,200,450+5*dis,250);
ButtonDefine(but7,450+6*dis,200,500+6*dis,250);
while(ch!=27)
{
switch(ch) }
case'1':
ReleaseButton(but1);break;
case'2':
ReleaseButton(but2);break;
case'3':
ReleaseButton(but3);break;
case'4':
ReleaseButton(but4);break;
case'5':
ReleaseButton(but5);break;
case'6':
ReleaseButton(but6);break;
case'7':
ReleaseButton(but7);break;
}
ch=getch();
if(ch==27)
break;
switch(ch)
{
case'1':
PutDownButton(but1);break;
case'2':
PutDownButton(but2);break;
case'3':
PutDownButton(but3);break;
case'4':
PutDownButton(but4);break;
case'5':
PutDownButton(but5);break;
case'6':
PutDownButton(but6);break;
case'7':
PutDownButton(but7);break;
}
delay-time(delay);
}
closegraph():
return 0;
}
void ButtonDefine(button *bt.short x1,short y1,short x2,short y2)
{
START-X=x1;
START-Y=y1;
END-X=x2;
END-Y=y2;
}
void ReleaseButton(button *bt)
{
int i,j;
setcolor(7);
setfillstyle(1,7);
bar(START-X,START-Y,END-X,END-Y);
setcolor(Button White);
setfillstyle(1,7);
bar(START-X+Grap,START-Y+Grap,END-X-Grap,END-Y-Grap);
setcolor(15);
for(j=0;j<=Grap;j++)
{
line(START-X,j+START-Y,END-X-j,j+STAT-Y);
}
for(i=0,i<=Grap;j++)
{
line(START-X+i,START-Y+Grap,START-X+i,END-Y-i);
}
setcolor(ButtonBlack);
for(j=0;j<Grap;j++)
}
line(END-X,j+END-Y-Grap,START-X+Grap-j,j+END-Y-Grap);
}
for(i=0,i<Grap;i++)
{
line(i+END-X+Grap,END-Y-Grap,i+END+X-Grap,START-Y+Grap-i);
}
return;
}
void PutDownButton(button *bt)
}
int i,j;
setcolor(put-color);
setfillstyle(1,put-color);
bar(START-X+Grap,START-Y+Grap,END-X-Grap,END-Y-Grap);
setcolor(ButtonBlack);
for(j=0;j<=Grap;j++)
{
line(START-X,j+START-Y,END-X-j,j+START-Y);
;}
for (i=0;i<Garp;i++)
{
line (START-X+i,START-Y+Grap,START-X+i,END-Y-i);
setcolor(15);
for(j=0,j<=Grap;j++)
{
line(END-X,j+END-Y-Grap,START-X+Grap-j,j+END-Y-Grap);
}
for(i=0;i<=Grap;i++)
{
line(i+END-X-Grap,END-Y-Grap,i+END-X-Grap,START-Y+Grap-i);
}
}
void delay-time(long int i)
{
i=0;
while(i<=delay)
i++;
}
button.h
typedef struct ButtonDef
{ short x1;
short y1;
short x2;
short y2;
}button;

05-25 7047

05-21 1.9万

#### <em>CButton</em> 按钮操作范例

2018年05月08日 00:00

#### NewControls 示例<em>代码</em> <em>C</em>MF<em>CButton</em>

2018年03月13日 00:00

#### V<em>C++ CBUTTON</em>

2018年06月26日 00:00

07-20 3622

01-06 1036

10-21 278

05-20 2822

11-27 6195