松湖轻烟雨 2022-08-14 20:45 采纳率: 71.4%
浏览 169
已结题

#include<conio.h>在devc++中用不了的吗

在devc++版本中因为我想使用getch所以我在开头加入了#include<conio.h>,然后无法正常运行程序,而且出现了一个代码不知道是什么,求解答
/**

  • This file has no copyright assigned and is placed in the Public Domain.
  • This file is part of the mingw-w64 runtime package.
  • No warranty is given; refer to the file DISCLAIMER.PD within this package.
  • /

#ifndef _INC_CONIO_S
#define _INC_CONIO_S

#include <conio.h>

#if defined(MINGW_HAS_SECURE_API)

#if defined(LIBMSVCRT)
/* When building mingw-w64, this should be blank. /
#define _SECIMP
#else
#ifndef _SECIMP
#define _SECIMP __declspec(dllimport)
#endif /
_SECIMP /
#endif /
defined(_CRTBLD) || defined(LIBMSVCRT) */

#ifdef __cplusplus
extern "C" {
#endif

_SECIMP errno_t __cdecl _cgets_s (char *_Buffer, size_t _Size, size_t *_SizeRead);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _cgets_s, char, _Buffer, size_t *, _SizeRead)

_SECIMP int __cdecl _cprintf_s (const char *_Format, ...);
_CRTIMP int __cdecl _cscanf_s(const char *_Format, ...);
_CRTIMP int __cdecl _cscanf_s_l(const char *_Format, _locale_t _Locale, ...);
_SECIMP int __cdecl _vcprintf_s (const char *_Format, va_list _ArgList);
_SECIMP int __cdecl _cprintf_s_l (const char *_Format, _locale_t _Locale, ...);
_SECIMP int __cdecl _vcprintf_s_l (const char *_Format, _locale_t _Locale, va_list _ArgList);

#ifndef _WCONIO_S_DEFINED
#define _WCONIO_S_DEFINED
_SECIMP errno_t __cdecl _cgetws_s (wchar_t *_Buffer, size_t _SizeInWords, size_t *_SizeRead);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _cgetws_s, wchar_t, _Buffer, size_t *, _SizeRead)

_SECIMP int __cdecl _cwprintf_s (const wchar_t *_Format, ...);
_CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format, ...);
_CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format, _locale_t _Locale, ...);
_SECIMP int __cdecl _vcwprintf_s (const wchar_t *_Format, va_list _ArgList);
_SECIMP int __cdecl _cwprintf_s_l (const wchar_t *_Format, _locale_t _Locale, ...);
_SECIMP int __cdecl _vcwprintf_s_l (const wchar_t *_Format, _locale_t _Locale, va_list _ArgList);
#endif

#ifdef __cplusplus
}
#endif

#endif

// The following compatible functions to Borland 'conio.h' are written by Anbang LI, 2021

//#if defined(_INC_CONIO) || defined(CONIO_H)
//#error can not include "conio.h" before "graphics.h"
//#endif
#ifndef _INC_WINDOWS
#include "windows.h"
#endif

void windowtitle(const char *title) { //set the title of window;
SetConsoleTitle(title);
}

void windowsize(short width, short height) { //set window size (-1 to restore)
static int firstrun = 1, wid = 0, hgt = 0;
HANDLE hdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hdout, &csbi);

if (firstrun) {
    wid = csbi.dwSize.X;
    hgt = csbi.dwSize.Y;
    firstrun = 0;
}

width = (width == -1 ? wid : width);
height = (height == -1 ? hgt : height);
COORD size = {width, height};
SetConsoleScreenBufferSize(hdout, size);
SMALL_RECT rc = {0, 0, width, height};
SetConsoleWindowInfo(hdout, 1, &rc);
//CloseHandle(hdout);

}

void fontsize(int size) { //set font size
//https://stackoverflow.com/questions/36590430/in-windows-does-setcurrentconsolefontex-change-consoles-font-size
static int firstrun = 1, sz = 0;
HANDLE hcsb = GetStdHandle(STD_OUTPUT_HANDLE); //handle to the current console
CONSOLE_FONT_INFOEX cfi = {sizeof(cfi)}; //current font info
GetCurrentConsoleFontEx(hcsb, FALSE, &cfi);
cfi.nFont = 0;

//cfi.FontFamily = TMPF_VECTOR;
//cfo.FontWeight = 200;
//wcscpy(cfi.FaceName, "Courier");
if (firstrun) {
    sz = cfi.dwFontSize.X * 2;
    firstrun = 0;
}

size = (size == -1 ? sz : size);
cfi.dwFontSize.X = size / 2;
cfi.dwFontSize.Y = cfi.dwFontSize.X * 2 * 9 / 8;
SetCurrentConsoleFontEx(hcsb, FALSE, &cfi);    //set the screen buffer's new font

}

void clrscr(void) { //clear screen
HANDLE hOutPut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hOutPut, &csbi);
COORD pos = {0, 0};
DWORD num;

//FillConsoleOutputCharacter(hOutPut, ' ', (csbi.dwSize.X * csbi.dwSize.Y), pos, &num);
// https://docs.microsoft.com/zh-cn/windows/console/fillconsoleoutputcharacter
// FillConsoleOutputCharacter is in valid under Windows 11

char ss[] = "                                        ";    //40 spaces
SetConsoleCursorPosition(hOutPut, pos);
int n =  csbi.srWindow.Bottom * (csbi.srWindow.Right - csbi.srWindow.Left) / 10 + 1;
for (int i = 0; i < n; i++)
    WriteConsole(hOutPut, ss, (DWORD)40, &num, NULL);

SetConsoleCursorPosition(hOutPut, pos);
// https://docs.microsoft.com/zh-cn/windows/console/setconsolecursorposition

}

void delay (int tm) { //delay some time (in ms)
Sleep(tm);
}

void gotoxy(short x, short y) { //goto coordinate (x, y)
COORD pos = {x, y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}

void showcursor(bool stat = 1) { //show or hide cursor (stat: 1-show, 0-hide)
CONSOLE_CURSOR_INFO cursor_info = {20, stat};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//Note: don't confused with function "ShowCursor" in windows.h. It behaves quite different.

void hidecursor() { //hide cursor
CONSOLE_CURSOR_INFO cursor_info = {20, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

#ifndef BLACK
enum COLORS {BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY,
LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE,
BLINK = 128
};
#endif

void textcolor(int forecolor, int backcolor = -1) { //set text color
static short int firstrun = 1, back = 0, fore = 0;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hOut, &csbi);

if (firstrun) {    //first run, save original colors
    //high 4 bits of scr.wAttributes is background color; low 4 bits is foreground color.
    //keep previous background color and set new foreground color.
    fore = csbi.wAttributes % 16;
    back = csbi.wAttributes / 16 * 16;
    firstrun = 0;
}

backcolor = (backcolor == -1 ? back : backcolor % 16 * 16);
forecolor = (forecolor == -1 ? fore : forecolor % 16);
SetConsoleTextAttribute(hOut, backcolor | forecolor);

}

void textbackground(int backcolor) { //set text background color
static short int firstrun = 1, back = 0;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbr;
GetConsoleScreenBufferInfo(hOut, &csbr);

if (firstrun) {
    back = csbr.wAttributes / 16 * 16;
    firstrun = 0;
}

backcolor = (backcolor == -1 ? back : backcolor % 16 * 16);
SetConsoleTextAttribute(hOut, backcolor | (csbr.wAttributes % 16));

}

#endif

  • 写回答

3条回答 默认 最新

  • [PE]经典八炮 2022-08-14 22:11
    关注

    你把c文件改成cpp文件就行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 8月23日
  • 已采纳回答 8月15日
  • 创建了问题 8月14日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改