当前位置:首页 » 多媒体相关

散分啦!请教各位c语言高手有关图形屏幕下的输入框的处理!


os:dos  
  ide:turbo   c3.0  
  我想在图形屏幕下做一个类似tc中open菜单或是save菜单的输入功能。只能*.c文件。望各位大侠指点!

推荐阅读

  • 家电维修:偷梁换柱漫天要价蒙你没商量 [详细内容]
  • 大众启用“高考业务信息化管理系统” 信息化频道 [详细内容]
  • 新型在用机动车尾气检测实现网络监测 信息化频道 [详细内容]
  • Javascript技术技巧大全 [详细内容]
  • 读delven帖子的感想加自己的一点体会 [详细内容]
  • 香格里拉加强网站功能 欲摆脱携程e龙 信息化频道 [详细内容]
  • 小心提防过雷区 DV市场八大陷阱看仔细 [详细内容]
  • 网友回答:
    网友:stukov2002

     
       
      很久没用tc++30了,顺手写了一个~输入框的函数写得很糙,只支持backspace键进行删除修改,enter确认,至于光标闪烁和文本卷动就自己加吧~~  
       
      #include   <conio.h>  
      #include   <dos.h>  
      #include   <graphics.h>  
      #include   <string.h>  
       
      void   far   printchar(char,   int,   int,   char,   char);  
      void   far   printstring(char   *,   int,   int,   char,   char);  
      void   far   inputbox(char   *,   int,   int,   int,   char,   char);  
       
      void   main()  
      {  
      int drive   =   vga,   mode   =   vgahi;  
      char str[80];  
       
      initgraph(&drive,   &mode,   "");  
       
                        //   打印提示字符串.  
      printstring("input   box:",   0,   0,   14,   0);  
                        //   输入最多16个字符到str中.  
      inputbox(str,   16,   88,   0,   15,   1);  
                        //   打印输入的字符串.  
      printstring(str,   0,   100,   9,   0);  
       
      getch();  
      closegraph();  
      }  
       
      //   pinput   -   接收输入字符串的指针.  
      //   nmaxlen   -   输入字符的最大个数.  
      //   xpos,   ypos   -   输入框的左上角坐标,单位是像素.  
      //   fcolor,   bcolor   -   前景色和背景色.  
      void   far   inputbox(char   *pinput,   int   nmaxlen,   int   xpos,   int   ypos,   char   fcolor,   char   bcolor)  
      {  
      int n;  
      unsigned   char ch;  
       
      for(n   =   0;   n   <=   nmaxlen;   n   ++)  
      {  
      printchar(   ,   xpos   +   n   *   8,   ypos,   fcolor,   bcolor);  
      }  
      n   =   0;  
      do{  
      printchar(<,   xpos   +   n   *   8,   ypos,   15,   bcolor);  
      ch   =   getch();  
      printchar(   ,   xpos   +   n   *   8,   ypos,   bcolor,   bcolor);  
      if(ch   >=   32   &&   ch   <=   127)  
      {  
      if(n   <   nmaxlen)  
      {  
      printchar(ch,   xpos   +   n   *   8,   ypos,   fcolor,   bcolor);  
      *(pinput   +   n)   =   ch;  
      n   ++;  
      }  
      }  
      else   if(ch   ==   8)  
      {  
      if(n   >   0)  
      {  
      printchar(   ,   xpos   +   n   *   8,   ypos,   bcolor,   bcolor);  
      n   --;  
      }  
      }  
      else   if(ch   ==   13)  
      {  
      *(pinput   +   n)   =   \0;  
      break;  
      }  
      }while(1);  
      }  
       
      //   打印rom中的8x8英文字模.  
      //   ch   -   字符.  
      //   xpos,   ypos   -   坐标.  
      //   fcolor,   bcolor   -   前景色和背景色.    
      void   far   printchar(char   ch,   int   xpos,   int   ypos,   char   fcolor,   char   bcolor)  
      {  
      int   w,   h;  
      int   nmask;  
      unsigned   char   far   *pmatrix;  
       
      pmatrix   =   (unsigned   char   far   *)mk_fp(0xf000,0xfa6e   +   ch   *   8);  
       
      for(h   =   0;   h   <   8;   h   ++)  
      {  
      nmask   =   0x80;  
      for(w   =   0;   w   <   8;   w   ++)  
      {  
      if((*pmatrix   &   nmask))  
      {  
      putpixel(xpos   +   w,   ypos   +   h,   fcolor);  
      }  
      else  
      {  
      putpixel(xpos   +   w,   ypos   +   h,   bcolor);  
      }  
      nmask   =   (nmask   >>   1);  
            }  
            pmatrix   ++;  
      }  
      }  
       
      //   打印字符串.  
      //   pstr   -   字符串指针.  
      //   xpos,   ypos   -   坐标.  
      //   fcolor,   bcolor   -   前景色和背景色.    
      void   far   printstring(char   *pstr,   int   xpos,   int   ypos,   char   fcolor,   char   bcolor)  
      {  
      int n,   nlen;  
       
      nlen   =   strlen(pstr);  
      for(n   =   0;   n   <   nlen;   n   ++)  
      {  
      printchar(*(pstr   +   n),   xpos   +   n   *   8,   ypos,   fcolor,   bcolor);  
      }  
      }  
       
     

    网友:iceblade

    在图形方式下做个小动画画出来就可以了

    .

    讨论区

    Login