签到

06月21日
尚未签到

共有回帖数 0

    懂得生活的人

    等级:
    有一段时间想编写图形化界面,用的是dos的图形函数,后来发现根本不实用.但已经编写一部分了.给大家看看.学c语言6个月后编写的,希望能对出学者一些启发~~本来很顺畅,但由于源码乱改,不知哪个没有bug了,就随手捡一个出来.  
    很简陋,不吝赐教,谢谢----badming  
    主文件main.c(一楼)  
    汉字包文件:hanzi.c(2-3楼)  
    窗体文件包文件:win_body.c(4楼)  
    鼠标文件包:mouse.c(5楼)  
    /////这个保存为main.c////  
    /* WIN-TC BGI 图形编程模板 */  

    #include "Conio.h"  
    #include "graphics.h"  
    #include "dos.h"  
    #include "mouse.c"  
    #include "hanzi.c"  
    #include "win_body.c"  
    #define closegr closegraph  
    #define NULL 0  
    void initgr(void) /* BGI初始化 */  
    {  
    int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */  
    registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */  
    initgraph(&gd, &gm, "");  
    }  
    /****************************************************************************/  

    struct b_window_body full={  
    1,  
    1,1,639,477,  
    "working",  
    0,{0},{0},{0},  
    13,{0},{0x1002,0x1002,0x1002,0x1002,0x1002,0xc02,0xc02,0xc02,0xc02,0xc02,0xc02,0xc02,0xc02},  
    {6,50,94,138,182,6,40,76,112,148,184,220,256},/*(字号+4)*n+4*/  
    {24,24,24,24,24,48,48,48,48,48,48,48,48},  
    {1,2,3,0,4,5,6,7,8,9,10,11,12},  
    0,0,0,0,  
    0,bad_f};  
    struct b_window_body xin={  
    1,  
    200,200,400,360,  
    "new",  
    0,{0},{0},{0},  
    3,{0},{0x1003,0x1002,0x1002},  
    {206,294,338},  
    {300,300,300},  
    {15,14,13},  
    1,0,220,250,  
    0,bad_f};  

    struct b_file{  
    int choice;  
    int num;  
    int open;  
    int sex;  
    char name[20];  
    struct b_file * parent;  
    struct b_file * l_brother;  
    struct b_file * r_brother;  
    struct b_file * child;  
    }root={0,1,1,1,"root",0,0,0,0},  
    bad1={0,1,0,1,"bad",&root,0,0,0},  
    bad2={0,2,0,0,"bad",&root,0,0,0},  
    bad3={0,3,0,1,"bad",&root,0,0,0},  
    bad4={0,5,0,1,"bad",0,0,0,0},*living,*lived;  
    draw_file(struct b_file *p)  
    {int midx,midy;  
    midx=(p-num-1)%12*50+30;  
    midy=(p-num-1)/12*60+30+70;  
    setcolor(13-p-choice);  
    rectangle(midx-20,midy-20,midx+20,midy+20);  
    if(p-sex==1)circle(midx,midy,5);  
    outtextxy(midx-20,midy+25,p-name);  
    }  
    look_file(struct b_file *p)  
    {  
    setfillstyle(1,15);  
    bar(5,70,636,476);  
    if(p-open==0){ /*文件或每打开的文件夹*/  
    if(p-l_brother!=0)p=p-parent-child;/*有左兄弟到大哥那里*/  
    loop:draw_file(p);if(p-r_brother!=0){p=p-r_brother;goto loop;}}  
    else if(p-child!=0){p=p-child;goto loop;}  


    }  
    open_file(struct b_file *p)  
    {if(p-sex==1)p-open=1;  
    look_file(p);  
    }  
       
    back_file()/*注意!改变了living 的指向!!!*/  
    {  
    if(living-parent!=0)if(living-open==0){living-choice=0;living=living-parent;}/*有父亲,是文件或每打开的文件夹*/  
    living-open=0;living-choice=1;  
    look_file(living);  
    }  
    search_file(x,y)  
    {  
    int i=1,midx,midy;  
    struct b_file *q;  
    q=living;  
    if(living-sex==1&&living-open==1){ /*一个打开的文件家*/  
    if(living-child!=0){living=living-child;}/*有害子则到孩子*/  
    else return;  
    }  
    else if(living-l_brother!=0)living=living-parent-child; /*有左兄弟,到大哥*/  
    while(i)  
    {  
    midx=(living-num-1)%9*50+30;  
    midy=(living-num-1)/6*30+30+70;  
    if(x=midx-20&&x=midx+20&&y=midy-20&&y=midy+25)  
    {q-choice=0;living-choice=1;i=0; look_file(living); }  
    else if(living-r_brother!=0){living=living-r_brother;}  
    else {living=q;living-choice=1;i=0;}  

    }  

    }  

    new_file(n)  
    {lived=(struct b_file *)malloc(sizeof(struct b_file));  
    if(living-open==1&&living-child==0){lived-parent=living;living-child=lived; lived-sex=n;  
    lived-choice=1;  
    living=lived;lived-num=1;return;}  
    if(living-open==1&&living-child!=0)living=living-child;  
    if(living-open==0)living-choice=0;  
    while(living-r_brother!=0)living=living-r_brother;  
    living-r_brother=lived;lived-l_brother=living;lived-parent=living-parent;  
    lived-num=living-num+1;  
    lived-sex=n;  
    lived-choice=1;  
    living=lived;  
    }  

    thing(n)/*按调用号对事件的具体处理*/  
    {  
    switch(n)  
    {  
    case 0:closegr();exit(0);break;  
    case 1:b_window_draw(xin);xin.power=1;while(xin.power)(*xin.f)(&xin);look_file(living);break;  
    case 2:open_file(living);break;  
    case 3:back_file();break;  
    case 13:xin.power=0;break;  
    case 14:new_file(1);xin.power=0;break;  
    case 15:new_file(2);xin.power=0;break;  
    }  
    }  
    int main(void)  
    { int i;  
    initgr(); /* BGI初始化 */  
    b_window_draw(full);  
    hanzi();  
    living=&root;  
    root.child=&bad1;  
    bad1.r_brother=&bad2;  
    bad2.l_brother=&bad1;  
    bad2.r_brother=&bad3;  
    bad3.l_brother=&bad2;  
    bad3.child=&bad4;  
    bad4.parent=&bad3;  
    thing(2);  
    while(1){  

    (*full.f)(&full);  
    }  
    getch();  
    closegr(); /* 恢复TEXT屏幕模式 */  
    return 0;  
    }  
    /////这个保存为hanzi.c/////  
    char tui16S[]={  
    /* 以下是 '退' 的 16点阵宋体 字模,32 byte */  
    0x40,0x00,0x27,0xF0,0x24,0x10,0x07,0xF0,  
    0x04,0x10,0x04,0x10,0xE7,0xF0,0x24,0x88,  
    0x24,0x50,0x24,0x20,0x25,0x10,0x26,0x18,  
    0x24,0x08,0x50,0x00,0x8F,0xFE,0x00,0x00,  
    };  
    char chu16S[]={  
    /* 以下是 '出' 的 16点阵宋体 字模,32 byte */  
    0x01,0x00,0x01,0x00,0x21,0x04,0x21,0x04,  
    0x21,0x04,0x21,0x04,0x3F,0xFC,0x21,0x04,  
    0x01,0x00,0x21,0x04,0x21,0x04,0x21,0x04,  
    0x21,0x04,0x3F,0xFC,0x20,0x04,0x00,0x00,  
    };  
    char xin16S[]={  
    /* 以下是 '新' 的 16点阵宋体 字模,32 byte */  
    0x10,0x00,0x08,0x0E,0x7F,0x70,0x22,0x40,  
    0x14,0x40,0xFF,0x7E,0x08,0x48,0x08,0x48,  
    0xFF,0x48,0x08,0x48,0x2C,0x48,0x2A,0x88,  
    0x4A,0x88,0x89,0x08,0x2A,0x08,0x10,0x08,  
    };  
    char jian16S[]={  
    /* 以下是 '建' 的 16点阵宋体 字模,32 byte */  
    0x00,0x40,0x78,0x40,0x0B,0xF8,0x10,0x48,  
    0x17,0xFE,0x20,0x48,0x7B,0xF8,0x08,0x40,  
    0x4B,0xFC,0x48,0x40,0x28,0x40,0x17,0xFC,  
    0x28,0x40,0x46,0x40,0x81,0xFE,0x00,0x00,  
    };  
    char da16S[]={  
    /* 以下是 '打' 的 16点阵宋体 字模,32 byte */  
    0x10,0x00,0x10,0x00,0x13,0xFE,0x10,0x20,  
    0xFE,0x20,0x10,0x20,0x14,0x20,0x18,0x20,  
    0x30,0x20,0xD0,0x20,0x10,0x20,0x10,0x20,  
    0x10,0x20,0x10,0x20,0x50,0xA0,0x20,0x40,  
    };  
    char kai16S[]={  
    /* 以下是 '开' 的 16点阵宋体 字模,32 byte */  
    0x00,0x00,0x7F,0xFE,0x04,0x20,0x04,0x20,  
    0x04,0x20,0x04,0x20,0xFF,0xFE,0x04,0x20,  
    0x04,0x20,0x04,0x20,0x08,0x20,0x08,0x20,  
    0x10,0x20,0x20,0x20,0x40,0x20,0x00,0x00,  
    };  


    char hou16S[]={  
    /* 以下是 '后' 的 16点阵宋体 字模,32 byte */  
    0x00,0x7C,0x1F,0x80,0x10,0x00,0x10,0x00,  
    0x1F,0xFC,0x10,0x00,0x10,0x00,0x10,0x00,  
    0x17,0xF8,0x24,0x08,0x24,0x08,0x24,0x08,  
    0x47,0xF8,0x44,0x08,0x84,0x08,0x00,0x00,  
    };  
    char da12S[]={  
    /* 以下是 '打' 的 12点阵宋体 字模,24 byte */  
    0x20,0x00,0x27,0xE0,0xF8,0x80,0x20,0x80,  
    0x20,0x80,0x38,0x80,0xE0,0x80,0x20,0x80,  
    0x20,0x80,0x20,0x80,0xE3,0x80,0x00,0x00,  
    };  
    char kai12S[]={  
    /* 以下是 '开' 的 12点阵宋体 字模,24 byte */  
    0x00,0x40,0x7F,0xE0,0x11,0x00,0x11,0x00,  
    0x11,0x00,0xFF,0xE0,0x11,0x00,0x11,0x00,  
    0x11,0x00,0x21,0x00,0xC1,0x00,0x00,0x00,  
    };  
    char jian12S[]={  
    /* 以下是 '剪' 的 12点阵宋体 字模,24 byte */  
    0x11,0x00,0xFF,0xE0,0x48,0x40,0x7A,0x40,  
    0x4A,0x40,0x7A,0x40,0x48,0xC0,0x00,0x00,  
    0x7F,0xC0,0x08,0x40,0x73,0x80,0x00,0x00,  
    };  
    char qie12S[]={  
    /* 以下是 '切' 的 12点阵宋体 字模,24 byte */  
    0x20,0x20,0x2F,0xE0,0x21,0x20,0x39,0x20,  
    0xE1,0x20,0x21,0x20,0x22,0x20,0x2A,0x20,  
    0x34,0x20,0x28,0x20,0x11,0xC0,0x00,0x00,  
    };  
    char fu12S[]={  
    /* 以下是 '复' 的 12点阵宋体 字模,24 byte */  
    0x10,0x40,0x3F,0xE0,0x60,0x80,0xBF,0x80,  
    0x20,0x80,0x3F,0x80,0x10,0x00,0x1F,0x80,  
    0x69,0x00,0x06,0x00,0xF9,0xE0,0x00,0x00,  
    };  
    char zhi12S[]={  
    /* 以下是 '制' 的 12点阵宋体 字模,24 byte */  
    0x10,0x20,0x54,0x20,0x7E,0xA0,0x90,0xA0,  
    0xFE,0xA0,0x10,0xA0,0x7E,0xA0,0x52,0xA0,  
    0x52,0x20,0x56,0x20,0x10,0xE0,0x00,0x00,  
    };  
    char zhan12S[]={  
    /* 以下是 '粘' 的 12点阵宋体 字模,24 byte */  
    0x21,0x00,0xA9,0x00,0x71,0xE0,0x21,0x00,  
    0xFD,0x00,0x21,0x00,0x77,0xE0,0xAC,0x20,  
    0xA4,0x20,0x24,0x20,0x27,0xE0,0x00,0x00,  
    };  
    char tie12S[]={  
    /* 以下是 '贴' 的 12点阵宋体 字模,24 byte */  
    0xF9,0x00,0x89,0x00,0xA9,0xE0,0xA9,0x00,  
    0xA9,0x00,0xAB,0xE0,0xAA,0x20,0xAA,0x20,  
    0x52,0x20,0x4B,0xE0,0x82,0x20,0x00,0x00,  
    };  
    char shan12S[]={  
    /* 以下是 '删' 的 12点阵宋体 字模,24 byte */  
    0x77,0x20,0x55,0x20,0x55,0x20,0x55,0x20,  
    0x55,0x20,0xFF,0xA0,0x55,0x20,0x55,0x20,  
    0x55,0x20,0x55,0x20,0xBB,0x60,0x00,0x00,  
    };  
    char chu12S[]={  
    /* 以下是 '除' 的 12点阵宋体 字模,24 byte */  
    0xF1,0x00,0x92,0x80,0xA4,0x40,0xA8,0x20,  
    0xA7,0xC0,0x91,0x00,0x9F,0xE0,0xF1,0x00,  
    0x85,0x40,0x89,0x20,0x93,0x20,0x00,0x00,  
    };  
    char ming12S[]={  
    /* 以下是 '命' 的 12点阵宋体 字模,24 byte */  
    0x04,0x00,0x0A,0x00,0x11,0x00,0x3F,0x80,  
    0xC0,0x60,0x7B,0xC0,0x4A,0x40,0x4A,0x40,  
    0x7A,0x40,0x4A,0xC0,0x02,0x00,0x00,0x00,  
    };  
    char ming122S[]={  
    /* 以下是 '名' 的 12点阵宋体 字模,24 byte */  
    0x08,0x00,0x0F,0xC0,0x10,0x80,0x31,0x00,  
    0x4A,0x00,0x04,0x00,0x0F,0xC0,0x30,0x40,  
    0xD0,0x40,0x10,0x40,0x1F,0xC0,0x00,0x00,  
    };  
    char shua12S[]={  
    /* 以下是 '刷' 的 12点阵宋体 字模,24 byte */  
    0x7E,0x20,0x42,0xA0,0x7E,0xA0,0x48,0xA0,  
    0x48,0xA0,0x7E,0xA0,0x6A,0xA0,0xAA,0xA0,  
    0xAA,0xA0,0x2E,0x20,0x08,0xE0,0x00,0x00,  
    };  
    char xin12S[]={  
    /* 以下是 '新' 的 12点阵宋体 字模,24 byte */  
    0x10,0x60,0xFD,0x80,0x49,0x00,0x29,0x00,  
    0xFD,0xE0,0x11,0x40,0xFD,0x40,0x59,0x40,  
    0x55,0x40,0x92,0x40,0x34,0x40,0x00,0x00,  
    };  
    char bang16S[]={  
    /* 以下是 '帮' 的 16点阵宋体 字模,32 byte */  
    0x04,0x00,0x3F,0xBE,0x04,0x24,0x3F,0xA8,  
    0x04,0x28,0x7F,0xA4,0x04,0x32,0x08,0xAC,  
    0x10,0xA0,0x2F,0xF8,0x48,0x88,0x08,0x88,  
    0x08,0xA8,0x08,0x90,0x00,0x80,0x00,0x80,  
    };  
    char zhu16S[]={  
    /* 以下是 '助' 的 16点阵宋体 字模,32 byte */  
    0x00,0x20,0x3E,0x20,0x22,0x20,0x22,0x20,  
    0x22,0xFC,0x3E,0x24,0x22,0x24,0x22,0x24,  
    0x3E,0x24,0x22,0x24,0x22,0x44,0x27,0x44,  
    0xF8,0x84,0x01,0x14,0x02,0x08,0x00,0x00,  
    };  





    void drawmat(char *mat,int matsize,int x,int y,int color)  
    /*依次:字模指针、点阵大小、起始坐标(x,y)、颜色*/  
    {int i,j,k,n;  
    n=(matsize-1)/8+1;  
    for(j=0;jmatsize;j++)  
    for(i=0;in;i++)  
    for(k=0;k8;k++)  
    if(mat[j*n+i]&(0x80k)) /*测试为1的位则显示*/  
    putpixel(x+i*8+k,y+j,color);  
    }  

    hanzi(){  
    drawmat(xin16S,16,8,26,6);/*对应按钮坐标横纵都+2,紧接的字横坐标+字号+4*/  
    drawmat(jian16S,16,24,26,6);  
    drawmat(da16S,16,52,26,6);  
    drawmat(kai16S,16,72,26,6);  
    drawmat(hou16S,16,94,26,6);  
    drawmat(tui16S,16,114,26,6);  
    drawmat(tui16S,16,140,26,6);  
    drawmat(chu16S,16,160,26,6);  
    drawmat(bang16S,16,184,26,6);  
    drawmat(zhu16S,16,204,26,6);  
    drawmat(da12S,12,8,50,6);  
    drawmat(kai12S,12,24,50,6);  
    drawmat(jian12S,12,44,50,6);  
    drawmat(qie12S,12,58,50,6);  
    drawmat(fu12S,12,78,50,6);  
    drawmat(zhi12S,12,94,50,6);  
    drawmat(zhan12S,12,114,50,6);  
    drawmat(tie12S,12,130,50,6);  
    drawmat(xin12S,12,150,50,6);  
    drawmat(jian12S,12,166,50,6);  
    drawmat(shan12S,12,186,50,6);  
    drawmat(chu12S,12,202,50,6);  
    drawmat(shua12S,12,222,50,6);  
    drawmat(xin12S,12,238,50,6);  
    }////保存为win_body.c////  
    /*函数说明:本函数快提供2中函数调用  
    1为b_window_draw(struct b_window_body p),用于初始化窗体;  
    2为船体结构体体struct b_window_body的设计,  
    存北京色无法完成。具体解释如下*/  
    struct b_window_body  
    {  
    int power;  
    int minx;  
    int miny;  
    int maxx;  
    int maxy;/*窗体框*/  
    /***********/  
    char *title;/*窗体标题*/  
    int word_num;/*提示信息的条数*/  
    char *word[13];/*信息内容*/  
    int word_x[13];/*信息的输出坐标*/  
    int word_y[13];  
    /**************/  
    int button;/*按钮的数目*/  
    int button_press[13];/*按键的状态*/  
    int button_mode[13];/*按键的模式,16进制数,前8为容纳字符数,后8为容纳字号大小点阵*/  
    int button_x[13];/*按键坐标*/  
    int button_y[13];  
    int button_thing[13];/*按键触发的事件*/  
    /******************/  
    int input;/*是否有输入*/  
    char *input_word;/*输入内容*/  
    int input_x;/*输入显示的坐标*/  
    int input_y;  
    /**************/  
    int *pic;/*所占据的背景储存*/  
    int (*f)();/*处理函数指针*/  
    };  
    draw_button(x,y,mode,press)  
    {int size,n;  
    size=mode8;  
    n=mode&255;  
    setcolor(15-press*8);line(x,y,x+(size+4)*n,y);line(x,y,x,y+(size+4));  
    setcolor(7+press*8);line(x,y+(size+4),x+(size+4)*n,y+(size+4));line(x+(size+4)*n,y,x+(size+4)*n,y+(size+4));  
    }  
    b_window_draw(struct b_window_body p)  
    {int i;  
    setbkcolor(15);  
    setcolor(13);  
    rectangle(p.minx,p.miny,p.maxx,p.maxy);  
    setfillstyle(1,1);  
    bar(p.minx+2,p.miny+2,p.maxx-2,p.miny+18);  
    line(p.minx,p.miny+20,p.maxx,p.miny+20);  
    setcolor(15);  
    outtextxy(p.minx+2,p.miny+6,p.title);  
    if(p.button!=0)for(i=0;i=p.button-1;i+=1)  
    draw_button(p.button_x,p.button_y,p.button_mode,p.button_press);  
    if(p.word_num!=0)for(i=0;i=p.word_num-1;i+=1){setcolor(13);outtextxy(p.word_x,p.word_y,p.word);}  
    }/*********************/  

    /*以下为函数的引用,基本的通用函数,必须家鼠标函数*/  
    int bad_f(struct b_window_body *p)  
    { int i;  
    if(mouse(3,0,0)==1)  
    {for(i=0;i=((*p).button-1);i+=1)  
    if(mousex=(*p).button_x&&mousex=((*p).button_x+((*p).button_mode&255)*(((*p).button_mode8)+4))  
    &&mousey=(*p).button_y&&mousey=(*p).button_y+((*p).button_mode8)+4)  
    {(*p).button_press=1;draw_button((*p).button_x,(*p).button_y,(*p).button_mode,(*p).button_press);  
    if(mouse(3,0,0)==0)thing((*p).button_thing);}if(mouse(3,0,0)==0)search_file(mousex,mousey);}  

    else for(i=0;i=((*p).button-1);i+=1)  
    if((*p).button_press==1){(*p).button_press=0;  
    draw_button((*p).button_x,(*p).button_y,(*p).button_mode,(*p).button_press);}  
    }




    .///这个保存为mouse.c////  
    #include "graphics.h"  
    #include "dos.h"  
    #define NULL 0  
    char mouseary[]={  
    /* 以下是 '☆' 的 16点阵宋体 字模,32 byte */  
    0x01,0x00,0x01,0x00,0x02,0x80,0x02,0x80,  
    0x02,0x80,0x04,0x40,0xFC,0x7E,0x40,0x04,  
    0x30,0x18,0x08,0x20,0x08,0x20,0x11,0x90,  
    0x16,0x50,0x18,0x30,0x20,0x08,0x00,0x00,  
    };  

    int mousex,mousey,mousez,mousex1,mousey1,*mousepoint=NULL;  
    drawmouse(x,y){  
    int i,j,k,n;  
    n=(16-1)/8+1;  
    for(j=0;j16;j++)  
    for(i=0;in;i++)  
    for(k=0;k8;k++)  
    if(mouseary[j*n+i]&(0x80k)) /*测试为1的位则显示*/  
    putpixel(x+i*8+k,y+j,GREEN);  

    }  
    mouse(n,x,y)  
    int x,y,n;  
    {switch(n){  
    case 0:_AX=0;geninterrupt(0x33);break;/*初始化*/  
    case 1:_AX=1;geninterrupt(0x33);break;/*显示模式*/  
    case 2:_AX=2;geninterrupt(0x33);break;/*隐藏模式*/  
    case 3:_AX=3;geninterrupt(0x33);mousex=_CX;mousey=_DX;mousez=_BX;  
    if(((mousex1!=mousex)||(mousey1!=mousey))&&(x==0)){  
    {putimage(mousex1,mousey1,mousepoint,0);free(mousepoint);  
    getimage(mousex,mousey,mousex+15,mousey+15,mousepoint);drawmouse(mousex,mousey);}  
    mousex1=mousex;mousey1=mousey;}/*显示鼠标*/  
    if(x==1){free(mousepoint);getimage(mousex,mousey,mousex+15,mousey+15,mousepoint);mousex1=mousex;mousey1=mousey;}/*取鼠标背景图*/  
    if(x==2){putimage(mousex1,mousey1,mousepoint,0);}/*释放背景图*/ if(mousez&1)return 1; else {if (mousez&2)return 2;else return 0;}break;  

    case 7:_AX=7;_CX=x;_DX=y;geninterrupt(0x33);break;/*设置水平范围*/  
    case 8:_AX=8;_CX=x;_DX=y;geninterrupt(0x33);break;/*设置垂直范围*/  
    }  
    }

    楼主 2016-03-03 17:26 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知