| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 727 人关注过本帖
标题:谁来帮我看看这个窗口间切换啊,真的很简单,只是我太菜
只看楼主 加入收藏
qq1
Rank: 2
等 级:论坛游民
帖 子:92
专家分:22
注 册:2010-3-26
结帖率:78.95%
收藏
 问题点数:0 回复次数:2 
谁来帮我看看这个窗口间切换啊,真的很简单,只是我太菜
#include "stdio.h"    /* 标准输入输出库      */
#include "string.h"   /* 字符串操作函数库    */
#include "stdlib.h"   /* 标准函数库          */
#include "math.h"
#include "graphics.h" /* 图形函数库          */
#include "bios.h"     /* 基本输入输出系统函数库*/
#include "dos.h"      /* dos函数库           */
#include "time.h"

/*定义键码*/
#define KEY1       0x231     /* 主键盘区上数字键1  */
#define KEY2       0x332     /* 主键盘区上数字键2  */
#define KEY3       0x433     /* 主键盘区上数字键3  */

#define NUM1       0x4f31    /* 小键盘区上数字键1  */
#define NUM2       0x5032    /* 小键盘区上数字键2  */
#define NUM3       0x5133    /* 小键盘区上数字键3  */
  
/*定义窗口*/
struct Block
    {    int  left,top,width,height;        /* 左上坐标,宽,高*/         
         char caption[50];                  /* 标题 */                  
         int  fontcolor,fontsize,status;    /*字体颜色,字体大小,状态 */
    };


struct Block frmmain,txtscreen,cmdbutton[8]; /*定义主窗口,文本输入框,8个按钮*/
 

void Form(struct Block form);
void CommandButton(struct Block cmdbutton);
void TextBox(struct Block txtbox);
void M_help();
void M_start();
void InitApp();
void Showme();
void Showme_h();
void Showme_s();
void CommandButton_KeyboardDown(int i);
void CommandButton_KeyboardUp(int key);
void M_m_start();

main()
{
    InitApp();   
    M_m_start();
}


void M_m_start()
{
    int key;
    Showme();    /*显示程序窗口*/
    while(1)
             {
                    if(bioskey(0)==1) continue; /*直到有键按下时,才返回非0值,否则返回0值*/
                    key=bioskey(1);             /*返回上条语句的按键值*/
                    switch(key)                 /*捕获相应的键盘按键并匹配到计算器按键上*/
                        {   
                            case NUM1: case KEY1: key=1;break;
                            case NUM2: case KEY2: key=2;break;
                            case NUM3: case KEY3: key=3;break;
                            default:    key=-1;break;
                        }
               
                if(key<0) continue;             /*若对应的按键返回负数,则返回到while(1)处执行*/
                else if(key==1)
                {
                    CommandButton_KeyboardDown(1);
                    delay(300000);
                    CommandButton_KeyboardUp(1);
                    M_start();break;
                 }
                 else if(key==2)
                 {
                     CommandButton_KeyboardDown(2);
                    delay(300000);
                    CommandButton_KeyboardUp(2);
                    M_help();break;
                 }
                 else if(key==3)
                 {
                     CommandButton_KeyboardDown(3);
                    delay(300000);
                    CommandButton_KeyboardUp(3);
                    exit(1);break;
                 }
             }
}

void M_start()
{
    int key;
    Showme_s();    /*显示程序窗口*/
    while(1)
             {
                    if(bioskey(1)==0) continue; /*直到有键按下时,才返回非0值,否则返回0值*/
                    key=bioskey(0);             /*返回上条语句的按键值*/
                    switch(key)                 /*捕获相应的键盘按键并匹配到计算器按键上*/
                        {   
                            case NUM1: case KEY1:     key=1;break;
                            case NUM2: case KEY2:     key=2;break;
                            case NUM3: case KEY3:     key=3;break;
                            default:                  key=-1;break;
                        }
         if(key<0) continue;             /*若对应的按键返回负数,则返回到while(1)处执行*/
        else if(key==1)
                {
                    CommandButton_KeyboardDown(4);
                    delay(300000);
                    CommandButton_KeyboardUp(4);
                    M_m_start();break;
                 }
                 else if(key==2)
                 {
                     CommandButton_KeyboardDown(5);
                    delay(300000);
                    CommandButton_KeyboardUp(5);
                    M_m_start();break;
                 }
                 else if(key==3)
                 {
                     CommandButton_KeyboardDown(6);
                    delay(300000);
                    CommandButton_KeyboardUp(6);
                    M_m_start();break;
                 }
             }
}

void M_help()
{
    int key;
   
    Showme_h();    /*显示程序窗口*/
    while(1)
             {
                    if(bioskey(1)==0) continue; /*直到有键按下时,才返回非0值,否则返回0值*/
                    key=bioskey(0);             /*返回上条语句的按键值*/
                    switch(key)                 /*捕获相应的键盘按键并匹配到计算器按键上*/
                        {   
                            case NUM1: case KEY1:     key=1;break;
                            default:                  key=-1;break;
                        }
         if(key<0) continue;             /*若对应的按键返回负数,则返回到while(1)处执行*/
         if(key==1)
         {
             M_m_start();
             break;
         }
             }
}

void Showme()                  /*显示计算器界面*/
    {    int i;
         Form(frmmain);        /*显示主窗口,frmmain为主窗口的结构变量名*/
         for(i=1;i<=3;i++)     /*显示27个按钮在计算器主窗口中*/
         CommandButton(cmdbutton[i]);
    }

void Showme_s()                  /*显示计算器界面*/
    {    int i;
         Form(frmmain);        /*显示主窗口,frmmain为主窗口的结构变量名*/
         for(i=4;i<=6;i++)     /*显示27个按钮在计算器主窗口中*/
         CommandButton(cmdbutton[i]);
    }

void Showme_h()                  /*显示计算器界面*/
    {   
         Form(frmmain);        /*显示主窗口,frmmain为主窗口的结构变量名*/
         TextBox(txtscreen);   /*显示文本框*/
         CommandButton(cmdbutton[7]);
    }
        
void Form(struct Block form)      /* 构造和显示主窗口*/
    {    int x1=form.left;        /*窗口左上角的横坐标值*/
         int y1=form.top;         /*窗口左上角的纵坐标值*/
         int x2=form.width+x1-1;  /*窗口右下角的横坐标值*/
         int y2=form.height+y1-1; /*窗口右下角的纵坐标值*/

         setfillstyle(SOLID_FILL,LIGHTGRAY); /*设置填充模式和颜色  */
                bar(x1+1,y1+1,x2-1,y2-1);    /*画一个淡灰色的填充窗口,作为主窗口,但此函数不画出边框*/
         setcolor(WHITE);                    /*设置当前画线颜色*/
                line(x1,y1,x2,y1);
                line(x1,y1,x1,y2);    /*用白线画边框左边和上边的线,美化主窗口*/
         setcolor(DARKGRAY);          /*设置填充模式和颜色  */
                line(x2,y1,x2,y2);
                line(x1,y2,x2,y2);    /*用深灰色画边框右边和下边的线,美化主窗口*/
         setfillstyle(SOLID_FILL,BLUE);
                bar(x1+2,y1+2,x2-2,y1+25);      /*设置标题栏颜色为红色*/
         settextjustify(LEFT_TEXT,CENTER_TEXT); /*设置文本的对齐方式为左中对齐*/
         settextstyle(DEFAULT_FONT,0,form.fontsize); /*设置文本显示字体为默认字体,大小为主窗体字体大小*/
         setcolor(form.fontcolor);
                outtextxy(x1+3,y1+10,form.caption);  /*用主窗体的颜色显示标题在标题栏*/

         if(form.status&1)     /*判断窗口是否可用,未使用ALT+X键,右上角的X按钮*/
             {      cmdbutton[0].left=form.width-25;
                    cmdbutton[0].top=5;
                    cmdbutton[0].width=20;
                    cmdbutton[0].height=20;
                    cmdbutton[0].status=1;
                    cmdbutton[0].caption[0]=0;
                    CommandButton(cmdbutton[0]);
                    x1=cmdbutton[0].left+form.left;
                    y1=cmdbutton[0].top+form.top;
                    x2=cmdbutton[0].width+x1-1;
                    y2=cmdbutton[0].height+y1-1;
                    setfillstyle(SOLID_FILL,LIGHTGRAY);
                         bar(x1+1,y1+1,x2-1,y2-1);
                    setcolor(DARKGRAY);
                         line(x1+2,y1+2,x2-2,y2-2);
                         line(x2-2,y1+2,x1+2,y2-2);
             }

    }

void CommandButton(struct Block cmdbutton)  /*设置和显示单个按钮*/
    {     /*(x1,y1),(x2,y2)为主窗口中的相对坐标*/
         int x1=cmdbutton.left+frmmain.left;
         int y1=cmdbutton.top+frmmain.top;
         int x2=cmdbutton.width+x1-1;
         int y2=cmdbutton.height+y1-1;
         int c1,c2;
         /*按钮的初始状态为1,若有键按下后,其状态变为0,处理完按键操作后,又恢复为状态1*/
         if(cmdbutton.status) /*根据按钮的当前状态值来,分别用不同的颜色边框来重绘此按钮*/
             {      c1=WHITE;  /*白色*/
                    c2=DARKGRAY; /*深灰色*/
             }
         else /*若刚有键按下*/
             {      c1=DARKGRAY;
                    c2=WHITE;
             }

         setcolor(c1);
                line(x1,y1,x2,y1);
                line(x1,y1,x1,y2);
         setcolor(c2);
                line(x2,y1,x2,y2);
                line(x1,y2,x2,y2);
         settextjustify(CENTER_TEXT,CENTER_TEXT);
         settextstyle(DEFAULT_FONT,0,cmdbutton.fontsize);
         outtextxy((x1+x2)/2,(y1+y2)/2,cmdbutton.caption);

    }
        
void TextBox(struct Block txtbox)     /* 设置和显示输入框*/
    {    /*(x1,y1),(x2,y2)为主窗口中的相对坐标*/
         int x1=txtbox.left+frmmain.left;
         int y1=txtbox.top+frmmain.top;
         int x2=txtbox.width+x1-1;
         int y2=txtbox.height+y1-1;

         setfillstyle(SOLID_FILL,WHITE);
                bar(x1+1,y1+1,x2-1,y2-1);
         /*因bar()不画出边框,所以接下来画这个方本框的边框线*/
         setcolor(LIGHTGRAY);
                rectangle(x1+1,y1+1,x2-1,y2-1);
         setcolor(DARKGRAY);
                line(x1,y1,x2,y1);
                line(x1,y1,x1,y2);
                setcolor(WHITE);
                line(x2,y1,x2,y2);
                line(x1,y2,x2,y2);
         settextjustify(RIGHT_TEXT,CENTER_TEXT);       /*为图形函数设置文本的对齐方式,第一参数为水平对齐方式,第二参数为垂直对齐方式*/
         settextstyle(DEFAULT_FONT,0,txtbox.fontsize); /*为图形输出设置当前的文本属性:字体,方向,大小*/
         setcolor(txtbox.fontcolor);                   /*设置方本框的字体颜色*/
         outtextxy(x2-10,(y1+y2)/2,txtbox.caption);    /*在指定位置显示txtbox.caption的字符串值*/

    }
   
