TC20写的DOS底下文本菜单

程序 专栏收录该内容
16 篇文章 0 订阅

很象用TURBO VISION写的界面。 

/*
 
  DATE:05/2000
  TOPIC:文本菜单
  pass by:turboc 20

*/

# include <graphics.h>
# include <alloc.h>
# include <process.h>
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# include <string.h>
# include <dos.h>
# include <bios.h>
# include <conio.h>
# include <ctype.h>

# define SCREENMINX 0
# define SCREENMINY 0
# define SCREENMAXX 79
# define SCREENMAXY 24

#define WindowMaxX 79
#define WindowMinX 0
#define WindowMaxY 24
#define WindowMinY 0

/* #define BLINK 0x80 */
#define LIGHT 0x08
#define WHITE 0x07
#define BLACK 0x00
#define RED   0x04
#define GREEN 0x02
#define BLUE  0x01

#define MIXCOLOR(A,B)   A|B
#define LIGHTSHOW(A)    A|LIGHT
#define DARKSHOW(A)     A&0xf7
#define BLINKSHOW(A)    A|BLINK
#define NOTBLINKSHOW(A) A&0x7f
#define BACKCOLOR(A)    A<<4
#define MIX(A,B)        (A | BACKCOLOR(B))
#define GetBackColor(A) ((A&0x70)>>4)
#define GetForeColor(A) A&0x0f
#define EnabledSelectMenuItem   MIX(BLACK,WHITE)
#define EnabledMenuItem         MIX(BLACK,GREEN)
#define DisabledSelectMenuItem  MIX(LIGHSHOW(BLACK),BLACK)
#define DisabledMenuItem        MIX(LIGHSHOW(BLACK),WHITE)


# define INSERT 0x5200
# define ESC    0x001b
# define TAB    0x0f09
# define RETURN 0x000d
# define RIGHT  0x4d00
# define LEFT   0x4b00
# define UP     0x4800
# define DOWN   0x5000
# define BS     0x0e08
# define HOME   0x4700
# define END    0x4f00
# define PGUP   0x4900
# define PGDN   0x5100
# define DEL    0x5300
# define F1     0x3b00
# define F2     0x3c00
# define F3     0x3d00
# define F4     0x3e00
# define F5     0x3f00
# define F6     0x4000
# define F7     0x4100
# define F8     0x4200
# define F9     0x4300
# define F10    0x4400

# define MenuInGround     1
# define MenuActiveGround 2
# define MenuActiveItem   3
# define MenuInItem       4
# define MenuEdge         5
# define WindowEdge       6
# define WindowGround     7
# define PopWindow        8

/*
unsigned char AllColors[20] = { 0 ,CYAN , LIGHTRED , YELLOW ,
    BLACK , WHITE , LIGHTRED,BLUE,
    CYAN ,9 ,10,11 ,12 ,13 ,14,15} ;
*/

typedef unsigned char UCHAR;
typedef unsigned int  UINT;
typedef unsigned long ULONG;

char edge[7]={0xda,0xc4,0xbf,0xb3,0xd9,0xc0,'/0'};

/* char edge1[7]={}; */

#define INUM  10     /* R maximum IO itenls in each MENU w */

typedef struct _menu
     {
     char coor[4];               /*  The menu's area w */
     char itemcoor[4 * INUM];    /*  max IO item, each with xl,yl ,x2,y2 w */
     char itemdispxy[2 * INUM] ; /*  Actually disp item name's X coor w */
     char select;                /*  selected item's ord # */
     char itemnum;               /*  The number of items in this menu w */
     char **itemname;            /* w item's name(point to static data) R */
     int COMMAND_ID[INUM];       /* w Key number R */
}MENUTYPE ;

static char * MainMenuItem[]= {" File "," Edit "," Run "," Compile "," Help ",
    " Exit ", 0 };
static char *Syshelp=" F1-Help F5-Zoom F6-Switch F7-Trace F8-Step F9-Make F10-Menu";

static char * SubMenuItem1[]= {" Load File...   F3 ",
          " Pick File  Alt+F3 ",
          " New               ",
          " Save           F2 ",
          " Write to          ",
          " Os Shell          ",
          " Quit        Alt+X ",0};
/*
static char *SubMenuItem[6][]={{"Help11..."},
          {
*/
static char * SubMenuItem2[]= {" Item21...",
          " Draw     ",
          " Item23   ",
          " Item24   ",
          " Item25   ",
          " Item26   ",
          " Item27   ",
          " Item28   ",0};

static char * SubMenuItem3[]= {" Item31...   ",
          " Item32...   ",
          " Item add... ",
          " Item33      ", 0 };
static char * SubMenuItem4[]= {" Item41...   ",
          " Item42...   ",
          " Moving Text ",
          " Item44      ",
          " Item45      ",
          " item **     ", 0} ;
static char * SubMenuItem5[]= {" Help Index  F1 ",
          " About...       ",
          " System Info    ",0};

static char * SubMenuItem6[]= {0};

void getitemcount(char ** ,int * ,int * ,int * );

void LoadMainMenu(void);

void LoadSubMenu(char **name, int ord);

int ManageSubMenu (void ) ;

void ManageMainMenu (void) ;
void DisplayMainMenu (void ) ;
int  DisplaySubMenu (int ord) ;
void Help_page_show(void) {return ; } ;
void Exitmenu (int) ;
void In_ActiveMainMenuItem(int select , char In_Active) ;
void In_ActiveSubMenuItem(int ord , int select , char In_Active) ;
int  GetKey (void) ;
void FuncProc (int ID) ;
void Draw(void) ;
void MoveText (void) ;
void About (void) ;
void MessageBox(char * Message) ;
void GoodBye(char * pcInf1 , char * pcInf2) ;

void win();
char gettextattrib();
void settextattrib();
void cprintfxy();

char *textbuf;
MENUTYPE MainMenu , SubMenu[INUM] ;
/* int maxx, texth, textw; */

void main(void)
{

 clrscr();
 win(0,1,SCREENMAXX+1,SCREENMAXY,'/xb0',BLUE<<4|LIGHTSHOW(GREEN));
 cprintfxy(25,9,"Analytic Hierarchy Process",BLUE<<4|BLACK);

 cprintfxy(26,11,"Howard.Hsu & WeiGuoZhang",BLUE<<4|BLACK);
 cprintfxy(33,18,"05/18/2000",BLUE<<4|BLACK);
 win(0,24,80,1,' ',WHITE<<4|BLUE);
 LoadMainMenu();
 LoadSubMenu (SubMenuItem1 , 0);
 LoadSubMenu (SubMenuItem2 , 1);
 LoadSubMenu (SubMenuItem3 , 2);
 LoadSubMenu (SubMenuItem4 , 3);
 LoadSubMenu (SubMenuItem5 , 4);
 LoadSubMenu (SubMenuItem6 , 5);
 ManageMainMenu();
}

 


void  prncharxy(char xpos,char ypos,char ch,char attrib)
{
 char far *p=(char far *)0xb8000000;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;

 *(p+ypos%25*160+2*(xpos%80))=ch;
 *(p+ypos%25*160+2*(xpos%80)+1)=attrib;
 return;
}


void cprintfxy(char xpos,char ypos,char *string,char attrib)
{
 int len,i;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;
 len=strlen(string);
 for(i=0;i<len;i++)
    prncharxy(xpos+i,ypos,string[i],attrib);
 return;
}

void vcprintfxy(char xpos,char ypos,char string[],char attrib)
{
 int len,i;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;
 len=strlen(string);
 for(i=0;i<len;i++)
    prncharxy(xpos,ypos+i,string[i],attrib);
 return;
}

void drawbox(char xpos,char ypos,char width,char heigh,
      char *edge,char attrib,char *title){

char i,j,len;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;

prncharxy(xpos,ypos,edge[0],attrib);
prncharxy(xpos+width-1,ypos,edge[2],attrib);
prncharxy(xpos+width-1,ypos+heigh-1,edge[4],attrib);
prncharxy(xpos,ypos+heigh-1,edge[5],attrib);
for(i=0;i<width-2;i++){
   prncharxy(xpos+i+1,ypos,edge[1],attrib);
   prncharxy(xpos+i+1,ypos+heigh-1,edge[1],attrib);
}
for(i=0;i<heigh-2;i++){
   prncharxy(xpos,ypos+i+1,edge[3],attrib);
   prncharxy(xpos+width-1,ypos+i+1,edge[3],attrib);
}
len=strlen(title);
cprintfxy(xpos+width/2-len/2,ypos,title,attrib);

for(i=0;i<heigh;i++)
{
 settextattrib(xpos+width,ypos+i+1,(BLACK<<4)|(WHITE));
 settextattrib(xpos+width+1,ypos+i+1,(WHITE)|(WHITE));

}
for(i=0;i<width-2;i++)
 settextattrib(xpos+2+i,ypos+heigh,(BLACK<<4)|(WHITE));


 for(i=1;i<heigh-1;i++)
   for(j=1;j<width-1;j++)
      prncharxy(xpos+j,ypos+i,' ',attrib);

 return;
}

void win(char xpos,char ypos,char width,char heigh,char ch,char attrib)
{
 char i,j;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;
 for(i=0;i<heigh;i++)
   for(j=0;j<width;j++)
      prncharxy(xpos+j,ypos+i,ch,attrib);
 return;
}

char *malloctextbuf(char width,char heigh)
{
 char *buf;
 if((buf=(char *)malloc(2*width*heigh*sizeof(char)))==NULL)
    return NULL;
 else
    return buf;
}


void gettextxy(char xpos,char ypos,char width,char heigh,char *buf)
{
 char i,j;
 char far *vp=(char far *)0xb8000000;

 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;

 if(xpos+width>SCREENMAXX)
    width=SCREENMAXX+1-xpos;
 if(xpos+heigh>SCREENMAXY)
    heigh=SCREENMAXY+1-ypos;

 for(i=0;i<heigh;i++)
    for(j=0;j<2*width;j++)
 buf[i*2*width+j]=*(vp+(ypos+i)%25*160+2*(xpos%80)+j);
 return;
}

char gettextattrib(char xpos,char ypos){
  char far *p=(char far *)0xb8000000;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;
 return(*(p+ypos%25*160+2*(xpos%80)+1));
}

void settextattrib(char xpos,char ypos,char attrib){
 char far *p=(char far *)0xb8000000;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
    return;
 *(p+ypos*160+2*xpos+1)=attrib;
 return;

}

void puttextxy(char xpos,char ypos,char width,char heigh,char *buf)
{
 char i,j,w,h;
 char far *vp=(char far *)0xb8000000;
 if(xpos<SCREENMINX || xpos>SCREENMAXX ||
    ypos<SCREENMINY || ypos>SCREENMAXY)
   return;
 if(xpos+width>SCREENMAXX)
    w=SCREENMAXX+1-xpos;
 else
    w=width;
 if(ypos+heigh>SCREENMAXY)
    h=SCREENMAXY+1-ypos;
 else
    h=heigh;

 for(i=0;i<h;i++)
    for(j=0;j<2*w;j++)
 *(vp+(ypos+i)%25*160+2*(xpos%80)+j)=buf[i*2*width+j];
 return;
}


void ManageMainMenu (void )
{
     unsigned key;
     int ID;
     DisplayMainMenu();
     for(key=0;;)
     {
     key=GetKey() ;
     switch(key)
     {
     case LEFT :
   In_ActiveMainMenuItem(MainMenu.select ,0) ;
   if(MainMenu.select<1)  /* w Already leftest item in mainmenu # */
      MainMenu.select =MainMenu.itemnum - 1 ;
   else
      MainMenu.select--;
   In_ActiveMainMenuItem(MainMenu.select , 1 ) ; /* R Light bar N */
   break ;

     case RIGHT :
   In_ActiveMainMenuItem(MainMenu.select , 0);
   if(MainMenu.select>MainMenu.itemnum-2)
      MainMenu.select=0;
   else
      MainMenu.select++;
   In_ActiveMainMenuItem(MainMenu.select,1);

   break;

     case DOWN:
     case RETURN:

   switch(MainMenu.COMMAND_ID[MainMenu.select] ){
   case 5: /*# Exit to DOS # */
        if (key==DOWN)
    break ;
        GoodBye ("Goodbye from ", "the MENU DEMO in graphics mode.");
        break ;
   default :

        ID = ManageSubMenu ();
        if (ID >=0)
    FuncProc (ID);
        break ;
   }
     }
   }
}

void FuncProc (int ID)
     {
     char *buf;
     switch ( ID ){
  case 6: /*w 006 FileIQuit # */

       GoodBye("Goodbye from ", "the BvIENU DEMO in graphics mode. ") ;
       break ;
  case 101:
       Draw() ;
       break ;
  case 302:
       MoveText();
       break ;
  case 401:
       About ( ) ;
       break ;
  default :
       buf=malloctextbuf(30+2,8+1);
       gettextxy(25,10,30+2,8+1,buf);
       drawbox(25,10,30,8,edge,RED<<4|GREEN," MessgeBox ");
       getch();
       puttextxy(25,10,30+2,8+1,buf);
              free(buf);
       break ;
  }
     }


     /*  ManageSubMenu() retarn an int value that is s /
     /#  Il there is a error # /
     /#  Return to main menu, nothing to do # /
     /  =O or =>O; the COMMAND_ID of a menu item w */

int ManageSubMenu (void)
     {

     MENUTYPE * mn = &SubMenu[MainMenu.select] ;
     unsigned key ;
     if(DisplaySubMenu(MainMenu.select)) /* w Out of memory * */
 return -2;
     for(key=0;;)
     {
       key=GetKey () ;
       switch (key ){
       case ESC: /* # return to MainMenu # */
     Exitmenu(MainMenu.select);
     return -1 ;

       case UP:
     In_ActiveSubMenuItem(MainMenu.select , mn->select,0);
     if(mn->select>0)
       mn->select--;
     else
       mn->select = mn->itemnum - 1 ;
     In_ActiveSubMenuItem(MainMenu.select , mn->select ,1 );
     break ;
       case DOWN:
     In_ActiveSubMenuItem (MainMenu. select , mn ->select , 0);
     if (mn ->select<mn ->itemnum - 1 )
        mn->select++;
     else
        mn->select=0;
     In_ActiveSubMenuItem (MainMenu.select , mn->select ,1);
     break ;
       case LEFT:
     Exitmenu (MainMenu.select);
     In_ActiveMainMenuItem (MainMenu.select , 0);
     if(MainMenu.select<1) /* e Already leftest item in mainmenu w */
        MainMenu.select = MainMenu.itemnum- 1 ;
     else
        MainMenu.select-- ;
     In_ActiveMainMenuItem(MainMenu.select , 1) ; /* # Light bar e */
     if(DisplaySubMenu(MainMenu.select) )/* Out of mentory w */

        return -2;
      mn= &SubMenu[MainMenu.select] ;

      break ;
       case RIGHT :
     Exitmenu (MainMenu.select ) ;
     In_ActiveMainMenuItem(MainMenu.select , 0);
     if(MainMenu.select>MainMenu.itemnum-2)/* # already rightest w */
        MainMenu.select = 0;
     else
        MainMenu.select++ ;
     In_ActiveMainMenuItem (MainMenu.select , 1);
     if (DisplaySubMenu(MainMenu.select) ) /* # Out of memory w */
         return -2 ;
     mn = &SubMenu[MainMenu. select];
     break ;
       case RETURN :
     Exitmenu (MainMenu.select );
     return mn->COMMAND_ID[mn->select] ;
   }
     }
}

void LoadMainMenu()
     {
     int count ,totallen ,maxlen ,i;
     int beginx;
     MainMenu.coor[0]= SCREENMINX;
     MainMenu.coor[1] =SCREENMINY;
     MainMenu.coor[2] =SCREENMAXX;
     MainMenu.coor[3] =SCREENMINY;

     getitemcount(MainMenuItem, &count ,&totallen ,&maxlen) ;

     MainMenu.itemnum =count ;
     beginx=3;
     for(i= 0;i<count;i++)
     {
     MainMenu.itemcoor[i*4] = beginx; /* w xl # */
     MainMenu.itemcoor[i*4+1] = MainMenu.coor[1]; /* w yl w */
     MainMenu.itemcoor[i*4+2] = beginx+strlen(MainMenuItem[i]); /* # x2 # */
     MainMenu.itemcoor[i*4+3] = MainMenu.coor[3];

     MainMenu.itemdispxy[i*2] = beginx; /* w actuall disp X w */
     MainMenu.itemdispxy[i*2+1] = MainMenu.coor[3]; /* w actuall disp Y w */

     MainMenu.COMMAND_ID[i] = i ;

     beginx=beginx+strlen(MainMenuItem[i])+1;
     }
     MainMenu.itemname = MainMenuItem ;
}

void LoadSubMenu(char ** name ,int ord)
     {
     int count ,i ,j ,maxlen;
     getitemcount(name , &count , &i , &maxlen) ;
     SubMenu[ord].itemname = name ;

     SubMenu [ord].itemnum =count ;
     j=maxlen+1;
     if(j+MainMenu.itemcoor[4 * ord]<WindowMaxX) /* w left text justification is OK # */
     {
     SubMenu[ord].coor[0] =MainMenu.itemcoor[4 * ord]; /*w item's xl w */
     SubMenu[ord].coor[2] =SubMenu[ord].coor[0] +j ;
     }
     else /* w Use right justification because of space w */
     {
      SubMenu[ord].coor[2]=MainMenu.itemcoor[2]; /* # left just use X2 w */
      SubMenu[ord].coor[0] =SubMenu[ord].coor[2] -j;
     }

     if(count==0)
     {
      SubMenu[ord].coor[1] =SubMenu[ord].coor[1]+1; /* w The item's y2*/
      SubMenu[ord].coor[3] =SubMenu[ord].coor[1];
     }

     else
     {
     SubMenu[ord].coor[1]=MainMenu.itemcoor[4*ord+3]+1;
     SubMenu[ord].coor[3]=SubMenu[ord].coor[1] + count+1;
     }
     for(i=0;i<count;i++)
     {
     SubMenu[ord].itemcoor[i * 4] =SubMenu[ord].coor[0]+1;
     SubMenu[ord].itemcoor[i * 4+1]=SubMenu[ord].coor[1]+i+1;
     SubMenu[ord].itemcoor[i * 4+2] =SubMenu[ord].coor[2]-1;
     SubMenu[ord].itemcoor[i * 4+3] = SubMenu[ord].itemcoor[i * 4+1] +i+1;

     SubMenu[ord].itemdispxy[i * 2] =SubMenu[ord].itemcoor[i * 4];
     SubMenu[ord].itemdispxy[i * 2+1] =SubMenu[ord].itemcoor[i * 4+1];
     SubMenu[ord].COMMAND_ID[i] = ord * 100+i ;
     }
}

void DisplayMainMenu (void )
     {
     unsigned i ;
     win(MainMenu.coor[0],MainMenu.coor[1],80,1,' ',WHITE<<4|BLACK);
     for(i= 0 ;i<MainMenu.itemnum ;i++)
     {
     if(MainMenu.select==i)
 In_ActiveMainMenuItem (i , 1) ;
     else
       cprintfxy (  MainMenu.itemdispxy[i * 2],
      MainMenu.itemdispxy[i * 2+1] ,
      MainMenu.itemname[i],WHITE<<4|BLACK) ;
     }
}

char *textbuf;

int DisplaySubMenu (int ord )
{
     unsigned size , i;
     MENUTYPE * mn = &SubMenu[ord] ;
     textbuf=NULL;
     textbuf=malloctextbuf(mn->coor[2]-mn->coor[0]+1+2,
   mn->coor[3]-mn->coor[1]+1+1);
     if(textbuf==NULL)
       {
 clrscr();
 printf("/nOut of memory!");
 printf("/nPress any key...");
 getch();
 return 1;
       }
     if(mn->coor[1]==mn->coor[3])
       return 0;
     gettextxy(mn->coor[0],mn->coor[1],
        mn->coor[2]-mn->coor[0]+1+2,
        mn->coor[3]-mn->coor[1]+1+1,textbuf);

     drawbox(mn->coor[0],mn->coor[1],
      mn->coor[2]-mn->coor[0]+1,
      mn->coor[3]-mn->coor[1]+1,edge,WHITE<<4|BLACK,"");

     for(i =0;i<mn->itemnum ;i++)
     {
     if(i==mn->select)
 In_ActiveSubMenuItem(ord , i , 1);
     else
     {
      cprintfxy(mn->itemdispxy[i*2],mn->itemdispxy[i*2+1],mn->itemname[i],WHITE<<4|BLACK);
     }
     }
     return 0 ;

}


static void Exitmenu (int ord )
     {
      MENUTYPE  *mn=&SubMenu[ord] ;
      if(textbuf)
     {
      puttextxy(mn->coor[0],mn ->coor[1],mn->coor[2]-mn->coor[0]+1+2,
  mn->coor[3]-mn->coor[1]+1+1,textbuf);
      free (textbuf);
     }
}

void In_ActiveMainMenuItem(int select , char In_Active)
{
     MENUTYPE * tp = &MainMenu ;


     if (In_Active==0) /* H off w */
     {
     cprintfxy (tp->itemdispxy[select * 2] ,
  tp->itemdispxy[select * 2+ 1] ,
  tp ->itemname [select],(WHITE<<4)|BLACK) ;
     }
     else
     {
     cprintfxy (tp->itemdispxy[select * 2] ,
  tp->itemdispxy[select * 2+1] ,
  tp ->itemname [select],(GREEN<<4)|BLUE) ;
     }
}

void In_ActiveSubMenuItem(int ord , int select , char In_Active)
{
     MENUTYPE * tp =&SubMenu[ord] ;
     if (In_Active==0) /* w off w */
     {
      cprintfxy(tp->itemdispxy[select * 2] ,
  tp ->itemdispxy[select * 2+1],
  tp ->itemname [select],(WHITE<<4)|BLACK) ;
     }
     else
     {
     cprintfxy (tp->itemdispxy[select * 2] ,
  tp->itemdispxy[select *2+ 1],
  tp ->itemname[select],(GREEN<<4)|BLUE) ;
     }
}


int GetKey(void){
        int key;
        key=bioskey(0);
        if(key==F1)
          Help_page_show();
        else
          if(key<<8)
            {
             key=key&0x00ff;
             if(isalpha(key))
               key=toupper(key);
            }
        return key;
}

static void getitemcount(char ** s ,int * count,int * len,int * maxlen)
{
     int i,j;
     for(( * maxlen)=0,(*len)=0,i=0; s[i]!=NULL; i++)
     {
     j =strlen (s[i]);
     (*len)+=j;
     if(j>(*maxlen))
       ( * maxlen) =j ;
     }
     ( *count)=i;
}

void Draw(void)
{
     int x, x1, x2, y1, y2;
     randomize ( ) ;
     do
     {
     x1 = random (WindowMaxX-WindowMinX) +WindowMinX ;
     y1 = random (WindowMaxY-WindowMinY) +WindowMinY ;
     x2 = random (WindowMaxX-WindowMinX) +WindowMinX ;
     y2 = random (WindowMaxY-WindowMinY) +WindowMinY ;
     if (x1>x2)
     {
     x = x1; x1= x2; x2=x;
     }
     if (y1>y2)
     {
     x=y1;y1 =y2;y2=x;
     }
     if(y1<1)
 y1=1;
     if(y2>23)
 y2=23;
     win(x1,y1,x2-y1+1,y2-y1+1,' ',random(256));
     delay(100);
     }while(!bioskey(1));
}

void About (void)
     {
     char MidX, MidY, x1, y1, x2, y2, size;
     char *buf1;
     MidX = (WindowMaxX - WindowMinX)/2 ;
     MidY = (WindowMaxY - WindowMinY)/2 ;
     x1 = MidX-15;
     x2 = MidX+15;
     y1 = MidY-4;
     y2 = MidY+4;
     buf1=malloctextbuf(x2-x1+1+2,y2-y1+1+1);
     gettextxy(x1,y1,x2-x1+1+2, y2-y1+1+1,buf1) ;

/*     win(WindowMinX,WindowMinY,WindowMaxX, WindowMaxY,' ',BLUE); */
     if ( buf1==NULL)
     {
     clrscr();
     printf("/nOut of memory!Press any key to exit...");
     getch ( ) ;
     exit(1);
     }
     else
     {
      gettextxy(x1 ,y1 , x2-x1+1+2,y2-y1+1+1, buf1) ;
     drawbox(x1,y1,x2-x1+1,y2-y1+1,edge,WHITE," About... ");
     cprintfxy(MidX-strlen("Menu Demo")/2,MidY-2,"Menu Demo",RED);
     cprintfxy(MidX-strlen("In Text Mode")/2,MidY-1,"In Text Mode",RED);
     cprintfxy(MidX-strlen("05/2000 By")/2,MidY,"05/2000 By",RED);
     cprintfxy(MidX-strlen("Howard.Hsu")/2,MidY+1,"Howard.Hsu",RED);
     cprintfxy(MidX-strlen(" OK ")/2,MidY+2," OK ",GREEN);
     getch() ;
     puttextxy(x1,y1,x2-x1+1+2,y2-y1+1+1,buf1);
     free (buf1);
     }
}

void DrawButtonUp(unsigned char xpos,unsigned char ypos,
    char *message,char attrib)
{
 unsigned char len,i;
 char BackAttrib;
 BackAttrib= gettextattrib(xpos,ypos);
 len=strlen(message);
 prncharxy(xpos,ypos,' ',attrib);
 cprintfxy(xpos+1,ypos,message,attrib);
 prncharxy(xpos+len+1,ypos,' ',attrib);
 prncharxy(xpos+len+2,ypos,240,BackAttrib);
 for(i=0;i<=len+2;i++)
   prncharxy(xpos+i+1,ypos+1,220,BackAttrib);
 return;
}

void DrawButtonDown(unsigned char xpos,unsigned char ypos,
      char *message,char attrib)
{
 unsigned char len,i;
 char BackAttrib;
BackAttrib= gettextattrib(xpos,ypos+1);
 len=strlen(message);
 prncharxy(xpos,ypos,' ',BackAttrib);
 prncharxy(xpos+1,ypos,' ',attrib);
 cprintfxy(xpos+2,ypos,message,attrib);
 prncharxy(xpos+len+2,ypos,' ',attrib);
 for(i=0;i<=len+2;i++)
   prncharxy(xpos,ypos+1,' ',BackAttrib);
 return;
}


void MessageBox(char * Message)
{
     int MidX, MidY, x1, y1, x2, y2, size, Len;
     char *buf1;
     MidX = (WindowMaxX - WindowMinX)/2 ;
     MidY = (WindowMaxY - WindowMinY)/2 ;
     Len = strlen(Message)>strlen(" MessageBox ")?strlen(Message):strlen(" MessageBox ");
     x1 = MidX-Len;
     x2=MidX+Len;
     y1=MidY-4;
     y2=MidY+4;
     buf1=malloctextbuf(x2-x1+1+2,y2-y1+1+1);
     if ( buf1==NULL)
     {
     clrscr();
     printf("/nOut of memory! Press any key to continue...");
     getch( );
     exit(1);
     }
     else
     {
     gettextxy(x1 ,y1 , x2-x1+1+2,y2-y1+1+1, buf1) ;
     drawbox(x1,y1,x2-x1+1,y2-y1+1,edge,GREEN<<4|RED," MessageBox ");
     cprintfxy(MidX-strlen(Message)/2,MidY-1,Message,GREEN<<4|BLUE);

     DrawButtonUp(MidX-strlen("OK")/2-2,MidY+2,"OK",RED);
     getch();
     DrawButtonDown(MidX-strlen("OK")/2-2,MidY+2,"OK",RED);
     delay(5000);

     puttextxy(x1 ,y1 ,x2-x1+1+2,y2-y1+1+1,buf1) ;
     free(buf1) ;
     }
}

void MoveText (void )
{
     int i;
     char attrib;
     win(0,1,80,23,' ',0);
     for (i=random(80); i>1; i-=2)

     {

     attrib= gettextattrib(i,14);
     cprintfxy(i ,14, "Menu example !",((BLUE<<4)&0x80)|RED) ;
     delay(2000) ;
     cprintfxy(i,14,  "              ",attrib);

     }
}

void GoodBye(char * pcInf1 , char * pcInf2)
{
     int f;
     clrscr ( );
     window(1 ,1 ,80,1) ;
     textbackground (LIGHTBLUE ) ;
     clrscr() ;
     highvideo ( );
     textcolor(WHITE);
     cprintf(pcInf1);
     textcolor(YELLOW);
     cprintf(pcInf2);
     window(1,1,80,25);
     printf("/n");
     for(f=400;f<800;f+=100)
      {
       sound(f);
       delay(100);
      }
     nosound();
     exit(0);
}

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

打赏
文章很值,打赏犒劳作者一下
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页

打赏

cutemouse

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值