📄 screen.h
字号:
/************************************************************************************
Copyright (c) 2000 Aaron O'Neil
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3) Redistributions in binary form must reproduce the above copyright notice on
program startup. Additional credits for program modification are acceptable
but original copyright and credits must be visible at startup.
4) You may charge a reasonable copying fee for any distribution of Mud Master.
You may charge any fee you choose for support of Mud Master. You may not
charge a fee for Mud Master itself.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**************************************************************************************/
//////////////////////////////////////////////////////////////
// 8/21/96 - Changed a lot of the functions in the class to
// be inline; hoping to speed some of the printing up.
class CScreen
{
public:
CScreen();
~CScreen();
// Returns TRUE if able to get a console handle.
BOOL IsValid() { return(m_hScreen != INVALID_HANDLE_VALUE); }
// Creates a new console screen buffer.
BOOL CreateNewScreen();
// Resets the console back to the standard output handle.
BOOL StandardHandle();
// Changes the text attributes.
BOOL SetColor(WORD wAttr)
{
m_wAttr = wAttr;
return(SetConsoleTextAttribute(m_hScreen,wAttr));
}
WORD GetColor() { return(m_wAttr); }
// Position the cursor.
BOOL Gotoxy(int x, int y)
{
m_dwCursor.X = x;
m_dwCursor.Y = y;
return(SetConsoleCursorPosition(m_hScreen,m_dwCursor));
}
BOOL Gotoxy(COORD dwPos)
{
m_dwCursor.X = dwPos.X;
m_dwCursor.Y = dwPos.Y;
return(SetConsoleCursorPosition(m_hScreen,dwPos));
}
// Following 2 versions don't save cursor pos.
BOOL Gotoxyns(int x, int y)
{
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
return(SetConsoleCursorPosition(m_hScreen,dwPos));
}
BOOL Gotoxyns(COORD dwPos)
{
return(SetConsoleCursorPosition(m_hScreen,dwPos));
}
// Clears the screen. Sets cursor to 0,0.
void ClearScreen();
// Prints text at current cursor pos.
void Print(const char *pszText);
void PrintCh(CHAR ch)
{
SetConsoleCursorPosition(m_hScreen,m_dwCursor);
unsigned long lNum;
WriteConsole(m_hScreen,&ch,1,&lNum,NULL);
SaveCursorPos();
}
void FillChar(int x, int y, int nWidth, CHAR ch, WORD wAttr);
void SaveCursorPos()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(m_hScreen,&csbi);
m_dwCursor.X = csbi.dwCursorPosition.X;
m_dwCursor.Y = csbi.dwCursorPosition.Y;
}
void SetFocus()
{
Gotoxyns(m_dwCursor);
SetConsoleTextAttribute(m_hScreen,m_wAttr);
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(m_hScreen,&cci);
cci.bVisible = FALSE;
SetConsoleCursorInfo(m_hScreen,&cci);
}
void ShowCursor()
{
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(m_hScreen,&cci);
cci.bVisible = TRUE;
SetConsoleCursorInfo(m_hScreen,&cci);
}
HANDLE m_hScreen;
COORD m_dwCursor;
protected:
WORD m_wAttr;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -