| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 928 人关注过本帖, 1 人收藏
标题:请教一个问题,
只看楼主 加入收藏
xujun1207
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2008-7-15
收藏(1)
 问题点数:0 回复次数:2 
请教一个问题,
conio.h是什么头文件,不通过TC工具,怎么用?还有TC下的绘图的头文件,也是用不了?我用的是(C-Free 标准版)和(C与C++程序设计学习与实验系统),但在这两个工具下都不能用,
搜索更多相关主题的帖子: 程序设计 
2008-09-03 08:19
妍清舞
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-11-12
收藏
得分:0 
[bo][un]xujun1207[/un] 在 2008-9-3 08:19 的发言:[/bo]

conio.h是什么头文件,不通过TC工具,怎么用?还有TC下的绘图的头文件,也是用不了?我用的是(C-Free 标准版)和(C与C++程序设计学习与实验系统),但在这两个工具下都不能用,

C语言中,图形函数大致可分为两类:字符模式函数和图形模式函数。本节我们练习使用字符模式函数。   
          使用字符模式函数应该在程序中联入conio.h头部文件。   
          下面是一些函数的作用   
  1)     void     clreol();           从光标处删除到本行末   
  2)     void     delline();         清除本行内容,下面内容上提一行   
                      delline();函数实际上还起到了向上卷屏的作用。   
  3)     void     insline();         在光标所在行插入一空行,原来该行及以   
                                                          下各行皆向下移一行   
  4)       int     wherex();           返回当前光标的x(行)坐标   
  5)       int     wherey();           返回当前光标的y(列)坐标   
  6)     void     highvideo();     字符输出用高亮度字符   
  7)     void     lowvideo();       字符输出用低亮度字符   
  8)     void     normvideo();     字符输出用普通亮度字符   
          在以上的各函数中皆不带参数,当然也可以写成括号中有void的形式:   
          void   wherex(void);         还可以写成         wherex();   
          清屏、清行、向后删行、插行的操作真有些CCED、WPS等编辑软件的风格,就是在你平时的屏幕设计中也用少不了。返回坐标的函数则给你的设计提供每一个环节的光标坐标值。有利于你前后响应。字   
  符亮度的改变则会让你的字符显示出层次感,怎么样,赶快试试吧:   
  /*   No32.c*/   
  #   include   "stdio.h"   
  #   include   "conio.h"   
  main()   
  {   clrscr();   
      gotoxy(10,1);   
      cprintf("甜密密,");   
      highvideo();                                                       /*高亮度显示*/   
      cprintf("\r\n                   你笑得甜密密,");   
      lowvideo();                                                         /*低亮度显示*/   
      cprintf("\r\n                   好象花儿开在春风里,");   
      normvideo();                                                       /*普通亮度显示*/   
      gotoxy(10,4);   cprintf("开在春风里");   
      cprintf("\r\n                   在哪里,在哪里见过你?");   
      printf("\r\n                   你的笑容这样熟悉。");   
      gotoxy(10,20);printf("任意键删去光标后的内容");   
      gotoxy(18,3);           getch();   
      gotoxy(18,3);   
      clreol();                                                             /*删去光标后字符*/   
      gotoxy(10,20);printf("任意键删去本行的内容     ");   
      gotoxy(18,3);           getch();   
      delline();                                                           /*删去本行*/   
      gotoxy(10,20);printf("任意键在本行插一空行     ");   
      gotoxy(18,3);           getch();   
      insline();                                                           /*插入一空行*/   
      gotoxy(1,7);   
  }   
          应该注意的是,要发挥本节所讲的函数的作用,在显示时不能使printf函数,应使用cprintf函数。它的使用方法和printf的完全一样,只不过后面的cprintf能发挥亮度设置和颜色设置的作用。前者   
  printf函数只有一种颜色和单一的亮度。   
          在cprintf函数中,“\n”的作用不再是既回到行首又换行,它只起一个换行的作用,所以要把内容在行首显示必须再加一个“\r”   
          上面的程序不是一真正对大家有用的程序,只是用来说明一个刚刚学到的几个函数的作用。在conio.h中还有一些字符型函数,它们都是带参数的。   
  9)     void   textcolor(颜色);                 定义显示字符颜色   
  10)   void   textbackground(颜色);       定义背景颜色   
          下面是颜色数字和颜色对照表   
          BLACK             0                                 DARKGRAY           8         深灰   
          BLUE               1                                 LIGHTBLUE         9         淡兰   
          GREEN             2       绿                           LIGHTGREEN       10       淡绿   
          CYAN               3                                 LIGHTCYAN         11       淡青   
          RED                 4                                 LIGHTRED           12       淡红   
          MAGENTA         5     洋红                         LIGHTMAGENTA   13       淡洋红   
          BROWN             6                                 YELLOW               14         
          LIGHTGRAY     7     淡灰                         WHILT                 15         
          背景颜色值只能是0-7共8个数字或其对应的英文大写单词。而前景(即字符)的颜色可以是0-15共16种颜色或其对应的英文大写单词。当你定义的前景和背景相同时,屏幕上看不到输出的内容。   
          textcolor(4);          textcolor(RED);     效果是相同的。   
          设置屏幕颜色还可以使用   
  11)   void   textattr(前景颜色+(背景颜色));   
          但这里的背景颜色要有“<<4”。如白底红字,就是:   
              textattr(RED+(WHITE<<4));   
  12)   int   gettext(左上角x,左上角y,右下角x,右下角y,内存指针);   
                              把定义的长方形区域内的内容存在内存中   
  13)   int   puttext(左上角x,左上角y,右下角x,右下角y,内存指针);   
                              把内存中存好的内容显示在新定义的矩形块内   
          这里的内存指针也可用字符形数组来代替。需要注意的是内存大小应该是所存内容的“行数*列数*2”。比如把第3行第5列到第6行第75列的数据存到内存中,可以用下面的片段:   
          char   buffer[4*70*2];   
          gettext(5,3,75,6,buffer);   
          然后你就可以用puttext函数来显示它了。   
  14)   void   movetext(左上角x,左上角y,右下角x,右下角y,   
                                                                                新左上角x,新左上角y);   
                                把矩形块移到新左上角(x,y)决定的地方   
  15)   void   window(左上角x,左上角y,右下角x,右下角y);   
                              定义一个窗口,大小就是上面参数决定的长方形   
          利用这一函数,你可以在屏幕上任何一个地方开辟一个窗口,并在上面显示需要的内容。这丝毫不影响屏幕其它地方的内容。当你定义了窗口后,你只能操作该窗口,gotoxy(),wherex(),wherey(),   
  clrscr()等等函数所表示的都是你定义窗口中的情况。实际上这就为我们的操作带来了方便,你想操作哪儿,就定义哪儿,想回到平时状态的屏幕,就定义一个最大的窗口,window(1,1,80,25);就复原了。   
          No.33号例子是利用puttext和gettext函数以及颜色定义来模仿CCED和WPS的菜单显示。但这个小程序没有可移动的光条,也没有菜单中内容的相应执行程序,只是演示一下屏幕的保存和释放而已。   
  /*   No33.c   */   
  #include   "conio.h"   
  #include   "stdio.h"   
  main()   
  {     int   i=1,j,ch;   
        char   buffer[6*50*2];               /*开辟内存空间的大小*/   
        clrscr();   
        textcolor(0);                             /*定义字符颜色*/   
        textbackground(7);                   /*定义背景颜色*/   
        gotoxy(1,1);   
        cprintf("         功能1               功能2             功能3         ");   
        textbackground(0);   
        textcolor(14);   
        gotoxy(1,2);   
        cprintf("What's   your   name?                 你叫什么名字");   
        cprintf("\n\rMy   name   is   Wang   Dong.         我叫王东.");   
        cprintf("\n\rHow   old   are   are   you?           你多大了   .   ");   
        cprintf("\n\rI'm   thirty-four.                   我四十四了");   
        cprintf("\n\r\n\rThis   is   Lesson   One.             这是第一课");   
        while(1)   
        {   j=i;   
            textcolor(0);   
            textbackground(7);   
            if(i==1)   
            {   gettext(1,2,13,5,buffer);   
                gotoxy(2,2);       cprintf("│第一课│");   
                gotoxy(2,3);       cprintf("│第二课│");   
                gotoxy(2,4);       cprintf("│第三课│");   
                gotoxy(2,5);       cprintf("└───┘");   
            }   
            if(i==2)   
            {   gettext(13,2,25,5,buffer);   
                gotoxy(14,2);       cprintf("│菜单一│");   
                gotoxy(14,3);       cprintf("│菜单二│");   
                gotoxy(14,4);       cprintf("│菜单三│");   
                gotoxy(14,5);       cprintf("└───┘");   
            }   
            if(i==3)   
            {   gettext(25,2,37,5,buffer);   
                gotoxy(26,2);       cprintf("│说明A   │");   
                gotoxy(26,3);       cprintf("│说明B   │");   
                gotoxy(26,4);       cprintf("│说明C   │");   
                gotoxy(26,5);       cprintf("└───┘");   
            }   
            textcolor(14);   
            gotoxy(10,20);printf("→向右移动     ←向左移动     Esc   退出");   
            ch=getch();   
            if((ch==75)&&(i==1))                 /*菜单个数的判断*/   
            {     i=3;   ch=0;}   
            if((ch==77)&&(i==3))                 /*ASCII码   77是右箭头*/   
            {     i=1;   ch=0;}   
            if((ch==75)&&(i>1))                   /*ASCII码   75是左箭头*/   
                i--;   
            if((ch==77)&&(i<3))   
                i++;   
            if(ch==27)   
                break;   
            puttext(j*12-11,2,j*12+1,5,buffer);   
      }   
  }

[bo]参考CSDN [un]http://topic.[/un][/bo]

conio.h是一个C标准库中的头文件。

conio是Console Input/Output(控制台输入输出)的简写,其中定义了通过控制台进行数据输入和数据输出的函数,主要是一些用户通过按键盘产生的对应操作,比如getch()函数等等。

/***
*conio.h - console and port I/O declarations
*
* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
* This include file contains the function declarations for
* the MS C V2.03 compatible console I/O routines.
*
* [Public]
*
****/

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _INC_CONIO
#define _INC_CONIO

#if !defined(_WIN32) && !defined(_MAC)
#error ERROR: Only Mac or Win32 targets supported!
#endif


#ifndef _MAC

#ifdef __cplusplus
extern "C" {
#endif



/* Define _CRTIMP */

#ifndef _CRTIMP
#ifdef _DLL
#define _CRTIMP __declspec(dllimport)
#else /* ndef _DLL */
#define _CRTIMP
#endif /* _DLL */
#endif /* _CRTIMP */


/* Define __cdecl for non-Microsoft compilers */

#if ( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
#endif

/* Define _CRTAPI1 (for compatibility with the NT SDK) */

#ifndef _CRTAPI1
#if _MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif

/* Function prototypes */

_CRTIMP char * __cdecl _cgets(char *);
_CRTIMP int __cdecl _cprintf(const char *, ...);
_CRTIMP int __cdecl _cputs(const char *);
_CRTIMP int __cdecl _cscanf(const char *, ...);
_CRTIMP int __cdecl _getch(void);
_CRTIMP int __cdecl _getche(void);
#ifdef _M_IX86
int __cdecl _inp(unsigned short);
unsigned short __cdecl _inpw(unsigned short);
unsigned long __cdecl _inpd(unsigned short);
#endif /* _M_IX86 */
_CRTIMP int __cdecl _kbhit(void);
#ifdef _M_IX86
int __cdecl _outp(unsigned short, int);
unsigned short __cdecl _outpw(unsigned short, unsigned short);
unsigned long __cdecl _outpd(unsigned short, unsigned long);
#endif /* _M_IX86 */
_CRTIMP int __cdecl _putch(int);
_CRTIMP int __cdecl _ungetch(int);


#if !__STDC__

/* Non-ANSI names for compatibility */

_CRTIMP char * __cdecl cgets(char *);
_CRTIMP int __cdecl cprintf(const char *, ...);
_CRTIMP int __cdecl cputs(const char *);
_CRTIMP int __cdecl cscanf(const char *, ...);
#ifdef _M_IX86
int __cdecl inp(unsigned short);
unsigned short __cdecl inpw(unsigned short);
#endif /* _M_IX86 */
_CRTIMP int __cdecl getch(void);
_CRTIMP int __cdecl getche(void);
_CRTIMP int __cdecl kbhit(void);
#ifdef _M_IX86
int __cdecl outp(unsigned short, int);
unsigned short __cdecl outpw(unsigned short, unsigned short);
#endif /* _M_IX86 */
_CRTIMP int __cdecl putch(int);
_CRTIMP int __cdecl ungetch(int);

#endif /* __STDC__ */

#ifdef __cplusplus
}
#endif

#endif /* _MAC */

#endif /* _INC_CONIO */

[bo]参考:<conio.h> [/bo]
2008-09-03 21:59
xujun1207
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2008-7-15
收藏
得分:0 
谢谢,知道怎么用了,学了好久了吧,这么厉害,什么时候才能像你一样就好了……
2008-09-09 15:15
快速回复:请教一个问题,
数据加载中...
 
   



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

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