·设为首页
·收藏本站  
·错误报告
您现在的位置: 首页>>理工论文>>计算机论文>>新闻

站长欢迎各位朋友投稿6366083#163.com(#换成@),本站永久免费,请各位朋友记住本站网址:www.lwen.net,别忘记介绍新朋友过来奥^_^

会员登陆
最近更新
有广告才有收入,网站才能发展。
用C语言实现按钮新技术
  发表时间:2005-9-28 14:56:17  浏览人次: 我要投稿
>@@T5S11500.GIF;图1@@图1和图2给出了按钮两种状态和图示,图1为按钮弹起时的状态图,其右边及下边的边框色为黑色(0X00),而左边及上边的边框颜色置为亮白(0x0f),而图2则恰恰相反,右边及下边的边框色为亮白,左边及上边为黑色,它反映了按钮被按下的状态。在程序应用中,设置某一按钮时,显示图1的状态,再选中这个按钮时,则显示出图2的状态,经过短暂的延时后,恢复到图1的状态,给用户的感觉是按钮被按下后又弹起。在Windows中的按钮就是这样的,3D studio中的部分按钮当被选中时,只显示图2,这时用户可以很清晰地看到凹下的按钮。二、程序实现主要包括按钮结构的意义和与它有关的几个函数。1.结构定义typedef struet Button Def{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 0x002.函数定义(1)void Button Define(button *bt,Short X1,Short Y,short X2,short Y2)该函数用于定义一个名为bt的按钮的大小和位置,其左上角及右下角坐标为(X1,Y1),(X2,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)该函数显示按钮按下时的状态。下面列出了以上函数用于定义按钮,显示按钮弹起,按下状态的程序,这个程序在屏幕上显示7个按钮,按下1~7个数字后就弹起某个按钮,非常方便,需要弹起某个数字就按哪个数字,特别需要指出的是,当Gsap大一些时,每个按钮,就如同键盘上的键一样,立体感很强,有兴趣的读者可以实践操作一下,并把这种简明易懂的技术用之于工作,以提高工作效率。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 10void 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.htypedef struct ButtonDef{ short x1;short y1;short x2;short y2;}button; 作者:庞剑飞
文章搜索
关键字:
Copyright ©2005 - 2006 Lwen.Net      广告合作—QQ 1573351 Email:6366083#163.com(#换成@)