为TurboC增加一个立体按钮函数

Author: 王焱 Date: 1997-01-01

  当今大多数优秀软件都采用立体按钮作选择开关,这种直观、清晰的图形界面深受广大用户的青睐,笔者利用Turbo C 2.0提供的绘图功能编制了一个通用的立体按钮函数Windows,该函数使用极其灵活,可任意改变其大小、高度、颜色及状态。现将实现立体按钮的程序介绍给读者,以供参考。
  /*在主程序中调用举例*/
  #include "graphics.h"
  void windows(int x,int y,int xa,int ya,int high,int stat,int color);
  main()
  {
  int d=VGA,m=VGAHI;
  initgraph(&d,&m,"");
  windows(100,100,200,130,4,0,1);
  getch();
  closegraph();}
  /*立体按钮函数*/
  void windows(int x,int y,int xa,int ya,int high,int stat,int color)
  {register i;
  if(!stat)
  setfillstyle(1,color+8);else setfillstyle(1,color);
  bar(x,y,xa,ya);
  setcolor(0);
  rectangle(x-high,y-high,xa+high,ya+high);
  rectangle(x,y,xa,ya);
  if(stat)
  setcolor(7);else setcolor(8);
  for (i=1;i<high;i++)
  {line(x-i,y-i,x-i,ya+i);}
  line(x-i,ya+i,xa+i,ya+i);}
  if(stat)
  setcolor(8);else setcolor(7);
  for(i=1;i<high;i++)
  {line(xa+i,y-i,xa+i,ya+i);
  line(x-i,y-i,xa+i,y-i);}
  setcolor(0);
  line(x-high,y-high,x,y);
  line(xa+high,y-high,xa,y);
  line(xa+high,ya+high,xa,ya);
  line(x-high,ya+high,x,ya);
  }