diff --git a/conctrl/README.md b/README.md similarity index 76% rename from conctrl/README.md rename to README.md index 69c77fc..86b4d24 100644 --- a/conctrl/README.md +++ b/README.md @@ -12,33 +12,38 @@ ## 开发环境   Windows,Visual Studio 2017 -## 说明 +## 注意事项   需要注意的是,窗格只是逻辑意义上的窗格,它们属于同一个控制台窗口,共享输入缓冲区,因此这个库仅**适用于需要多个窗格用于输出**而不超过1个窗格同时用来输入。 -  构建这个库的初衷是为了方便某些高级语言操作控制台,因此将它的导出函数的参数都设定为简单的数值型和字符串,避免在高级语言中额外定义数据类型,方便使用。 +  分隔线是需要占用空间的,由于制表符是双字节字符,因此分隔线长度必须是2的倍数。同时注意,水平分割线的**高度**是1个字符,而**垂直分隔线的宽度是2个字符**。 + +  构建这个库的初衷是为了方便某些高级语言操作控制台,因此没有导出类而是封装了一系列C函数,并将它们的参数都设定为简单的数值型和字符串,避免在高级语言中额外定义数据类型,方便使用。 +###   **你不应该直接操作ConsoleWindow、Pannel、和Spliter类对象**,而应仅将它们的指针作为参数传递。   此库通过调用Windows API实现,因此仅适用于Windows系统。 +## 使用示例 +* ### C/C++ + 将conctrl.dll和conctrl.h放到同一目录; + +* ### 其他语言 + + + +## 导出函数列表 + + ## 缺陷 * 对用户输入的控制比较无力 * 只能对整行设定字符样式 * 其他 -## 使用示例 -* ### C/C++ - -* ### 其他语言 - - - -## 函数列表 - - ## 辅助资料 ### Windows控制台字符样式常量 +定义于consoleapi2.h,使用引入windows.h或自定义 ```C #define FOREGROUND_BLUE 0x0001 // text color contains blue. #define FOREGROUND_GREEN 0x0002 // text color contains green. @@ -59,4 +64,4 @@ ``` ## 项目地址 -[https://github.com/mattuy/conctrl.git](https://github.com/mattuy/conctrl.git) \ No newline at end of file +[https://github.com/mattuylee/conctrl.git](https://github.com/mattuylee/conctrl.git) \ No newline at end of file diff --git a/conctrl/conctrl.cpp b/conctrl/conctrl.cpp index 13a4218..961eea3 100644 --- a/conctrl/conctrl.cpp +++ b/conctrl/conctrl.cpp @@ -1,4 +1,8 @@ #include +#include "console_window.h" +#include "pannel.h" +#include "spliter.h" +#include "coding.h" #include "conctrl.h" //ǰ̨ڶӦĿƴ diff --git a/conctrl/conctrl.def b/conctrl/conctrl.def index fe3985d..b64a85c 100644 --- a/conctrl/conctrl.def +++ b/conctrl/conctrl.def @@ -18,5 +18,3 @@ FocusOnPannel CreateSpliter DestroySpliter MoveSpliter - - diff --git a/conctrl/conctrl.h b/conctrl/conctrl.h index 9abf226..fc37927 100644 --- a/conctrl/conctrl.h +++ b/conctrl/conctrl.h @@ -1,13 +1,11 @@ // ConsoleController // 2018-11-28 // By Mattuy - #ifndef _HEAD_CONSOLE_CONTROLLER_ #define _HEAD_CONSOLE_CONTROLLER_ -#include "console_window.h" -#include "pannel.h" -#include "spliter.h" -#include "coding.h" +class ConsoleWindow; +class Pannel; +class Spliter; /** * ̨ * @return value, ָǰ̨Ŀָ̨룬ΪIJͨ diff --git a/conctrl/conctrl.vcxproj b/conctrl/conctrl.vcxproj index 4e064dd..7a2d09a 100644 --- a/conctrl/conctrl.vcxproj +++ b/conctrl/conctrl.vcxproj @@ -33,8 +33,8 @@ + - 15.0 @@ -50,7 +50,7 @@ MultiByte - Application + DynamicLibrary false v141 true @@ -95,6 +95,9 @@ true true + + conctrl.def + @@ -103,6 +106,9 @@ true true + + conctrl.def + @@ -116,6 +122,7 @@ true true + conctrl.def @@ -130,6 +137,7 @@ true true + conctrl.def diff --git a/conctrl/conctrl.vcxproj.filters b/conctrl/conctrl.vcxproj.filters index 8976d81..e33893b 100644 --- a/conctrl/conctrl.vcxproj.filters +++ b/conctrl/conctrl.vcxproj.filters @@ -49,10 +49,10 @@ - + Resource Files - + Resource Files diff --git a/conctrl/pannel.cpp b/conctrl/pannel.cpp index 2509343..1cf183a 100644 --- a/conctrl/pannel.cpp +++ b/conctrl/pannel.cpp @@ -65,7 +65,7 @@ void Pannel::Move(SMALL_RECT rect) { */ 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; lines.pop_back(); } @@ -102,7 +102,7 @@ void Pannel::Flush() { if (this->lines.size() == 0) return; //ջ //ȡ std::vector::iterator iter; - if (this->lines.size() <= lineCount) { + if (this->lines.size() <= (size_t)lineCount) { iter = this->lines.begin(); } //ʾ else if (this->from < 0 || this->from >= this->lines.size()) { @@ -113,7 +113,7 @@ void Pannel::Flush() { } //ʾض //дı COORD lineStart = { 0, 0 }; - for (size_t i = 0; i < lineCount; i++) { + for (size_t i = 0; i < (size_t)lineCount; i++) { DWORD writtenCount; //ȡȥзַ int length = iter->text.size(); @@ -138,11 +138,11 @@ bool Pannel::ScrollForward(int lineCount) { int to = this->from; if (this->from < 0 || lineCount < 0) return false; else to += lineCount; - return ScrollTo(to < this->lines.size() ? to : -1); + return ScrollTo(to < (int)this->lines.size() ? to : -1); } // bool Pannel::ScrollTo(int line) { - if (line >= this->lines.size()) return false; + if (line >= (int)this->lines.size()) return false; int to = line < 0 ? -1 : line; if (this->from != to) { this->from = to; @@ -164,7 +164,7 @@ bool Pannel::Focus(COORD _coord){ return SetConsoleCursorPosition(this->window->hOutput, coord); } -//ıָΪС +//ıָΪУٱ֤һ std::vector Pannel::splitToLines(std::string _text) { int charCount = this->area.Right - this->area.Left + 1; if (charCount <= 0) { @@ -178,12 +178,13 @@ std::vector Pannel::splitToLines(std::string _text) { do { int i; line = ""; - for (i = 0; i < charCount; i++) { - if (!text[start + i]) break; //ıβ + for (i = 0; text[start + i] && i < charCount; i++) { if (text[start + i] == '\r' || text[start + i] == '\n') { line += "\r\n"; break; } //Ȼеβз + //һַ޷ʾ˫ַֽ + if (i == charCount - 1 && text[i + start] > 127) break; line += text[i + start]; } //ɨһУѼ߿ //˻з diff --git a/conctrl/spliter.cpp b/conctrl/spliter.cpp index f2ac633..9835dc5 100644 --- a/conctrl/spliter.cpp +++ b/conctrl/spliter.cpp @@ -32,9 +32,9 @@ void Spliter::draw(bool clear) { //ȡ SHORT* direct = this->verticle ? &curPosition.Y : &curPosition.X; //ָ - for (SHORT i = 0; i < this->length; i++) { + for (; *direct < this->length; ) { FillConsoleOutputAttribute(this->window->hOutput, this->attribute, 2, curPosition, &written); WriteConsoleOutputCharacter(this->window->hOutput, spliter, 2, curPosition, &written); - this->verticle ? curPosition.Y += 2 : curPosition.X += 2; + this->verticle ? curPosition.Y += 1 : curPosition.X += 2; } } diff --git a/conctrl/test.cpp b/conctrl/test.cpp deleted file mode 100644 index e5d3e82..0000000 --- a/conctrl/test.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "conctrl.h" -int main() { - ConsoleWindow* window = CreateConsoleWindow(80, 40); - Pannel* writePannel = window->CreatePannel({ 0, 0, 79, 24 }); - Pannel* messagePannel = window->CreatePannel({ 0, 26, 79, 39 }); - Spliter* spliter = window->CreateSpliter({ 0, 25 }, 80, false, FOREGROUND_GREEN); - messagePannel->AddLine("hello world."); - writePannel->Focus({ 0,0 }); - getchar(); -} \ No newline at end of file