📄 conio.h
字号:
@函数名称: getch
函数原型: int getch(void)
函数功能: 获取下一个按键值,不回显,无按键时等待
函数返回: 按键值或EOF
参数说明:
所属文件: <conio.h>
#include <stdio.h>
#include <conio.h>
int main()
{
int c;
printf("Press any key\n");
c=getch();
printf("You pressed %c(%d)\n",c,c);
return 0;
}
@函数名称: gotoxy
函数原型: void gotoxy(int x,int y)
函数功能: 将当前字符屏幕的光标位置移动到x,y坐标位置
函数返回: x,y-要移动的目的坐标位置
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
gotoxy(35, 12);
cprintf("Hello world");
getch();
return 0;
}
@函数名称: clreol
函数原型: void clreol(void)
函数功能: 清除当前字符窗口光标处到行尾的所有字符
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
cprintf("The function CLREOL clears all characters from the");
cprintf("cursor position to the end of the line within the");
cprintf("current text window, without moving the cursor.");
cprintf("Press any key to continue ...");
gotoxy(14, 4);
getch();
clreol();
getch();
return 0;
}
@函数名称: clrscr
函数原型: void clrscr(void)
函数功能: 清除当前字符窗口所有字符
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
int i;
clrscr();
for (i=0;i<20;i++)
cprintf("%d",i);
cprintf("Press any key to clear screen");
getch();
clrscr();
cprintf("The screen has been cleared!")
getch();
return 0;
}
@函数名称: delline
函数原型: void delline(void)
函数功能: 删除当前活动窗口的当前行字符
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
cprintf("The function DELLINE deletes the line containing the");
cprintf("cursor and moves all lines below it one line up.");
cprintf("DELLINE operates within the currently active text");
cprintf("window. Press any key to continue ...");
gotoxy(1,2);
getch();
delline();
getch();
return 0;
}
@函数名称: cputs
函数原型: int cputs(const char *str)
函数功能: 在当前字符窗口显示字符串
函数返回: EOF-显示失败,最后一个显示字符:显示成功
参数说明: str-要显示的字符串
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
window(10, 10, 80, 25);
cputs("This is within the window");
getch();
return 0;
}
@函数名称: gettext
函数原型: int gettext(int left,int top,int right,int bottom,void *buf)
函数功能: 保存矩形屏幕上的字符
函数返回:
参数说明: Left,Top,Right,bottom-矩形屏幕坐标
所属文件: <conio.h>
#include <conio.h>
char buffer[4096];
int main()
{
int i;
clrscr();
for (i=0;i<=20;i++)
cprintf("Line #%d",i);
gettext(1,1,80,25,buffer);
gotoxy(1,25);
cprintf("Press any key to clear screen...");
getch();
clrscr();
gotoxy(1,25);
cprintf("Press any key to restore screen...");
getch();
puttext(1,1,80,25,buffer);
gotoxy(1,25);
cprintf("Press any key to quit...");
getch();
return 0;
}
@函数名称: puttext
函数原型: int puttext(int left,int top,int right,int bottom,void *source)
函数功能: 将gettext函数保存的字符恢复到屏幕上
函数返回:
参数说明: left,top,right,bottom-恢复的位置,source-以前gettext保存的字符
所属文件: <conio.h>
#include <conio.h>
int main()
{
char buffer[512];
clrscr();
gotoxy(20,12);
cprintf("This is a test.Press any key to continue...");
getch();
gettext(20,12,36,21,buffer);
clrscr();
gotoxy(20,12);
puttext(20,12,36,21,buffer);
getch();
return 0;
}
@函数名称: insline
函数原型: void insline(void)
函数功能: 字符模式下插入一行到当前光标位置
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
cprintf("INSLINE inserts an empty line in the text window");
cprintf("at the cursor position using the current text");
cprintf("background color. All lines below the empty one");
cprintf("move down one line and the bottom line scrolls");
cprintf("off the bottom of the window.");
cprintf("Press any key to continue:");
gotoxy(1, 3);
getch();
insline();
getch();
return 0;
}
@函数名称: highvideo
函数原型: void highvideo(void)
函数功能: 将字符屏幕状态下的字符改为高亮度显示
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
lowvideo();
cprintf("Low Intensity text");
highvideo();
gotoxy(1,2);
cprintf("High Intensity Text");
return 0;
}
@函数名称: textattr
函数原型: void textattr(int newattr)
函数功能: 设置字符模式下的前景、背景、闪烁属性
函数返回:
参数说明: newattr 各位含义如下:
B7 是否闪烁
B6 B5 B4 背景颜色
B3 B3 B1 B0 字符颜色
所属文件: <conio.h>
#include <conio.h>
int main()
{
int i;
clrscr();
for (i=0;i<9;i++)
{
textattr(i+((i+1)<<4));
cprintf("This is a test");
}
return 0;
}
@函数名称: textbackground
函数原型: void textbackground(int newcolor)
函数功能: 设置字符模式下的背景颜色
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
int i,j;
clrscr();
for(i=0;i<9;i++)
{
for(j=0;j<80;j++)
cprintf("C");
cprintf("");
textcolor(i+1);
textbackground(i);
}
return 0;
}
@函数名称: textcolor
函数原型: void textcolor(int newcolor)
函数功能: 设置字符模式下的字符颜色
函数返回:
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
int i;
for (i=0;i<15;i++)
{
textcolor(i);
cprintf("Foreground Color");
}
return 0;
}
@函数名称: textmode
函数原型: void textmode(int newmode)
函数功能: 设置字符显示模式
函数返回:
参数说明: newmode 字符显示模式,取值和含义如下:
LASTMODE=-1 上次模式
BW40 =0 40列黑白
C40 =1 40列彩色
BW80 =2 80列黑白
C80 =3 80列彩色
MONO =7 80列单色
所属文件: <conio.h>
#include <conio.h>
int main()
{
textmode(BW40);
cprintf("ABC");
getch();
textmode(C40);
cprintf("ABC");
getch();
textmode(BW80);
cprintf("ABC");
getch();
textmode(C80);
cprintf("ABC");
getch();
textmode(MONO);
cprintf("ABC");
getch();
return 0;
}
@函数名称: wherex
函数原型: int wherex(void)
函数功能: 得到字符模式下窗口光标的x坐标数值
函数返回: 光标的x坐标值
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
gotoxy(10,10);
cprintf("Current location is X:%d Y:%d",wherex(),wherey());
getch();
return 0;
}
@函数名称: wherey
函数原型: int wherey(void)
函数功能: 得到字符模式下窗口光标的y坐标数值
函数返回: 光标的y坐标值
参数说明:
所属文件: <conio.h>
#include <conio.h>
int main()
{
clrscr();
gotoxy(10,10);
cprintf("Current location is X:%d Y:%d",wherex(),wherey());
getch();
return 0;
}
@函数名称: window
函数原型: void window(int left,int top,int right,int bottom)
函数功能: 建立字符模式下的矩形字符窗口
函数返回:
参数说明: left,top,right,bottom-相对于屏幕的字符窗口坐标,屏幕原点在左上角,坐标是(1,1)
所属文件: <conio.h>
#include <conio.h>
int main()
{
window(10,10,40,11);
textcolor(BLACK);
textbackground(WHITE);
cprintf("This is a test");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -