经过自己的修改,成功从Dev-C++移植到VC,不用多说,直接上代码,支持Visual Studio and VC++, Windows only

/* A conio implementation for Mingw/Dev-C++.** Written by:* Hongli Lai <hongli@telekabel.nl>* tkorrovi <tkorrovi@altavista.net> on 2002/02/26. * Andrew Westcott <ajwestco@users.sourceforge.net>* Michal Molhanec <michal@molhanec.net>** Offered for use in the public domain without any warranty.** Modified by Tody Guo on 2020/04/29* Only support for VC and VS Studio* Tody Guo <tody_guo@163.com>* https://www.csdn.net/tody_guo**/#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include "conio2.h"#ifdef __cplusplus
extern "C" {
#endifstatic int __BACKGROUND = BLACK;
static int __FOREGROUND = LIGHTGRAY;
static struct text_info __text_info = {1, 1,LIGHTGRAY + (BLACK << 4),LIGHTGRAY + (BLACK << 4),80, 25
};
static int __CONIO_TOP = 0;
static int __CONIO_LEFT = 0;static void __fill_text_info (void)
{CONSOLE_SCREEN_BUFFER_INFO info;GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);__CONIO_LEFT = info.srWindow.Left;__CONIO_TOP = info.srWindow.Top;__text_info.curx = info.dwCursorPosition.X - __CONIO_LEFT + 1;__text_info.cury = info.dwCursorPosition.Y - __CONIO_TOP  + 1;__text_info.attribute = info.wAttributes;__text_info.screenwidth  = info.srWindow.Right - info.srWindow.Left + 1;__text_info.screenheight = info.srWindow.Bottom - info.srWindow.Top + 1;
}void
gettextinfo (struct text_info * info)
{__fill_text_info();*info = __text_info;
}void inittextinfo (void)
{CONSOLE_SCREEN_BUFFER_INFO info;GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE), &info);__text_info.normattr = info.wAttributes;
}void clrscr (void)
{DWORD written;int i;COORD coord = { (short)__CONIO_LEFT, 0};__fill_text_info();for (i = __CONIO_TOP; i < __CONIO_TOP + __text_info.screenheight; i++) {coord.Y = i;FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE), __FOREGROUND + (__BACKGROUND << 4), __text_info.screenwidth, coord, &written);FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ',__text_info.screenwidth, coord, &written);}gotoxy (1, 1);
}void clreol (void)
{COORD coord;DWORD written;__fill_text_info();coord.X = __CONIO_LEFT + __text_info.curx - 1;coord.Y = __CONIO_TOP  + __text_info.cury - 1;FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),__FOREGROUND + (__BACKGROUND << 4),__text_info.screenwidth - __text_info.curx + 1, coord, &written);FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),' ', __text_info.screenwidth - __text_info.curx + 1, coord, &written);gotoxy (__text_info.curx, __text_info.cury);
}void delline (void)
{COORD coord;SMALL_RECT rect;CHAR_INFO fillchar;__fill_text_info();coord.X = __CONIO_LEFT;coord.Y = __CONIO_TOP + __text_info.cury - 1;rect.Left = __CONIO_LEFT;rect.Top = __CONIO_TOP + __text_info.cury;rect.Right = __CONIO_LEFT + __text_info.screenwidth - 1;rect.Bottom = __CONIO_TOP + __text_info.screenheight - 1;fillchar.Attributes = __FOREGROUND + (__BACKGROUND << 4);
#ifdef UNICODEfillchar.Char.UnicodeChar = L' ';ScrollConsoleScreenBufferW(GetStdHandle(STD_OUTPUT_HANDLE),&rect, NULL, coord, &fillchar);
#elsefillchar.Char.AsciiChar = ' ';ScrollConsoleScreenBufferA(GetStdHandle(STD_OUTPUT_HANDLE),&rect, NULL, coord, &fillchar);
#endifgotoxy (__text_info.curx, __text_info.cury);
}void insline (void)
{COORD coord;SMALL_RECT rect;CHAR_INFO fillchar;__fill_text_info();coord.X = __CONIO_LEFT;coord.Y = __CONIO_TOP + __text_info.cury;rect.Left = __CONIO_LEFT;rect.Top = __CONIO_TOP + __text_info.cury - 1;rect.Right = __CONIO_LEFT + __text_info.screenwidth - 1;rect.Bottom = __CONIO_TOP + __text_info.screenheight - 2;fillchar.Attributes = __FOREGROUND + (__BACKGROUND << 4);#ifdef UNICODEfillchar.Char.UnicodeChar = L' ';ScrollConsoleScreenBufferW(GetStdHandle(STD_OUTPUT_HANDLE),&rect, NULL, coord, &fillchar);
#elsefillchar.Char.AsciiChar = ' ';ScrollConsoleScreenBufferA(GetStdHandle(STD_OUTPUT_HANDLE),&rect, NULL, coord, &fillchar);
#endifgotoxy (__text_info.curx, __text_info.cury);
}void movetext (int left, int top, int right, int bottom, int destleft, int desttop)
{struct char_info * buffer;buffer = (char_info*)malloc ((right - left + 1) * (bottom - top + 1) * sizeof(struct char_info));  // -----gettext (left, top, right, bottom, buffer);puttext (destleft, desttop, destleft + right - left, desttop + bottom - top, buffer);free(buffer);
}void _conio_gettext (int left, int top, int right, int bottom,struct char_info * buf)
{int i;SMALL_RECT r= { (short)(__CONIO_LEFT + left - 1), (short)(__CONIO_TOP + top - 1), (short)(__CONIO_LEFT + right - 1), (short)(__CONIO_TOP + bottom - 1) };CHAR_INFO* buffer;COORD size;COORD coord = {0,0};__fill_text_info();size.X = right - left + 1;size.Y = bottom - top + 1;buffer = (CHAR_INFO*)malloc (size.X * size.Y * sizeof(CHAR_INFO));ReadConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE),(PCHAR_INFO) buffer, size, coord, &r);for (i = 0; i < size.X * size.Y; i++){
#ifdef UNICODEbuf[i].letter = buffer[i].Char.UnicodeChar;
#elsebuf[i].letter = buffer[i].Char.AsciiChar;
#endifbuf[i].attr = buffer[i].Attributes;}free (buffer);
}void puttext (int left, int top, int right, int bottom, struct char_info * buf)
{ int i;SMALL_RECT r= { (short)(__CONIO_LEFT + left - 1), (short)(__CONIO_TOP + top - 1), (short)(__CONIO_LEFT + right - 1), (short)(__CONIO_TOP + bottom - 1) };CHAR_INFO* buffer;COORD size;COORD coord = { 0,0 };__fill_text_info();size.X = right - left + 1;size.Y = bottom - top + 1;buffer = (CHAR_INFO*)malloc (size.X * size.Y * sizeof(CHAR_INFO));for (i = 0; i < size.X * size.Y; i++){
#ifdef UNICODEbuffer[i].Char.UnicodeChar = buf[i].letter;
#elsebuffer[i].Char.AsciiChar = buf[i].letter;
#endifbuffer[i].Attributes = buf[i].attr;}WriteConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE), buffer, size, coord, &r);free (buffer);
}void gotoxy(int x, int y)
{COORD c;c.X = __CONIO_LEFT + x - 1;c.Y = __CONIO_TOP  + y - 1;SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}void cputsxy (int x, int y, char * str)
{gotoxy (x, y);cputs (str);
}void putchxy (int x, int y, char ch)
{gotoxy (x, y);_putch (ch);
}void _setcursortype (int type)
{CONSOLE_CURSOR_INFO Info;if (type == 0) {Info.bVisible = FALSE;} else {Info.dwSize = type;Info.bVisible = TRUE;}SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),&Info);
}void textattr (int _attr)
{__FOREGROUND = _attr & 0xF;__BACKGROUND = _attr >> 4;SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
}void normvideo (void)
{textattr (__text_info.normattr);
}void textbackground (int color)
{__BACKGROUND = color;SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),__FOREGROUND + (color << 4));
}void textcolor (int color)
{__FOREGROUND = color;SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),color + (__BACKGROUND << 4));
}int wherex (void)
{__fill_text_info();return __text_info.curx;
}int wherey (void)
{__fill_text_info();return __text_info.cury;
}char *getpass (const char * prompt, char * str)
{int maxlength = str[0];int length = 0;int ch = 0;int x, y;cputs(prompt);__fill_text_info();x = __text_info.curx;y = __text_info.cury;while (ch != '\r') {ch = _getch();switch (ch) {case '\r' : /* enter */break;case '\b' : /* backspace */if (length > 0) putchxy (x + --length, y, ' ');gotoxy (x + length, y);break;default:if (length < maxlength) {putchxy (x + length, y, '*');str[2 + length++] = ch;}}}str[1] = length;str[2 + length] = '\0';return &str[2];
}void highvideo (void)
{if (__FOREGROUND < DARKGRAY) textcolor(__FOREGROUND + 8);
}void lowvideo (void)
{if (__FOREGROUND > LIGHTGRAY) textcolor(__FOREGROUND - 8);
}void delay (int ms)
{Sleep(ms);
}void switchbackground (int color)
{struct char_info* buffer;int i;buffer = (char_info*)malloc(__text_info.screenwidth * __text_info.screenheight *sizeof(struct char_info));_conio_gettext(1, 1, __text_info.screenwidth, __text_info.screenheight,buffer);for (i = 0; i < __text_info.screenwidth * __text_info.screenheight; i++) {unsigned short attr = buffer[i].attr & 0xF;buffer[i].attr = (color << 4) | attr;}puttext(1, 1, __text_info.screenwidth, __text_info.screenheight, buffer);free(buffer);
}void flashbackground (int color, int ms)
{struct char_info* buffer;buffer = (char_info*)malloc(__text_info.screenwidth * __text_info.screenheight *sizeof(struct char_info));_conio_gettext(1, 1, __text_info.screenwidth, __text_info.screenheight,buffer);switchbackground(color);delay(ms);puttext(1, 1, __text_info.screenwidth, __text_info.screenheight, buffer);free(buffer);
}void clearkeybuf (void)
{while (_kbhit()) {_getch();}
}#ifdef __cplusplus
}
#endif

conio2.h

/** @file conio2.h* A conio implementation for Mingw/Dev-C++.** Written by:* Hongli Lai <hongli@telekabel.nl>* tkorrovi <tkorrovi@altavista.net> on 2002/02/26.* Andrew Westcott <ajwestco@users.sourceforge.net>* Michal Molhanec <michal@molhanec.net>** Offered for use in the public domain without any warranty.*/#ifndef _CONIO2_H_
#define _CONIO2_H_#include <conio.h>
#ifdef UNICODE#include <windows.h>    // we need wchar_t
#endif#ifdef __cplusplus
extern "C" {
#endif/*** Colors which you can use in your application.*/
typedef enum
{BLACK,          /**< black color */BLUE,           /**< blue color */GREEN,          /**< green color */CYAN,           /**< cyan color */RED,            /**< red color */MAGENTA,        /**< magenta color */BROWN,          /**< brown color */LIGHTGRAY,      /**< light gray color */DARKGRAY,       /**< dark gray color */LIGHTBLUE,      /**< light blue color */LIGHTGREEN,     /**< light green color */LIGHTCYAN,      /**< light cyan color */LIGHTRED,       /**< light red color */LIGHTMAGENTA,   /**< light magenta color */YELLOW,         /**< yellow color */WHITE           /**< white color */
} COLORS;/*@{*/
/*** This defines enables you to use all MinGW conio.h functions without* underscore.*/
#define cgets   _cgets
#define cprintf _cprintf
#define cputs   _cputs
#define cscanf  _cscanf#ifdef UNICODE#define cgetws   _cgetws#define getwch   _getwch#define getwche  _getwche#define putwch   _putwch#define ungetwch _ungetwch#define cputws   _cputws#define cwprintf _cwprintf#define cwscanf  _cwscanf
#endif
/*@}*//*** Define alias for _conio_gettext.* If you want to use gettext function from some other library* (e.g. GNU gettext) you have to define _CONIO_NO_GETTEXT_ so you won't get* name conflict.*/
#ifndef _CONIO_NO_GETTEXT_#define gettext _conio_gettext
#endif#define ScreenClear clrscr/*** @anchor cursortypes* @name Cursor types* Predefined cursor types. */
/*@{*/
#define _NOCURSOR 0         /**< no cursor */
#define _SOLIDCURSOR 100    /**< cursor filling whole cell */
#define _NORMALCURSOR 20    /**< cursor filling 20 percent of cell height */
/*@}*//*** Structure holding information about screen.* @see gettextinfo* @see inittextinfo*/
struct text_info {unsigned char curx;          /**< cursor coordinate x */unsigned char cury;          /**< cursor coordinate y */unsigned short attribute;    /**< current text attribute */unsigned short normattr;     /**< original value of text attribute afterstart of the application. If you don'tcalled the <TT>inittextinfo</TT> on thebeginning of the application, this alwayswill be black background and light grayforeground */unsigned char screenwidth;   /**< screen width */unsigned char screenheight;  /**< screen height */
};/*** Structure used by gettext/puttext.* @see _conio_gettext* @see puttext*/
struct char_info {
#ifdef UNICODEwchar_t letter;        /**< character value */
#elsechar letter;           /**< character value */
#endifunsigned short attr;   /**< attribute value */
};/*** Returns information of the screen.* @see text_info*/
void gettextinfo (struct text_info * info);/*** Call this if you need real value of normattr attribute in the text_info* structure.* @see text_info*/
void inittextinfo (void);/*** Clears rest of the line from cursor position to the end of line without* moving the cursor.*/
void clreol (void);/*** Clears whole screen.*/
void clrscr (void);/*** Delete the current line (line on which is cursor) and then moves all lines* below one line up. Lines below the line are moved one line up.*/
void delline (void);/*** Insert blank line at the cursor position.* Original content of the line and content of lines below moves one line down.* The last line is deleted.*/
void insline (void);/*** Gets text from the screen. If you haven't defined <TT>_CONIO_NO_GETTEXT_</TT>* prior to including <TT>conio2.h</TT> you can use this function also under* the <TT>gettext</TT> name.* @see char_info* @see puttext* @param left Left coordinate of the rectangle, inclusive, starting from 1.* @param top Top coordinate of the rectangle, inclusive, starting from 1.* @param right Right coordinate of the rectangle, inclusive, starting from 1.* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.* @param buf You have to pass buffer of size* <TT>(right - left + 1) * (bottom - top + 1) * sizeof(char_info)</TT>.*/
void _conio_gettext (int left, int top, int right, int bottom,struct char_info * buf);/*** Puts text back to the screen.* @see char_info* @see _conio_gettext* @param left Left coordinate of the rectangle, inclusive, starting from 1.* @param top Top coordinate of the rectangle, inclusive, starting from 1.* @param right Right coordinate of the rectangle, inclusive, starting from 1.* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.* @param buf You have to pass buffer of size* <TT>(right - left + 1) * (bottom - top + 1) * sizeof(char_info)</TT>.*/
void puttext (int left, int top, int right, int bottom, struct char_info * buf);/*** Copies text.* @param left Left coordinate of the rectangle, inclusive, starting from 1.* @param top Top coordinate of the rectangle, inclusive, starting from 1.* @param right Right coordinate of the rectangle, inclusive, starting from 1.* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.* @param destleft Left coordinate of the destination rectangle.* @param desttop Top coordinate of the destination rectangle.*/
void movetext (int left, int top, int right, int bottom, int destleft,int desttop);/*** Moves cursor to the specified position.* @param x horizontal position* @param y vertical position*/
void gotoxy(int x, int y);/*** Puts string at the specified position.* @param x horizontal position* @param y vertical position* @param str string*/
void cputsxy (int x, int y, char * str);/*** Puts char at the specified position.* @param x horizontal position* @param y vertical position* @param ch char*/
void putchxy (int x, int y, char ch);/*** Sets the cursor type.* @see @ref cursortypes* @param type cursor type, under Win32 it is height of the cursor in percents*/
void _setcursortype (int type);/*** Sets attribute of text.* @param _attr new text attribute*/
void textattr (int _attr);/*** Sets text attribute back to value it had after program start.* It uses text_info's normattr value.* @see text_info*/
void normvideo (void);/*** Sets text background color.* @see COLORS* @param color new background color*/
void textbackground (int color);/*** Sets text foreground color.* @see COLORS* @param color new foreground color*/
void textcolor (int color);/*** Reads the cursor X position.* @returns cursor X position*/
int wherex (void);/*** Reads the cursor Y position.* @returns cursor Y position*/
int wherey (void);/*** Reads password. This function behaves like cgets.** @see cgets* @param prompt prompt which will be displayed to user* @param str string for the password. <TT>str[0]</TT> have to contain* length of the <TT>str</TT> - 3* @returns <TT>&str[2]</TT>, the password will be stored in <TT>str</TT>* beginning at <TT>str[2]</TT>, in <TT>str[1]</TT> will be length of the* string without <TT>\\0</TT>, at <TT>str[2 + str[1]]</TT> will be \\0.*/
char * getpass (const char * prompt, char * str);/*** Makes foreground colors light.* If the current foreground color is less than <TT>DARKGRAY</TT> adds* 8 to the its value making dark colors light.* @see COLORS* @see lowvideo*/
void highvideo (void);/*** Makes foreground colors dark.* If the current foreground color is higher than <TT>LIGHTGRAY</TT> substracts* 8 from its value making light colors dark.* @see COLORS* @see highvideo*/
void lowvideo (void);/*** Pauses program execution for a given time.* @see switchbackground* @param ms miliseconds*/
void delay (int ms);/*** Replaces background color in the whole window. The text however* is left intact. Does not modify textbackground().* @see flashbackground* @param color background color*/
void switchbackground (int color);/*** Changes background color for a given time and then it restores it back.* You can use it for visual bell. Does not modify textbackground().* @see switchbackground* @see delay* @param color background color* @param ms miliseconds*/
void flashbackground (int color, int ms);/*** Clears the keyboard buffer.* To see it in effect run <TT>conio_test</TT> and try to press a key during* the 'Flashing...' phase.*/
void clearkeybuf (void);#ifdef __cplusplus
}
#endif#endif /* _CONIO2_H_ */

Windows conio.h 的源码,实现gotoxy, textcolor,movetext等函数相关推荐

  1. windows和linux下源码编译7-Zip(7za)

    windows和linux下源码编译7-Zip(7za) 如需转载请标明出处:http://blog.csdn.net/itas109 QQ技术交流群:129518033 文章目录 windows和l ...

  2. 从零开始成为GStreamer专家——基于Windows的GStreamer从源码下载、编译到开发

    基于Windows的GStreamer从源码下载.编译到开发 本文介绍了在GStreamer下载方法, 使用过程中的部分依赖,以及在Windows上编译配置GStreamer 过程,为学习GStrea ...

  3. Windows IEDA 编译Hbase源码报错 - 无法执行shell脚本

    windows 下编译 hbase源码,报错 [ERROR] Command execution failed. java.io.IOException: Cannot run program &qu ...

  4. Windows 环境下载 Android 源码

    Windows 环境下载 Android 源码 前言 Android 官网(该方式不适合 Windows 平台):https://source.android.com/source/downloadi ...

  5. Windows优化大师注册机源码

    Windows优化大师注册机源码 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics ...

  6. WINDOWS 下编译 ffmpeg 源码总结

    WINDOWS 下编译 ffmpeg 源码,有两种方式:VC.GCC 1.VC 编译:   https://github.com/ShiftMediaProject/FFVS-Project-Gene ...

  7. windows下载编译chromium源码

    前言 chromium 源码的下载编译,真的就是如各位前辈说的一样,参考再完整的教程,还是会遇到各种各样的问题.因为每个人的开发环境是不一样的,网络环境也不一样. 一路参考各路大神的教程开始踩坑填坑的 ...

  8. wemall app商城源码Android之支付宝接口公用函数

    wemall-mobile是基于WeMall的Android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享wemall app商城源码Android之 ...

  9. NeuCF源码中用到的模块(函数)

    论文:<Neural Collaborative Filtering>源码中用到的模块(函数) from keras.layers import Embedding, Input, Den ...

  10. windows下编译lua源码

    http://blog.csdn.net/zjg555543/article/details/11814563 因为之前一直使用 lua for windows 来搭建lua的使用环境,但是最新的 l ...

最新文章

  1. 自建git服务器连接Pycharm系列二:在centos7上搭建git服务器
  2. pybind 播放h264
  3. tensorflow dataset_ops map()方法 (返回数据集通过函数“ map_func”的元素映射)
  4. PPT 下载 | 神策数据徐美玲:数据分析之产品应用实践
  5. [Flashback]开启数据库闪回数据库功能
  6. 上传jar包到nexus私服
  7. dubbo 消费者也要暴露端口吗_一文详细解读 Dubbo 中的 http 协议
  8. httpHandlers和httpModules接口介绍 (5)
  9. 辰皇怎么过鸿蒙,诛仙3最厉害的职业是什么 强弱对应原因解析
  10. python通用数据库连接_python 连接数据库pg
  11. 解决idea的html代码中使用es6语法报错的问题
  12. 三大抽样分布、正态总体下的抽样分布
  13. C++父类和子类同名函数及继承关系---多态
  14. Luarocks 安装艰难过程
  15. Linux的LCD驱动
  16. 读懂西瓜书 14 : 概率图模型
  17. 报错 [Error] expected primary-expression before ‘)‘ token
  18. 易语言程序c盘路径,易语言取文件路径的操作教程
  19. 有没有免费的数据恢复软件,easyrecovery中文版
  20. Unity API常用方法和类

热门文章

  1. 英语数字听力学习软件操作
  2. 使用CSS给文字添加描边效果
  3. 代码对比/归并/两个代码对比,对比代码
  4. 国内外计算机专业图形图像处理课程现状,计算机图像处理论文
  5. 高效记忆/形象记忆(07)110数字编码表 11-20
  6. SqList顺序表实现笔记
  7. 解放前端工程师——手把手教你开发自己的自定义列表和自定义表单系列之三表格
  8. 易语言pc微信hook最新版本
  9. html调用xfplugin,傻瓜式网页里嵌入先锋web万能播放控件
  10. 随机信号分析学习笔记(3)