void InitApp()   /*初始化主程序*/
    {
         int driver=DETECT,mode;        /* 显示设备驱动为自动检测显示器模式 */
         initgraph(&driver,&mode,"");   /* 初始化图形显示系统  */
         if(driver!=VGA&&driver!=EGA)   /* 如果不能初始化  */
             {      printf("\n\nERROR!Can't initialize the graphics system!"); /* 显示错误信息"不能初始化图形系统"  */
                    closegraph();   /* 关闭图形接口*/
                    exit(0);        /* 直接退出系统 */
             }
         setbkcolor(LIGHTBLUE);     /* 设置背景颜色为浅蓝色  */


         /*主窗口的属性设置*/
         frmmain.left=100; frmmain.top=25; frmmain.width=450;  frmmain.height=350; frmmain.fontcolor=BLACK; frmmain.fontsize=1; strcpy(frmmain.caption,"SIZEYUNSUAN");frmmain.status=1;
         /*文本框的属性设置*/
         txtscreen.left=10;txtscreen.top=25;txtscreen.width=210;txtscreen.height=40;txtscreen.fontcolor=BLACK;txtscreen.fontsize=1;strcpy(txtscreen.caption,"0.");           txtscreen.status=1;
         /*命令按钮的属性设置*/
         cmdbutton[1].left=185-35;cmdbutton[1].top=100;cmdbutton[1].width=150;cmdbutton[1].height=45;cmdbutton[1].fontcolor=BLUE;cmdbutton[1].fontsize=2;strcpy(cmdbutton[1].caption,"START");cmdbutton[1].status=1;
         cmdbutton[2].left=185-35;cmdbutton[2].top=150;cmdbutton[2].width=150;cmdbutton[2].height=45;cmdbutton[2].fontcolor=BLUE;cmdbutton[2].fontsize=2;strcpy(cmdbutton[2].caption,"HELP"); cmdbutton[2].status=1;
         cmdbutton[3].left=185-35;cmdbutton[3].top=200;cmdbutton[3].width=150;cmdbutton[3].height=45;cmdbutton[3].fontcolor=BLUE;cmdbutton[3].fontsize=2;strcpy(cmdbutton[3].caption,"EXIT");cmdbutton[3].status=1;
         cmdbutton[4].left=185-35;cmdbutton[4].top=100;cmdbutton[4].width=150;cmdbutton[4].height=45;cmdbutton[4].fontcolor=BLUE;cmdbutton[4].fontsize=2;strcpy(cmdbutton[4].caption,"in ten");cmdbutton[4].status=1;
         cmdbutton[5].left=185-35;cmdbutton[5].top=150;cmdbutton[5].width=150;cmdbutton[5].height=45;cmdbutton[5].fontcolor=BLUE;cmdbutton[5].fontsize=2;strcpy(cmdbutton[5].caption,"in twenty");cmdbutton[5].status=1;
         cmdbutton[6].left=185-35;cmdbutton[6].top=200;cmdbutton[6].width=150;cmdbutton[6].height=45;cmdbutton[6].fontcolor=BLUE;cmdbutton[6].fontsize=2;strcpy(cmdbutton[6].caption,"return");cmdbutton[6].status=1;
         cmdbutton[7].left=185-35;cmdbutton[7].top=250;cmdbutton[7].width=150;cmdbutton[7].height=45;cmdbutton[7].fontcolor=BLUE;cmdbutton[7].fontsize=2;strcpy(cmdbutton[7].caption,"return");cmdbutton[7].status=1;
         
    }
   
void CommandButton_KeyboardDown(int i)  /*按下某键时所做的操作*/
    {                     
         cmdbutton[i].status=0;
         CommandButton(cmdbutton[i]);     /*用与初始时不同的边框颜色色,重绘此命令按钮*/
    }

void CommandButton_KeyboardUp(int key)    /*当按键处理完后,恢复按钮状态,重绘此命令按钮*/
    {  
         cmdbutton[key].status=1;
         CommandButton(cmdbutton[key]);
    }
搜索更多相关主题的帖子: 窗口 
2010-05-08 22:52
qq1
Rank: 2
等 级:论坛游民
帖 子:92
专家分:22
注 册:2010-3-26
收藏
得分:0 
自己弄了死循环
2010-05-31 22:09
五当家
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:2
帖 子:1112
专家分:3674
注 册:2010-10-20
收藏
得分:0 
这么多人过而不答,你认为你的问题还算菜么?反正我没学图形,我不会,我就是来看看.

经验积累中............
2010-11-12 23:51
快速回复:谁来帮我看看这个窗口间切换啊,真的很简单,只是我太菜
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.070562 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved