📄 msoftcon.h
字号:
//msoftcon.h
//declarations for Lafore's console graphics functions
//uses Window's console functions
#ifndef _INC_WCONSOLE //don't let this file be included
#define _INC_WCONSOLE //twice in the same source file
#include <windows.h> //for Windows console functions
#include <conio.h> //for kbhit(), getche()
#include <math.h> //for sin, cos
enum fstyle { SOLID_FILL, X_FILL, O_FILL,
LIGHT_FILL, MEDIUM_FILL, DARK_FILL };
enum color {
cBLACK=0, cDARK_BLUE=1, cDARK_GREEN=2, cDARK_CYAN=3,
cDARK_RED=4, cDARK_MAGENTA=5, cBROWN=6, cLIGHT_GRAY=7,
cDARK_GRAY=8, cBLUE=9, cGREEN=10, cCYAN=11,
cRED=12, cMAGENTA=13, cYELLOW=14, cWHITE=15
};
/*
enum color fg,bg;
void set_color(fg,bg);
//--------------------------------------------------------------
void init_graphics();
//
void set_cursor_pos(int x, int y);
void wait(int milliseconds);
void clear_line();
void set_fill_style(fstyle);
#endif /* _INC_WCONSOLE
*/
HANDLE hConsole; //console handle
char fill_char; //character used for fill
//--------------------------------------------------------------
void init_graphics()
{
COORD console_size = {80, 25};
//open i/o channel to console screen
hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);
//set to 80x25 screen size
SetConsoleScreenBufferSize(hConsole, console_size);
//set text to white on black
SetConsoleTextAttribute( hConsole, (WORD)((0 << 4) | 15) );
fill_char = '\xDB'; //default fill is solid block
}
//--------------------------------------------------------------
void set_color(int a, int b)
{
SetConsoleTextAttribute( hConsole,
(WORD)((a << 4) | b) );
} //end setcolor()
/* 0 Black 8 Dark gray
1 Dark blue 9 Blue
2 Dark green 10 Green
3 Dark cyan 11 Cyan
4 Dark red 12 Red
5 Dark magenta 13 Magenta
6 Brown 14 Yellow
7 Light gray 15 White
*/
//--------------------------------------------------------------
void set_cursor_pos(int x, int y)
{
COORD cursor_pos; //origin in upper left corner
cursor_pos.X = x - 1; //Windows starts at (0, 0)
cursor_pos.Y = y - 1; //we start at (1, 1)
SetConsoleCursorPosition(hConsole, cursor_pos);
}
//--------------------------------------------------------------
void wait(int milliseconds)
{
Sleep(milliseconds);
}
//--------------------------------------------------------------
void clear_line() //clear to end of line
{ //80 spaces
//.....1234567890123456789012345678901234567890
//.....0........1.........2.........3.........4
cputs(" ");
cputs(" ");
}
//--------------------------------------------------------------
//--------------------------------------------------------------
#endif /* _INC_WCONSOLE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -