?? console_screen2.cpp
字號:
// ----------------------------------------------------------
// ITS82
// console_screen2.cpp
//
// Helper Functions for console screen manipulation
// Apr 2005
// ----------------------------------------------------------
//
// Disclaimer:
// Hey, I just took reference from the web. So if the code
// doesn't work, you can blame the one who created internet.
//
// ----------------------------------------------------------
#include "console_screen2.h"
#include <conio.h>
// ----------------------------------------------------------
// This is a function that use to clear the screen
// ----------------------------------------------------------
void cls()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { 0, 0 }; /* cursor position */
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* used to get buffer info */
DWORD dwConSize; /* number of character cells in the current buffer */
/* get the number of character cells in the current buffer */
GetConsoleScreenBufferInfo( hConsole, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten );
/* get the current text attribute */
GetConsoleScreenBufferInfo( hConsole, &csbi );
/* now set the buffer's attributes accordingly */
FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );
/* put the cursor at (0, 0) */
SetConsoleCursorPosition( hConsole, coordScreen );
}
// ----------------------------------------------------------
// call this when you need the system wait for a period
// ----------------------------------------------------------
void wait(long ms)
{
Sleep(ms);
}
// ----------------------------------------------------------
// call this when you want to detect if user press key
// return:
// 0 : no key has been input
// 1 to 127 : printable ascii code (most of) :P
// 128 - 255 : special code
//
// * Some useful code:
// Esc - 27
// F1 - 187
// ...
// F10 - 196
// F11 - 5
// F12 - 6
//
// UP - 200
// DOWN - 208
// LEFT - 203
// RIGHT - 205
//
// Insert - 210
// Delete - 211
// Home - 199
// End - 207
// PageUP - 201
// PageDown - 209
//
// ----------------------------------------------------------
char getKey()
{
unsigned char c;
if(!_kbhit())
return 0;
c = (unsigned char)_getch();
// on special key, need to _getch again
if((c == 0) || (c == (unsigned char)0xE0))
return((unsigned char)128 + (unsigned char)_getch());
else
return c;
}
// ----------------------------------------------------------
// Set the cursor position
// parameters: row is x, col is y.
// ----------------------------------------------------------
void setPos(int row, int col) //簿笆positionノ
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = { col, row };
SetConsoleCursorPosition(hConsole, coordScreen);
}
// ----------------------------------------------------------
// Get the screen size
// Using pass by reference
// ----------------------------------------------------------
void getScreenSize(int &width, int &height)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo( hConsole, &csbi );
width = csbi.dwSize.X;
height = csbi.dwSize.Y;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -