修复一大堆bug中的一小堆bug

This commit is contained in:
2018-12-01 23:20:15 +08:00
parent b9b6d3d28b
commit 6c7ea5b3f8
13 changed files with 341 additions and 134 deletions
+41 -5
View File
@@ -9,6 +9,8 @@
&emsp;&emsp;你可以为每一**行**设定字符格式,字符格式由Windows的一些<a href="#constant">常量</a>定义。 &emsp;&emsp;你可以为每一**行**设定字符格式,字符格式由Windows的一些<a href="#constant">常量</a>定义。
## 开发环境 ## 开发环境
&emsp;&emsp;WindowsVisual Studio 2017 &emsp;&emsp;WindowsVisual Studio 2017
@@ -22,10 +24,13 @@
&emsp;&emsp;此库通过调用Windows API实现,因此仅适用于Windows系统。 &emsp;&emsp;此库通过调用Windows API实现,因此仅适用于Windows系统。
## 使用示例 ## 使用方法
* ### C/C++ * ### C++
将conctrl.dll和conctrl.h放到同一目录; 将conctrl.hconctrl.dll和conctrl.lib放在源代码目录,并在源代码中添加:
> `#include "conctrl.h"`
> `#pragma comment(lib, "conctrl.lib")`
<a href="#usage_cpp">查看示例</a>
* ### 其他语言 * ### 其他语言
@@ -39,10 +44,41 @@
* 其他 * 其他
## 辅助资料 ## 使用示例
<a name="constant"> </a> <a name="usage_cpp"></a>
### C++VC
```C++
#include <stdio.h>
#include <Windows.h>
#include "conctrl.h"
#pragma comment(lib, "conctrl.lib")
int main() {
ConsoleWindow* window = CreateConsoleWindow(80, 40);
Pannel* messagePannel = CreatePannel(window, 0, 0, 78, 25);
Pannel* writePannel= CreatePannel(window, 0, 26, 80, 40);
Spliter* spliter = CreateSpliter(window, 0, 25, 80, false, FOREGROUND_GREEN);
AddPannelLine(messagePannel, "请在下方区域输入任意内容", false);
FocusOnPannel(writePannel, 0, 0);
while (true) {
char str[1024];
gets_s(str, 1024);
AddPannelLine(messagePannel, str, false, FOREGROUND_RED|FOREGROUND_GREEN);
ClearPannel(writePannel);
FocusOnPannel(writePannel, 0, 0);
}
}
```
```C
```
## 辅助资料
<a name="constant"></a>
### Windows控制台字符样式常量 ### Windows控制台字符样式常量
定义于consoleapi2.h,使用引入windows.h或自定义 定义于consoleapi2.h,使用引入windows.h或自定义
```C ```C
#define FOREGROUND_BLUE 0x0001 // text color contains blue. #define FOREGROUND_BLUE 0x0001 // text color contains blue.
+6 -5
View File
@@ -6,18 +6,19 @@
//将utf8编码的文本转换为ANSI编码(GBK) //将utf8编码的文本转换为ANSI编码(GBK)
std::string UTF8ToANSI(const char* str) { std::string UTF8ToANSI(const char* str) {
//统计字符数 //统计字符数
int wideCharCount = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0); int wideCharCount = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (wideCharCount == 0) { if (wideCharCount == 0) {
return "?"; return "?";
} }
//为Unicode缓冲区申请空间 //为Unicode缓冲区申请空间
wchar_t* wideCharBufer = (wchar_t*)malloc(sizeof(wchar_t) * wideCharCount); //!!注意此处,务必将内存初始化为0值。因为MultiByteToWideChar因为未知原因似乎不会主动添'\0'结束符
wchar_t* wideCharBufer = (wchar_t*)calloc(wideCharCount, sizeof(wchar_t));
//转换成Unicode //转换成Unicode
MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), wideCharBufer, wideCharCount); MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), wideCharBufer, wideCharCount);
//转换为ANSI //转换为ANSI
int multiByteCharCount = WideCharToMultiByte(CP_ACP, 0, wideCharBufer, wideCharCount, NULL, 0, NULL, NULL); int multiByteCharCount = WideCharToMultiByte(936, 0, wideCharBufer, wideCharCount, NULL, 0, NULL, NULL);
char* mutiByteCharBuffer = (char*)malloc(sizeof(char) * multiByteCharCount); char* mutiByteCharBuffer = (char*)calloc(multiByteCharCount, sizeof(char));
int result = WideCharToMultiByte(CP_ACP, 0, wideCharBufer, wideCharCount, mutiByteCharBuffer, multiByteCharCount, NULL, NULL); int result = WideCharToMultiByte(936, 0, wideCharBufer, wideCharCount, mutiByteCharBuffer, multiByteCharCount, NULL, NULL);
if (!result) if (!result)
return "???"; return "???";
std::string text(mutiByteCharBuffer); std::string text(mutiByteCharBuffer);
+17 -11
View File
@@ -1,4 +1,4 @@
#include <iostream> #define _CRT_SECURE_NO_WARNINGS
#include "console_window.h" #include "console_window.h"
#include "pannel.h" #include "pannel.h"
#include "spliter.h" #include "spliter.h"
@@ -9,11 +9,17 @@
ConsoleWindow* CreateConsoleWindow(int width, int height) { ConsoleWindow* CreateConsoleWindow(int width, int height) {
if (width <= 5 || height <= 5 || width > 32767 || height > 32767) if (width <= 5 || height <= 5 || width > 32767 || height > 32767)
return new(std::nothrow) ConsoleWindow(); return new(std::nothrow) ConsoleWindow();
else else {
return new(std::nothrow) ConsoleWindow(width, height); return new(std::nothrow) ConsoleWindow(width, height);
}
} }
void DestroyConsoleWindow(ConsoleWindow* window) {
delete window;
}
//重新设置窗口和缓冲区大小 //重新设置窗口和缓冲区大小
bool ResizeConsoleWindow(ConsoleWindow* window, int width, int height) { bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height) {
if (width <= 5 || height <= 5 || width > 32767 || height > 32767) if (width <= 5 || height <= 5 || width > 32767 || height > 32767)
return false; return false;
return window->Resize({ (SHORT)width, (SHORT)height }); return window->Resize({ (SHORT)width, (SHORT)height });
@@ -29,10 +35,10 @@ bool SetConsoleWindowTitle(char* _title, bool utf8) {
} }
//创建一个窗格 //创建一个窗格
Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height) { Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height) {
if (left < 0 || top < 0 || width <= 5 || height <= 5 if (left < 0 || top < 0
|| left > 32767 || top > 32767 || width > 32767 || height > 32767 || left > 32767 || top > 32767 || width > 32767 || height > 32767
) return NULL; ) return NULL;
return window->NewPannel({ (SHORT)left, (SHORT)top, (SHORT)width - 1, (SHORT)height - 1 }); return window->NewPannel({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1) });
} }
//删除窗格 //删除窗格
void DestroyPannel(ConsoleWindow* window, Pannel* pannel) { void DestroyPannel(ConsoleWindow* window, Pannel* pannel) {
@@ -45,18 +51,18 @@ bool SetMaxLineCache(Pannel* pannel, int lineCount) {
return true; return true;
} }
//向Pannel中添加文本 //向Pannel中添加文本
void AddPannelText(Pannel* pannel, const char* _text, bool utf8, int attribute) { void AddPannelText(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) {
std::string text; std::string text;
if (utf8) text = UTF8ToANSI(_text); if (utf8) text = UTF8ToANSI(_text);
else text = _text; else text = _text;
pannel->AddText(text, attribute); pannel->AddText(text, focus, attribute);
} }
//向Pannel中添加行 //向Pannel中添加行
void AddPannelLine(Pannel* pannel, const char* _text, bool utf8, int attribute) { void AddPannelLine(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) {
std::string text; std::string text;
if (utf8) text = UTF8ToANSI(_text); if (utf8) text = UTF8ToANSI(_text);
else text = _text; else text = _text;
pannel->AddLine(text, attribute); pannel->AddLine(text, focus, attribute);
} }
//清空Pannel //清空Pannel
void ClearPannel(Pannel* pannel) { void ClearPannel(Pannel* pannel) {
@@ -69,7 +75,7 @@ bool MovePannel(Pannel* pannel, int left, int top, int width, int height) {
if (top < 0) top = pannel->area.Top; if (top < 0) top = pannel->area.Top;
if (width <= 5) width = pannel->area.Right - pannel->area.Left + 1; if (width <= 5) width = pannel->area.Right - pannel->area.Left + 1;
if (height <= 5) height = pannel->area.Bottom - pannel->area.Top+ 1; if (height <= 5) height = pannel->area.Bottom - pannel->area.Top+ 1;
pannel->Move({ (SHORT)left, (SHORT)top, (SHORT)width - 1, (SHORT)height - 1}); pannel->Move({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1)});
return true; return true;
} }
//向前滚屏 //向前滚屏
@@ -86,7 +92,7 @@ bool ScrollPannelTo(Pannel* pannel, int lineTo) {
} }
//将光标设置到窗格的特定位置 //将光标设置到窗格的特定位置
bool FocusOnPannel(Pannel* pannel, int offsetLeft, int offsetTop) { bool FocusOnPannel(Pannel* pannel, int offsetLeft, int offsetTop) {
return pannel->Focus({ (SHORT)offsetLeft, (SHORT)offsetTop}); return pannel->Focus({ (SHORT)offsetLeft, (SHORT)offsetTop });
} }
//创建一条分隔线。 //创建一条分隔线。
Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute) { Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute) {
+2 -1
View File
@@ -2,7 +2,8 @@ LIBRARY conctrl
EXPORTS EXPORTS
CreateConsoleWindow CreateConsoleWindow
ResizeConsoleWindow DestroyConsoleWindow
ResizeScreenBuffer
SetConsoleWindowTitle SetConsoleWindowTitle
CreatePannel CreatePannel
DestroyPannel DestroyPannel
+47 -36
View File
@@ -3,27 +3,36 @@
// By Mattuy // By Mattuy
#ifndef _HEAD_CONSOLE_CONTROLLER_ #ifndef _HEAD_CONSOLE_CONTROLLER_
#define _HEAD_CONSOLE_CONTROLLER_ #define _HEAD_CONSOLE_CONTROLLER_
#ifdef __cplusplus //cpp
class ConsoleWindow; class ConsoleWindow;
class Pannel; class Pannel;
class Spliter; class Spliter;
/** #else //C
typedef void ConsoleWindow;
typedef void Pannel;
typedef void Spliter;
#endif
extern "C" {
/**
* 创建控制台控制器 * 创建控制台控制器
* @return value, 指向当前控制台的控制台操作对象的指针,作为其他函数的参数,以通过它控制 * @return value, 指向当前控制台的控制台操作对象的指针,作为其他函数的参数,以通过它控制
* 控制台。失败返回0 * 控制台。失败返回0
* @param width, 控制台窗口宽度,有效范围(5, 32767),默认80 * @param width, 屏幕缓冲区宽度,有效范围(5, 32767),默认80
* @param height, 控制台窗口高度,有效范围(5, 32767),默认40 * @param height, 屏幕缓冲区高度,有效范围(5, 32767),默认40
*/ */
ConsoleWindow* CreateConsoleWindow(int width = 80, int height = 40); ConsoleWindow* CreateConsoleWindow(int width = 80, int height = 40);
//重新设置窗口和缓冲区大小 //还原控制台,销毁控制器
bool ResizeConsoleWindow(ConsoleWindow* window, int width, int height); void DestroyConsoleWindow(ConsoleWindow* window);
/** //重新设置窗口和缓冲区大小
bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height);
/**
* 设置控制台窗口标题 * 设置控制台窗口标题
* @param window, 要设置标题的窗口 * @param window, 要设置标题的窗口
* @param title, 要设置的标题 * @param title, 要设置的标题
* @param utf8, 是否utf8编码。UTF-8请设为非0,否则当作ANSI处理 * @param utf8, 是否utf8编码。UTF-8请设为非0,否则当作ANSI处理
*/ */
bool SetConsoleWindowTitle(char* title, bool utf8 = false); bool SetConsoleWindowTitle(char* title, bool utf8 = false);
/** /**
* 创建一个窗格。 * 创建一个窗格。
* @return value, 指向一个窗格的指针 * @return value, 指向一个窗格的指针
* @param window, 窗格所属窗口 * @param window, 窗格所属窗口
@@ -32,47 +41,48 @@ bool SetConsoleWindowTitle(char* title, bool utf8 = false);
* @param width, 窗格的宽度,有效范围(5, 32767) * @param width, 窗格的宽度,有效范围(5, 32767)
* @param height, 窗格的高度,有效范围(5, 32767) * @param height, 窗格的高度,有效范围(5, 32767)
*/ */
Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height); Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height);
//删除窗格 //删除窗格
void DestroyPannel(ConsoleWindow* window, Pannel* pannel); void DestroyPannel(ConsoleWindow* window, Pannel* pannel);
//设置窗格行缓存大小(行数) //设置窗格行缓存大小(行数)
bool SetlMaxLineCache(Pannel* pannel, int lineCount); bool SetMaxLineCache(Pannel* pannel, int lineCount);
/** /**
* 向Pannel中添加文本。如果行缓冲区中上一行不是换行符结尾或调用【AddPannelLine】函数添加的,新 * 向Pannel中添加文本。如果行缓冲区中上一行不是换行符结尾或调用【AddPannelLine】函数添加的,新
* 文本将合并到上一行。原文本属性也会被覆盖。 * 文本将合并到上一行。原文本属性也会被覆盖。
* @param window, 窗格所属窗口 * @param window, 窗格所属窗口
* @param text, 要添加的字符串 * @param text, 要添加的字符串
* @param focus, 是否将光标移动到新添加的文本后
* @param utf8, 是否utf8编码。仅支持ANSI编码和UTF-8编码,并且UTF-8编码也将被转换为ANSI * @param utf8, 是否utf8编码。仅支持ANSI编码和UTF-8编码,并且UTF-8编码也将被转换为ANSI
* 编码。默认为false * 编码。默认为false
* @param attribute, 行文本属性,由Windows定义的控制台常量,默认黑底白字 * @param attribute, 行文本属性,由Windows定义的控制台常量,默认黑底白字
*/ */
void AddPannelText(Pannel* pannel, const char* text, bool utf8 = false, int attribute = 7); void AddPannelText(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7);
//与AddText唯一的不同是,如果字符串不是以换行符结尾,将自动插入换行符 //与AddText唯一的不同是,如果字符串不是以换行符结尾,将自动插入换行符
void AddPannelLine(Pannel* pannel, const char* text, bool utf8 = false, int attribute = 7); void AddPannelLine(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7);
//清空Pannel。这将同时清除pannel的行缓冲区 //清空Pannel。这将同时清除pannel的行缓冲区
void ClearPannel(Pannel* pannel); void ClearPannel(Pannel* pannel);
//移动或改变Pannel大小,参数同【CreatePannel】。如果参数分量无效,该分量将不会改变 //移动或改变Pannel大小,参数同【CreatePannel】。如果参数分量无效,该分量将不会改变
bool MovePannel(Pannel* pannel, int left, int top, int width, int height); bool MovePannel(Pannel* pannel, int left, int top, int width, int height);
/** /**
* 向前滚屏。 * 向前滚屏。
* @return value, 如果滚动前已触顶返回false,否则返回true * @return value, 如果滚动前已触顶返回false,否则返回true
* @param pannel, 要滚动的窗格 * @param pannel, 要滚动的窗格
* @param lineCount, 要滚动的行数,如果小于0滚动一屏(相对窗格) * @param lineCount, 要滚动的行数,如果小于0滚动一屏(相对窗格)
*/ */
bool ScrollPannelBackward(Pannel* pannel, int lineCount); bool ScrollPannelBackward(Pannel* pannel, int lineCount);
//向后滚屏。 //向后滚屏。
bool ScrollPannelForward(Pannel* pannel, int lineCount); bool ScrollPannelForward(Pannel* pannel, int lineCount);
//滚动到特定行。如果行号小于0滚到最后,否则如果行号无效返回false //滚动到特定行。如果行号小于0滚到最后,否则如果行号无效返回false
bool ScrollPannelTo(Pannel* pannel, int lineTo); bool ScrollPannelTo(Pannel* pannel, int lineTo);
/** /**
* 将光标设置到窗格的特定位置。 * 将光标设置到窗格的特定位置。
* @return value, 如果offset超出窗格范围则设置失败 * @return value, 如果offset超出窗格范围则设置失败
* @param pannel, 要设置光标所在的窗格 * @param pannel, 要设置光标所在的窗格
* @param offsetLeft, 光标相对窗格左上角的水平偏移,默认为0 * @param offsetLeft, 光标相对窗格左上角的水平偏移,默认为0
* @param offsetTop, 光标相对窗格左上角的垂直偏移,默认为0 * @param offsetTop, 光标相对窗格左上角的垂直偏移,默认为0
*/ */
bool FocusOnPannel(Pannel* pannel, int offsetLeft = 0, int offsetTop = 0); bool FocusOnPannel(Pannel* pannel, int offsetLeft = 0, int offsetTop = 0);
/** /**
* 创建一条分隔线。 * 创建一条分隔线。
* @return value, 指向一条分隔线的指针 * @return value, 指向一条分隔线的指针
* @param window, 窗格所属的窗口 * @param window, 窗格所属的窗口
@@ -82,14 +92,15 @@ bool FocusOnPannel(Pannel* pannel, int offsetLeft = 0, int offsetTop = 0);
* @param verticle, 是水平分隔线还是竖直分隔线。0为水平,非0为竖直 * @param verticle, 是水平分隔线还是竖直分隔线。0为水平,非0为竖直
* @param attribute, 分割线的文本属性,由Windows定义的控制台常量,默认黑底白字 * @param attribute, 分割线的文本属性,由Windows定义的控制台常量,默认黑底白字
*/ */
Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute = 7); Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute = 7);
//删除分隔线 //删除分隔线
void DestroySpliter(Spliter* spliter); void DestroySpliter(ConsoleWindow* window, Spliter* spliter);
/** /**
* 移动或重新设定分隔线的长度 * 移动或重新设定分隔线的长度
* @param left, 相对窗格的水平偏移,如果小于0则不改变 * @param left, 相对窗格的水平偏移,如果小于0则不改变
* @param top, 相对窗口的垂直偏移,如果小于0则不改变 * @param top, 相对窗口的垂直偏移,如果小于0则不改变
* @param len, 新的长度/高度。如果小于0则不改变 * @param len, 新的长度/高度。如果小于0则不改变
*/ */
bool MoveSpliter(int left, int top, int len); bool MoveSpliter(Spliter* spliter, int left, int top, int len);
}
#endif // !_HEAD_CONSOLE_CONTROLLER_ #endif // !_HEAD_CONSOLE_CONTROLLER_
+1 -1
View File
@@ -57,7 +57,7 @@
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset> <PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
+8 -8
View File
@@ -21,6 +21,7 @@ bool ConsoleWindow::InitWindow() {
//重新设定窗口缓冲区大小 //重新设定窗口缓冲区大小
bool ConsoleWindow::Resize(COORD size) { bool ConsoleWindow::Resize(COORD size) {
bool success = false;
//记录原来的窗口信息 //记录原来的窗口信息
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(this->hOutput, &info); GetConsoleScreenBufferInfo(this->hOutput, &info);
@@ -29,14 +30,13 @@ bool ConsoleWindow::Resize(COORD size) {
SMALL_RECT rect = { 0, 0, 5, 5 }; SMALL_RECT rect = { 0, 0, 5, 5 };
if (!SetConsoleWindowInfo(this->hOutput, true, &rect)) if (!SetConsoleWindowInfo(this->hOutput, true, &rect))
return false; return false;
if (!SetConsoleScreenBufferSize(hOutput, { size.X, size.Y })) { success = SetConsoleScreenBufferSize(hOutput, { size.X, size.Y });
SetConsoleWindowInfo(this->hOutput, true, &info.srWindow); //还原窗口 rect = info.srWindow;
return false; //调整窗口
} if (rect.Right - rect.Left + 1 > size.X || !success) rect.Right = rect.Left + size.X - 1;
//设置窗口大小 if (rect.Bottom - rect.Top + 1 > size.Y || !success) rect.Bottom = rect.Top + size.Y - 1;
rect = { 0, 0, size.X - 1, size.Y - 1 }; SetConsoleWindowInfo(this->hOutput, true, &rect); //还原窗口
SetConsoleWindowInfo(this->hOutput, true, &rect); return success;
return true;
} }
//创建窗格 //创建窗格
+20 -11
View File
@@ -7,6 +7,10 @@ Pannel::Pannel(ConsoleWindow* _controller, SMALL_RECT rect) {
this->from = -1; //默认打印最新行 this->from = -1; //默认打印最新行
this->maxLineCount = 4096; this->maxLineCount = 4096;
} }
Pannel::~Pannel() {
this->clearScreen();
}
//设置最大行数 //设置最大行数
void Pannel::SetMaxLine(SHORT lineCount) { void Pannel::SetMaxLine(SHORT lineCount) {
if (lineCount < 0) lineCount = 0; if (lineCount < 0) lineCount = 0;
@@ -57,13 +61,8 @@ void Pannel::Move(SMALL_RECT rect) {
} //重新分割文本行 } //重新分割文本行
this->Flush(); this->Flush();
} }
/** //向窗格添加文本
* 向窗格添加文本 void Pannel::AddText(std::string text, bool focus, int attribute) {
* @return value, 成功返回true, 否则返回false
* @param text, 要写入的文本
* @param attribute, 文本属性,详见 FORGROUND_*和BACKGROUND_* 常量
*/
void Pannel::AddText(std::string text, int attribute) {
//将要添加的文本与最后一行拼接。否则每次调用本函数将直接写到新行 //将要添加的文本与最后一行拼接。否则每次调用本函数将直接写到新行
if (this->lines.size() > 0 && !this->isTrueLine(lines.back())) { if (this->lines.size() > 0 && !this->isTrueLine(lines.back())) {
text = this->lines.back().text + text; text = this->lines.back().text + text;
@@ -81,12 +80,22 @@ void Pannel::AddText(std::string text, int attribute) {
line.attribute = attribute; line.attribute = attribute;
this->lines.push_back(line); this->lines.push_back(line);
} //加入新的文本行 } //加入新的文本行
//把光标置到新添加的文本之后
if (focus && this->lines.size()) {
COORD coord;
coord.X = isTrueLine(lines.back()) ? 0 : this->lines.back().text.size();
if (this->lines.size() > this->area.Bottom - this->area.Top + 1) coord.Y = this->area.Bottom;
else coord.Y = this->lines.size() - 1;
coord.Y = isTrueLine(lines.back()) ? coord.Y + 1 : coord.Y;
this->Focus(coord);
}
else if (focus) this->Focus({ 0,0 });
this->Flush(); this->Flush();
} }
//添加行 //添加行
void Pannel::AddLine(std::string text, int attribute) { void Pannel::AddLine(std::string text, bool focus, int attribute) {
if (text.size() && !this->isTrueLine(text)) text += '\n'; if (text.size() && !this->isTrueLine(text)) text += '\n';
this->AddText(text, attribute); this->AddText(text, focus, attribute);
}; };
//刷新显示 //刷新显示
@@ -159,8 +168,8 @@ bool Pannel::Focus(COORD _coord){
return false; return false;
} }
COORD coord; COORD coord;
coord.X = this->area.Left + _coord.X; coord.X = this->area.Left +_coord.X;
coord.Y = this->area.Top + _coord.Y; coord.Y = this->area.Top +_coord.Y;
return SetConsoleCursorPosition(this->window->hOutput, coord); return SetConsoleCursorPosition(this->window->hOutput, coord);
} }
+3 -2
View File
@@ -14,6 +14,7 @@ public:
SHORT maxLineCount; //最大保存文本行数 SHORT maxLineCount; //最大保存文本行数
SMALL_RECT area; //窗格区域(包含边框) SMALL_RECT area; //窗格区域(包含边框)
Pannel(ConsoleWindow* window, SMALL_RECT rect); Pannel(ConsoleWindow* window, SMALL_RECT rect);
~Pannel();
//设置最大缓存行数 //设置最大缓存行数
void SetMaxLine(SHORT lineCount); void SetMaxLine(SHORT lineCount);
//清空窗格文本 //清空窗格文本
@@ -21,9 +22,9 @@ public:
//移动窗格和重新设置大小 //移动窗格和重新设置大小
void Move(SMALL_RECT rect); void Move(SMALL_RECT rect);
//向窗格中加入文本 //向窗格中加入文本
void AddText(std::string text, int attribute = 7); void AddText(std::string text, bool focus = false, int attribute = 7);
//向窗格中加入文本行 //向窗格中加入文本行
void AddLine(std::string text, int attribute = 7); void AddLine(std::string text, bool focus = false, int attribute = 7);
//从特定行开始打印一屏。若this.from无效则打印最后一屏 //从特定行开始打印一屏。若this.from无效则打印最后一屏
void Flush(); void Flush();
//向前滚动,当前已到达最前页返回false,否则返回true //向前滚动,当前已到达最前页返回false,否则返回true
+4
View File
@@ -10,6 +10,10 @@ Spliter::Spliter(ConsoleWindow* window, COORD pos, SHORT len, bool verticle, WOR
this->draw(); this->draw();
} }
Spliter::~Spliter() {
this->Clear();
}
void Spliter::Clear() { void Spliter::Clear() {
this->draw(true); this->draw(true);
} }
+1
View File
@@ -11,6 +11,7 @@ public:
COORD position; //位置 COORD position; //位置
SHORT length; //宽度/高度 SHORT length; //宽度/高度
Spliter(ConsoleWindow* window, COORD pos, SHORT len, bool verticle, WORD attr = 7); Spliter(ConsoleWindow* window, COORD pos, SHORT len, bool verticle, WORD attr = 7);
~Spliter();
//从屏幕清除 //从屏幕清除
void Clear(); void Clear();
//移动或重新设置长度 //移动或重新设置长度
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{629BA97E-AE88-4F62-8ABB-EDBC575D5284}</ProjectGuid>
<RootNamespace>test</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
</Project>