C语言写的仿Win 3.1界面

/************************************
名 称:仿Win 3.1界面
作 者:freewind
版 本:v1.0
时 间:2006-08
Email:freewind22@163.com
*************************************/

#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <string.h>
#include <time.h>
#include <process.h>

#define TRUE 1
#define FALSE 0
/* User Interface */
#define START 0
#define TIME 1
#define M_EXIT 2
#define M_HELP 3
#define M_EXEC 4
#define M_OPTION 5
#define M_DOCUMENT 6
#define M_SEARCH 7
#define M_PROGRAM 8
#define M_NEWFILE 9
#define M_UPDATE 10
#define M_ST 11
#define M_ME 12
#define M_AP 13
#define UIMAX 14
/* Form Option */
#define OP_FORM 30
#define OP_TITLE 31
#define OP_OK 32
#define OP_CANCEL 33
#define OPMAX 4

struct rect{
 int l;
 int t;
 int r;
 int b;
};
typedef struct rect RECT;

/*************************** Public Variable ****************************/
/*  Data    */
struct time CurTime;
struct date CurDate;
RECT UI[UIMAX];
RECT SM;
RECT PM;
RECT Window;
RECT Option[OPMAX];
int ShowDate;
int ExitProgram;
int MousePress=FALSE, PressX=1, PressY=1;

void *vmImage;
int CurFocus;

/*  Menu    */
char *StartMenu[]={
 "Exit",
 "-",
 "Help",
 "Exec",
 "Option",
 "Document",
 "Search",
 "Program  >>",
 "-",
 "New File",
 "Update"};
char *ProgramMenu[]={"Super Tetris",
       "MyEditor",
       "-",
       "Add Program"};
int SMNum=-1,PMNum=-1;
int SMMaxNum=11,PMMaxNum=4;
int SMIsShow,PMIsShow;

/*  Color   */
int iBgColor,iForeColor;
int iTitleColor,iTitleBgColor,iConBtnColor,iConBtnBgColor;
int iGameAreaBgColor,iBackGround;
int iBoxColor,iCurColor,iNextColor;
int iTextBoxBgColor,iTextBoxColor;
int iMaxColor;
int iInterface;
int iCursorColor;

/* Mouse */
union REGS regs;
int X__max,Y__max,x_max,y_max;
int MouseX,MouseY;
void *MouseBack;

/********************************* function declaring **********************/
void End();

/******************************** GetL **********************************/
 int GetL(int icolor){
 return icolor<=7?icolor+8:15;
}
/******************************** GetKey ********************************/
void GetKey(int *ah,int *al){
 union REGS r;
 r.h.ah=0;
 int86(0x16,&r,&r);
 *ah=r.h.ah;
 *al=r.h.al;
}
/********************************** Init_Graph *****************************/
void Init_Graph(){
 int gdriver=DETECT,gmode,errorcode;
 initgraph(&gdriver, &gmode, "");
 errorcode = graphresult();
 if (errorcode != grOk) /* an error occurred */
   {
   printf("Graphics error: %s/n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1); /*terminate with an error code */
    }
 
}
/********************************* Init_Color ****************************/
void Init_Color(){
 /* 11 colors */
 iBoxColor=2;
 iBgColor=7;
 iForeColor=1;
 iTitleColor=11;
 iTitleBgColor=1;
 iConBtnColor=11;
 iConBtnBgColor=8;
 iGameAreaBgColor=8;
 iBackGround=3;
 iTextBoxBgColor=15;
 iTextBoxColor=10;
 iInterface=TRUE;
 iCursorColor=10;
}
/**************************** Init_Mouse **********************************/
int Init_Mouse(int Xlo,int Xhi,int Ylo,int Yhi)/*鼠标初始化*/
{
 int retcode;
 regs.x.ax=0;/*初始化鼠标*/
 int86(0x33,&regs,&regs);
 retcode=regs.x.ax;
 if(retcode==0) return 0;
 regs.x.ax=7;/*设置鼠标X方向的移动范围*/
 regs.x.cx=Xlo;
 regs.x.dx=Xhi;
 int86(0x33,&regs,&regs);
 regs.x.ax=8;/*设置鼠标Y方向的移动范围*/
 regs.x.cx=Ylo;
 regs.x.dx=Yhi;
 int86(0x33,&regs,&regs);
 regs.x.ax=15;/*设置mickey与象素的比,这各会影响鼠标移动速度*/
 regs.x.cx=(int)(x_max/X__max);
 regs.x.dx=(int)(y_max/Y__max);
 int86(0x33,&regs,&regs); 
 return retcode;
}
/*********************************** Init_Data **************************/
void Init_Data()
{
 int w,h,l,t,r,b;
 int i,x,y;
 unsigned size;
 X__max=getmaxx();/*求横向象点坐标数*/
 Y__max=getmaxy();/*求纵向象点坐标数*/
 getaspectratio(&w,&h);/*求纵横比*/
 x_max=1000; /*设置屏幕坐标的宽度*/
 y_max=x_max*(float)Y__max*h/((float)X__max*w);

 getdate(&CurDate);
 size=imagesize(1,1,17,17);
 MouseBack=malloc(size);

 MouseX=x_max;
 MouseY=y_max;
 /* Window Pos */
 Window.l=l=0;
 Window.t=t=0;
 Window.r=r=X__max;
 Window.b=b=Y__max;
 /* Start Button Pos */
 UI[START].l=l+1;
 UI[START].t=b-16;
 UI[START].r=l+48;
 UI[START].b=b-1;
 /* Start Menu Pos */
 SM.l=l+2;
 SM.t=b-201;
 SM.r=l+120;
 SM.b=b-19;
 /* Time Pos */
 UI[TIME].l=r-45;
 UI[TIME].t=b-16;
 UI[TIME].r=r-6;
 UI[TIME].b=b-5;
 /* Menu Pos */
 x=l+19;
 y=b-37;
 for(i=M_EXIT;i<=M_UPDATE;i++)
 {
  UI[i].l=x;
  UI[i].t=y;
  UI[i].r=x+99;
  UI[i].b=y+16;
  y-=19;
  if(i==M_EXIT || i==M_PROGRAM) y-=5;
 }
 /* Program Menu Pos */
 PM.l=UI[M_PROGRAM].r+3;
 PM.t=UI[M_PROGRAM].t;
 PM.r=PM.l+113;
 PM.b=PM.t+63;
 x=PM.l+2;
 y=PM.b-18;
 for(i=M_ST;i<=M_AP;i++)
 {
  UI[i].l=x;
  UI[i].t=y;
  UI[i].r=x+109;
  UI[i].b=y+16;
  y-=19;
  if(i==M_ME) y-=5;
 }
 /* form option */
 Option[0].l = X__max/2 - 130;
 Option[0].t = Y__max/2 - 150;
 Option[0].r = Option[0].l + 260;
 Option[0].b = Option[0].t + 180;

 Option[OP_TITLE-OP_FORM].l = 0;
 size = imagesize ( Option[0].l, Option[0].t, Option[0].r, Option[0].b );
 vmImage = malloc ( size );
}
/********************************** Init ********************************/
void Init()
{
 Init_Graph();
 Init_Color();
 Init_Data();
 Init_Mouse(0,(int)x_max,0,(int)y_max); 
}
/******************************** Button ********************************/
void Button(int x1,int y1,int x2,int y2,int icolor){
 int lightcolor,darkcolor;
 lightcolor=GetL(icolor);
 setfillstyle(SOLID_FILL,icolor);
 setcolor(lightcolor);
 bar3d(x1,y1,x2,y2,0,0);
 if(iInterface){
  darkcolor=icolor==8?0:8;
  setcolor(darkcolor);
  line(x2,y1,x2,y2);
  line(x1,y2,x2,y2);
 }
}
/******************************** Button2 ********************************/
void Button2(int x1,int y1,int x2,int y2,int icolor){
 int lightcolor,darkcolor;
 lightcolor=GetL(icolor);
 setfillstyle(SOLID_FILL,icolor);
 setcolor(lightcolor);
 bar3d(x1,y1,x2,y2,0,0);
 if(iInterface){
  darkcolor=icolor==8?0:8;
  setcolor(darkcolor);
  line(x1,y1,x2,y1);
  line(x1,y1,x1,y2);
 }
}
/******************************** CloseButton ****************************/
void CloseButton(int x1,int y1,int x2,int y2,int icolor){
 int i=3;
 Button(x1,y1,x2,y2,icolor);
 setcolor(iConBtnColor);
 /* / */
 line(x1+i,y1+i,x2-i,y2-i+1);
 /* / */
 line(x1+i,y2-i+1,x2-i,y1+i);
}
/********************************* MinButton ******************************/
void MinButton(int x1,int y1,int x2,int y2,int icolor){
 int i=4;
 Button(x1,y1,x2,y2,icolor);
 setcolor(iConBtnColor);
 line(x1+i,y2-i+1,x2-i,y2-i+1);
 line(x1+i,y2-i,x2-i,y2-i);
}
/*********************************** OpenWindow ****************************/
void OpenWindow(int x1,int y1,int x2,int y2,int btnMin,int btnClose,char cTitle[20]){
 int bx=x2,i=4;
 Button(x1,y1,x2,y2,iBgColor);
 setfillstyle(SOLID_FILL,iTitleBgColor);
 bar(x1+2,y1+2,x2-2,y1+16);
 /* draw icon */
 setfillstyle(SOLID_FILL,12);
 bar(x1+i,y1+i-1,x1+i*2,y1+i*2-1);
 setfillstyle(SOLID_FILL,14);
 bar(x1+i*2+2,y1+i-1,x1+i*3+2,y1+i*2-1);
 setfillstyle(SOLID_FILL,9);
 bar(x1+i,y1+i*2+1,x1+i*2,y1+i*3+1);
 setfillstyle(SOLID_FILL,10);
 bar(x1+i*2+2,y1+i*2+1,x1+i*3+2,y1+i*3+1);
 /* control button */
 if (btnClose){
  CloseButton(x2-17,y1+3,x2-5,y1+14,iConBtnBgColor);
  bx-=17;
 }
 if (btnMin){
  MinButton(bx-17,y1+3,bx-5,y1+14,iConBtnBgColor);
  bx-=17;
 }
 setcolor(iTitleColor);
 if( iInterface){
  settextjustify(0,1);
  outtextxy(x1+20,y1+9,cTitle);
 }else{
  settextjustify(1,1);
  outtextxy(x1+(x2-x1)/2 ,y1+9,cTitle);
 }
}
/***************************** TextBox ***********************************/
void TextBox(int l,int t,int r,int b){
 int lightcolor,darkcolor=8;
 setfillstyle(SOLID_FILL,iTextBoxBgColor);
 lightcolor=GetL(iTextBoxBgColor);
 setcolor(lightcolor);
 bar3d(l,t,r,b,0,0);
 if(iInterface){
  if(iTextBoxBgColor==8 || iTextBoxBgColor==0) darkcolor=0;
  setcolor(darkcolor);
  line(l,t,r,t);
  line(l,t,l,b);
 }
}
/******************************* FrmOption *******************************/
void FrmOption(){
 int l,r,t,b,x,y;
 int ah,al;
 int i,j;
 char c[3] = " 0";

 l=Option[0].l ,r=Option[0].r;
 t=Option[0].t ,b=Option[0].b;
 /*if ( TRUE || Option[1].l == 0 )
 {*/
  Option[1].l = l+2;
  Option[1].t = t+2;
  Option[1].r = r-2;
  Option[1].b = t+16;

 
 getimage(l,t,r,b,vmImage);
 OpenWindow(l,t,r,b,0,1,"Option");
 /*bar(l+2,t+2,r-2,t+16);*/
 x = l + 18, y = t + 26; 
 settextjustify( 0, 0 );
 for ( i = 0; i < 16; i++ )
 {
  setcolor(iForeColor);
  if ( i < 10 )
   c[1] = i + 48;
  else
   itoa( i, c, 10 );
  outtextxy( x - 16, y + 10, c );
  setcolor(15);
  setfillstyle( SOLID_FILL, i );
  bar3d ( x, y, x + 11, y + 9, 0, 0 );
  x += 32;
  if ( i == 7 )
  {
   y += 20;
   x = l + 18;
  }
 }
 /*GetKey( &ah, &al );
 putimage(l,t,vmImage,COPY_PUT);*/

}
/*************************** Xpixel Ypixel *******************************/
int Xpixel(int x)/*由象素坐标变换为屏幕坐标*/
{
 return (int)((long)X__max*x/x_max);
}
int Ypixel(int y)
{
 return Y__max-(int)((long)Y__max*y/y_max);
}
/******************************* Cursor ********************************/
void Cursor(int x,int y,int show)
{
 static int X,Y;
 int i,wid,hei;
 if(!show)
 {
  putimage(X,Y,MouseBack,COPY_PUT);
  return;
 }
 wid=(X__max-x),hei=(Y__max-y);
 if(wid>10) wid=10;
 if(hei>10) hei=10;
 getimage(x,y,x+wid,y+hei,MouseBack);
 X=x;
 Y=y;
 setcolor(iCursorColor);
 for(i=0;i<4;i++)
 {
  line(x,y+i,x+10,y+6);
  line(x+i,y+i,x,y+6);
 }
}
/******************************* GetPos ****************************************/
int GetPos(int x,int y)
{
 int result=-1,i;
 for(i=0;i<UIMAX;i++)
 {
  if((i>=M_EXIT && !SMIsShow) || (i>=M_ST && !PMIsShow))
   goto next;
  if(x>=UI[i].l && y>=UI[i].t && x<=UI[i].r && y<=UI[i].b)
   break;
 }
 if(i<UIMAX)
  result=i;
next:
 for(i=1;i<OPMAX;i++)
  if(x>=Option[i].l && y>=Option[i].t && x<=Option[i].r && y<=Option[i].b)
   break;
 if(i<OPMAX)
  result=i+OP_FORM;
 return result;
}
/******************************** Show_Data ************************************/
void Show_Date(int Show)
{
 int color,l,t,r,b;
 int year,month,day;
 char Date[14]="",c[5]="";
 if(Show) color=15; else color=iBackGround;
 setfillstyle(SOLID_FILL,color);
 l=UI[TIME].l-41;
 t=UI[TIME].t-18;
 r=l+84;
 b=t+14;
 bar(l,t,r,b);
 if(Show)
 {
  getdate(&CurDate);
  year=CurDate.da_year;
  month=CurDate.da_mon;
  day=CurDate.da_day;
  /* year */
  itoa(year,c,10);
  strcpy(Date,c);
  strcat(Date,"-");
  /* month */
  itoa(month,c,10);
  if(month<10) strcat(Date,"0");
  strcat(Date,c);
  strcat(Date,"-");
  /* day */
  itoa(day,c,10);
  if(day<10) strcat(Date,"0");
  strcat(Date,c);

  setcolor(0);
  rectangle(l,t,r,b);
  settextjustify(0,1);
  setcolor(iForeColor);
  outtextxy(l+3,t+8,Date);
 }
}
/******************************* ShowMenu **************************************/
void ShowMenu(int n)
{
 int l,t,r,b;
 int i,lightcolor;
 Cursor(MouseX,MouseY,FALSE);
 settextjustify(0,0);
 if(SMNum>=0)
 {
  l=UI[SMNum].l;
  t=UI[SMNum].t;
  r=UI[SMNum].r;
  b=UI[SMNum].b;
  setfillstyle(SOLID_FILL,iBgColor);
  bar(l,t,r,b);
  setcolor(iForeColor);
  i=SMNum;
  if(i>M_PROGRAM) i++;
  if(i>M_EXIT) i++;  
  i-=M_EXIT;
  outtextxy(l+8,t+13,StartMenu[i]);
 }
 if(n>=0)
 {
  l=UI[n].l;
  t=UI[n].t;
  r=UI[n].r;
  b=UI[n].b;
  setfillstyle(SOLID_FILL,iForeColor);
  bar(l,t,r,b);
  lightcolor=GetL(iBgColor);
  setcolor(lightcolor);
  i=n; 
  if(i>M_PROGRAM) i++;
  if(i>M_EXIT) i++;
  i-=M_EXIT;
  outtextxy(l+8,t+13,StartMenu[i]);
 }
 Cursor(MouseX,MouseY,TRUE);
}
/******************************* ShowSubMenu **************************************/
void ShowSubMenu(int n)
{
 int l,t,r,b;
 int i,lightcolor;
 Cursor(MouseX,MouseY,FALSE);
 settextjustify(0,0);
 if(PMNum>=0)
 {
  l=UI[PMNum].l;
  t=UI[PMNum].t;
  r=UI[PMNum].r;
  b=UI[PMNum].b;
  setfillstyle(SOLID_FILL,iBgColor);
  bar(l,t,r,b);
  setcolor(iForeColor);
  i=PMNum;
  if(i>M_ME) i++; 
  i-=M_ST;
  outtextxy(l+8,t+13,ProgramMenu[i]);
 }
 if(n>=0)
 {
  l=UI[n].l;
  t=UI[n].t;
  r=UI[n].r;
  b=UI[n].b;
  setfillstyle(SOLID_FILL,iForeColor);
  bar(l,t,r,b);
  lightcolor=GetL(iBgColor);
  setcolor(lightcolor);
  i=n; 
  if(i>M_ME) i++;
  i-=M_ST;
  outtextxy(l+8,t+13,ProgramMenu[i]);
 }
 Cursor(MouseX,MouseY,TRUE);
}
/******************************* ShowProgramMenu *******************************/
void ShowProgramMenu(int show)
{
 int l,t,r,b;
 int i,j,color;
 int spline=0;
 int lightcolor,darkcolor;
 Cursor(MouseX,MouseY,FALSE);
 l=PM.l;
 t=PM.t;
 r=PM.r;
 b=PM.b;
 if(show)
  Button(l,t,r,b,iBgColor);
 else{
  setfillstyle(SOLID_FILL,iBackGround);
  bar(l,t,r,b);
 }
 PMIsShow=show;
 if(!show) return;
 settextjustify(0,0);
 lightcolor=GetL(iBgColor);
 darkcolor=iBgColor==8?0:8;
 /* Show Menu */
 for(i=0;i<PMMaxNum;i++)
 {
  l=UI[i+M_ST-spline].l;
  t=UI[i+M_ST-spline].t;
  r=UI[i+M_ST-spline].r;
  b=UI[i+M_ST-spline].b;
  if(!strcmp(ProgramMenu[i],"-"))
  {
   setcolor(darkcolor);
   line(l,t+20,r,t+20);
   setcolor(lightcolor);
   line(l,t+21,r,t+21);
   spline++;
  }
  else
  {
   setcolor(iForeColor);
   outtextxy(l+8,t+13,ProgramMenu[i]);
  }
 }
 Cursor(MouseX,MouseY,TRUE);
}
/******************************* ShowStartMenu *********************************/
void ShowStartMenu(int show)
{
 int l,t,r,b;
 int i,j;
 int spline=0;
 int lightcolor,darkcolor;
 Cursor(MouseX,MouseY,FALSE);
 l=SM.l;
 t=SM.t;
 r=SM.r;
 b=SM.b;
 if (show)
  Button(l,t,r,b,iBgColor);
 else
 {
  setfillstyle(SOLID_FILL,iBackGround);
  bar(l,t,r,b);
 }
 SMIsShow=show;
 if(!show) return;
 /* Show AppName */
 setfillstyle(SOLID_FILL,iForeColor);
 bar(l+1,t+1,l+15,b-1);
 settextstyle(0,1,0);
 settextjustify(0,0);
 setcolor(15);
 outtextxy(l+12,b-4,"Windows 3.1");
 settextstyle(0,0,0);
 lightcolor=GetL(iBgColor);
 darkcolor=iBgColor==8?0:8;
 /* Show Menu */
 for(i=0;i<SMMaxNum;i++)
 {
  l=UI[i+M_EXIT-spline].l;
  t=UI[i+M_EXIT-spline].t;
  r=UI[i+M_EXIT-spline].r;
  b=UI[i+M_EXIT-spline].b;
  if(!strcmp(StartMenu[i],"-"))
  {
   setcolor(darkcolor);
   line(l,t+20,r,t+20);
   setcolor(lightcolor);
   line(l,t+21,r,t+21);
   spline++;
  }
  else
  {
   /*setfillstyle(SOLID_FILL,2);
   bar(l,t,r,b);*/
   setcolor(iForeColor);
   outtextxy(l+8,t+13,StartMenu[i]);
  }
 }
 Cursor(MouseX,MouseY,TRUE);
}
/******************************* Mouse_Move ************************************/
void Mouse_Move(int x,int y)
{
 int pos=GetPos(x,y);
 int l,t,r,b,i;
 /****** UI ************/
 switch(pos)
 {
 case START:
  break;
 case TIME:
  if(!ShowDate)
  {
   ShowDate=TRUE;
   Show_Date(TRUE);
  }
  break;
 case M_EXIT:
 case M_HELP:
 case M_EXEC:
 case M_OPTION:
 case M_DOCUMENT:
 case M_SEARCH:
 case M_PROGRAM:
 case M_NEWFILE:
 case M_UPDATE:
  if(pos!=SMNum)
  {
   ShowMenu(pos);
   SMNum=pos;
   /* Show Program Menu */
   if(pos==M_PROGRAM && !PMIsShow)
   {
    ShowProgramMenu(TRUE);
   }
   if(pos!=M_PROGRAM && PMIsShow)
   {
    ShowProgramMenu(FALSE);
    PMNum=-1;
   }
  }
  break;
 case M_ST:
 case M_ME:
 case M_AP:
  if(pos!=PMNum)
  {
   ShowSubMenu(pos);
   PMNum=pos;
  }
  break;
 default:
  if(ShowDate)
  {
   ShowDate=FALSE;
   Show_Date(FALSE);
  } 
  if(SMIsShow && SMNum>=0 && !PMIsShow)
  {
   ShowMenu(-1); 
   SMNum=-1;
  }
  if(PMIsShow && PMNum>=0)
  {
   ShowSubMenu(-1);
   PMNum=-1;
  }
  break;
 }
 /******* Option ***********/
 if( MousePress && FALSE )
 {
  printf("%d,%d  ",PressX,PressY);
 }
 switch(pos)
 {
 case OP_TITLE:
  if( MousePress && (PressX || PressY) )
  { 
   l=Option[0].l , t=Option[0].t;
   r=Option[0].r , b=Option[0].b;
   if ( MousePress==1)
   {
    MousePress=2;
    getimage(l,t,r,b,vmImage);
   }
   setfillstyle(SOLID_FILL,iBackGround);
   bar(l,t,r,b);

   Option[0].l=l+PressX , Option[0].r=r+PressX;
   Option[0].t=t+PressY , Option[0].b=b+PressY;

   Option[1].l = l+2;
   Option[1].t = t+2;
   Option[1].r = r-2;
   Option[1].b = t+16;
   
   putimage(Option[0].l,Option[0].t,vmImage,COPY_PUT);
  }
  break;
 }
}
/******************************* End_ExecST ************************************/
void End_ExecST(void)
{
 system("G://c//tetris//tetris.exe");
}
/******************************* End_ExecME ***********************************/
void End_ExecME(void)
{
 system("G://c//myeditor//myeditor.exe");
}
/******************************* ClearMenu ************************************/
void ClearMenu()
{
 ShowStartMenu(FALSE);
 SMNum=-1;
 if(PMIsShow)
 {
  ShowProgramMenu(FALSE);
  PMNum=-1;
 }
}
/******************************* Mouse_Click **********************************/
void Mouse_Click(int x,int y,int btn)
{
 int pos=GetPos(x,y);
 int result;
 switch(pos)
 {
 case START:
  if(btn==1) /* left */
  {
   ShowStartMenu(TRUE);
  }
  break;
 case TIME:
  break;
 case M_EXIT:
  ExitProgram=TRUE;
  break;
 case M_OPTION:
  ClearMenu();
  Cursor( MouseX, MouseY, TRUE );
  FrmOption();
  break;
 case M_ST:
  End();
  atexit(End_ExecST);
  exit(0);
  break;
 case M_ME:
  End();
  atexit(End_ExecME);
  exit(0);
  break;
 default:
  if(SMIsShow)
   ClearMenu();
 }
}
/****************************** Mouse_Read *************************/
int Mouse_Read(int *px,int *py,int *pbuttons)
{
 union REGS regs;
 int btn;
 regs.x.ax=3;
 int86(0x33,&regs,&regs);
 *px=Xpixel(regs.x.cx);
 *py=Ypixel((int)(y_max-regs.x.dx));
 *pbuttons=regs.x.bx;
 if (*pbuttons == 1 )
 {
  regs.x.ax=5;
  regs.x.bx=0;
  int86(0x33,&regs,&regs);
  btn=regs.x.bx;
  if ( btn == 1){
   MousePress=TRUE;
   /*PressX=*px-MouseX;
   PressY=*py-MouseY;*/
  }
 }
 else
  MousePress=FALSE;
 
 return -1;
}
/******************************** ShowTime *****************************/
void ShowTime(int x,int y)
{
 static int left,top;
 char c[3]="",ctime[10]="";
 if(x>0){
  left=x;
  top=y;
 }
 itoa(CurTime.ti_hour,c,10);
 if(CurTime.ti_hour<10)
 {
  c[2]=0;
  c[1]=c[0];
  c[0]='0';
 }
 strcpy(ctime,c);
 strcat(ctime,":");
 itoa(CurTime.ti_min,c,10);
 if(CurTime.ti_min<10)
 {
  c[2]=0;
  c[1]=c[0];
  c[0]='0';
 }
 strcat(ctime,c);
 setcolor(iForeColor);
 setfillstyle(SOLID_FILL,iBgColor);
 bar(left-1,top-6,left+38,top+5);
 settextjustify(0,1);
 outtextxy(left,top,ctime);
}
/******************************* FrmMain *******************************/
void FrmMain()
{
 int l,t,r,b;
 int bt,x,y,i;
 int lightcolor,darkcolor;
 lightcolor=GetL(iBgColor);
 darkcolor=iBgColor==8?0:8;
 l=Window.l;
 t=Window.t;
 r=Window.r;
 b=Window.b;
 bt=b-18;
 /* BackGround */
 setfillstyle(SOLID_FILL,iBackGround);
 bar(l,t,r,b);
 /* Bottom Buttom */
 setfillstyle(SOLID_FILL,iBgColor);
 bar(l,bt,r,b);
 setcolor(lightcolor);
 line(l,bt,r,bt);
 /* Start Button */
 Button(UI[START].l,UI[START].t,UI[START].r,UI[START].b,iBgColor);
 settextjustify(0,1);
 setcolor(iForeColor);
 settextstyle(2,0,4);
 outtextxy(UI[START].l+17,UI[START].t+6,"Start");
 /*hanzi16(UI[START].l+16,UI[START].t+2,"开始",iForeColor);*/
 settextstyle(0,0,0);
 /* Draw Icon */
 x=l+1;
 y=bt+1;
 i=4;
 setfillstyle(SOLID_FILL,12);
 bar(x+i,y+i-1,x+i*2,y+i*2-1);
 setfillstyle(SOLID_FILL,14);
 bar(x+i*2+2,y+i-1,x+i*3+2,y+i*2-1);
 setfillstyle(SOLID_FILL,9);
 bar(x+i,y+i*2+1,x+i*2,y+i*3+1);
 setfillstyle(SOLID_FILL,10);
 bar(x+i*2+2,y+i*2+1,x+i*3+2,y+i*3+1);
 /* Show Time */
 x=r-76;
 y=bt+2;
 Button2(x,y,r-2,y+15,iBgColor);
 gettime(&CurTime);
 ShowTime(r-44,y+8);
 /* Show Language */
 setfillstyle(SOLID_FILL,iForeColor);
 bar(x+5,y+2,x+25,y+13);
 setcolor(iBgColor);
 outtextxy(x+8,y+8,"CH");
 /* line
 x=UI[START].r+4;
 y=UI[START].t+2;
 setcolor(darkcolor);
 line(x,y,x,y+11);
 setcolor(lightcolor);
 line(x+1,y,x+1,y+11);*/
}
/****************************** Begin **********************************/
void Begin()
{
 int ah=-1,al=-1;
 int x,y,btn,btn0;
 struct time t;
 btn=btn0=0;
 Cursor(MouseX,MouseY,TRUE);
 ExitProgram=FALSE;
 while(!ExitProgram)
 {
  while(!kbhit() && !ExitProgram)
  {
   Mouse_Read(&x,&y,&btn);
   if(x!=MouseX || y!=MouseY) /* Mouse Move */
   {
    Cursor(MouseX,MouseY,FALSE);
    if ( MousePress )
    {
     PressX=x-MouseX;
     PressY=y-MouseY;
    }
    MouseX=x;
    MouseY=y;
    Cursor(MouseX,MouseY,TRUE);
    Mouse_Move(x,y);
   }
   if(btn!=btn0){   /* Mouse Click */
    Mouse_Click(MouseX,MouseY,btn);
    btn0=btn;
   }
   gettime(&t);
   if(t.ti_min!=CurTime.ti_min || t.ti_hour!=CurTime.ti_hour)
   {
    CurTime=t;
    ShowTime(-1,-1);
   }

  }
  if(!ExitProgram)
  {
   GetKey(&ah,&al);
   if(ah==1 && al==27) break;
  }
 }
 Cursor(MouseX,MouseY,FALSE);
}
/****************************** End ************************************/
void End()

 /* close graph*/
 closegraph();
 /* free memory */
 free(MouseBack);
 /* close mouse */
 regs.x.ax=2;
 int86(0x33,&regs,&regs);
}
/****************************** main ***********************************/
void main()
{
 Init();
 FrmMain();
 Begin();
 End();
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值