diff --git a/README.md b/README.md
index 592a682..1450eea 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
你可以为每一**行**设定字符格式,字符格式由Windows的一些常量定义。
- 这不是一个设计严谨的库,使用需谨慎。
+ 最初只是为了在某个高级语言中控制控制台输出而写这些函数,**这不是一个设计严谨的库,使用需谨慎。**
## 开发环境
Windows,Visual Studio 2017
@@ -28,7 +28,7 @@
## 使用方法
* ### C++
- 将代码目录里的conctrl.h,编译得到的conctrl.dll和conctrl.lib放在相同目录,在你的代码中添加:
+ 将代码目录里的conctrl.h,编译得到的conctrl.dll和conctrl.lib放在VS项目目录,在你的代码中添加:
> `#include "conctrl.h"`
> `#pragma comment(lib, "conctrl.lib")`
@@ -41,8 +41,6 @@
分隔线是需要占用空间的,由于制表符是双字节字符,因此分隔线长度必须是2的倍数。同时注意,水平分割线的**高度**是1个字符,而**垂直分隔线的宽度是2个字符**。
- 构建这个库的初衷是为了方便某些高级语言操作控制台,因此没有导出类而是封装了一系列C函数,并将它们的参数都设定为简单的数值型和字符串,避免在高级语言中额外定义数据类型,方便使用。
-
**你不应该直接操作ConsoleWindow、Pannel、和Spliter类对象**,而应仅将它们的指针作为参数传递。
此库通过调用Windows API实现,因此仅适用于Windows系统。
@@ -125,17 +123,18 @@
#include
#include
#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);
- AddPannelText(messagePannel, "输入任意内容,回车发送", true, true, 7);
+ ConsoleWindow* window = CreateConsoleWindow(100, 30);
+ Pannel* messagePannel = CreatePannel(window, 0, 0, 100, 20);
+ Pannel* writePannel = CreatePannel(window, 0, 21, 100, 9);
+ Spliter* spliter = CreateSpliter(window, 0, 20, 100, false, FOREGROUND_GREEN);
+ AddPannelLine(messagePannel, "请在下方输入任意内容,回车发送", false, false, 7);
FocusOnPannel(writePannel, 0, 0);
while (true) {
- char str[1024];
- gets_s(str, 1023);
- AddPannelText(messagePannel, str, false, false, FOREGROUND_RED | FOREGROUND_GREEN);
+ char text[1024];
+ gets_s(text, 1023);
+ AddPannelLine(messagePannel, text, false, false, FOREGROUND_RED | FOREGROUND_GREEN);
ClearPannel(writePannel);
FocusOnPannel(writePannel, 0, 0);
}
@@ -174,14 +173,6 @@ conctrl
#define BACKGROUND_GREEN 0x0020 // background color contains green.
#define BACKGROUND_RED 0x0040 // background color contains red.
#define BACKGROUND_INTENSITY 0x0080 // background color is intensified.
-#define COMMON_LVB_LEADING_BYTE 0x0100 // Leading Byte of DBCS
-#define COMMON_LVB_TRAILING_BYTE 0x0200 // Trailing Byte of DBCS
-#define COMMON_LVB_GRID_HORIZONTAL 0x0400 // DBCS: Grid attribute: top horizontal.
-#define COMMON_LVB_GRID_LVERTICAL 0x0800 // DBCS: Grid attribute: left vertical.
-#define COMMON_LVB_GRID_RVERTICAL 0x1000 // DBCS: Grid attribute: right vertical.
-#define COMMON_LVB_REVERSE_VIDEO 0x4000 // DBCS: Reverse fore/back ground attribute.
-#define COMMON_LVB_UNDERSCORE 0x8000 // DBCS: Underscore.
-#define COMMON_LVB_SBCSDBCS 0x0300 // SBCS or DBCS flag.
```
## 项目地址
diff --git a/test.png b/test.png
new file mode 100644
index 0000000..0e8dd03
Binary files /dev/null and b/test.png differ
diff --git a/test_x64/conctrl.cpp b/test_x64/conctrl.cpp
deleted file mode 100644
index 450a0b0..0000000
--- a/test_x64/conctrl.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-#define _CRT_SECURE_NO_WARNINGS
-#include "console_window.h"
-#include "pannel.h"
-#include "spliter.h"
-#include "coding.h"
-#include "conctrl.h"
-
-//ǰ̨ڶӦĿƴ
-ConsoleWindow* CreateConsoleWindow(int width, int height) {
- if (width <= 5 || height <= 5 || width > 32767 || height > 32767)
- return new(std::nothrow) ConsoleWindow();
- else {
- return new(std::nothrow) ConsoleWindow(width, height);
- }
-}
-
-void DestroyConsoleWindow(ConsoleWindow* window) {
- delete window;
-}
-
-//ôںͻС
-bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height) {
- if (width <= 5 || height <= 5 || width > 32767 || height > 32767)
- return false;
- return window->Resize({ (SHORT)width, (SHORT)height });
-}
-//ÿ̨ڱ
-bool SetConsoleWindowTitle(char* _title, bool utf8) {
- if (utf8) {
- std::string title;
- title = UTF8ToANSI(_title);
- return SetConsoleTitle(title.c_str());
- }
- return SetConsoleTitle(_title);
-}
-//һ
-Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height) {
- if (left < 0 || top < 0
- || left > 32767 || top > 32767 || width > 32767 || height > 32767
- ) return NULL;
- return window->NewPannel({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1) });
-}
-//ɾ
-void DestroyPannel(ConsoleWindow* window, Pannel* pannel) {
- window->RemovePannel(pannel);
-}
-//PannelлС
-bool SetMaxLineCache(Pannel* pannel, int lineCount) {
- if (lineCount < 0) return false;
- pannel->maxLineCount = lineCount;
- return true;
-}
-//Pannelı
-void AddPannelText(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) {
- std::string text;
- if (utf8) text = UTF8ToANSI(_text);
- else text = _text;
- pannel->AddText(text, focus, attribute);
-}
-//Pannel
-void AddPannelLine(Pannel* pannel, const char* _text, bool focus, bool utf8, int attribute) {
- std::string text;
- if (utf8) text = UTF8ToANSI(_text);
- else text = _text;
- pannel->AddLine(text, focus, attribute);
-}
-//Pannel
-void ClearPannel(Pannel* pannel) {
- pannel->Clear();
-}
-//ƶıPannelС
-bool MovePannel(Pannel* pannel, int left, int top, int width, int height) {
- if(left > 32767 || top > 32767 || width > 32767 || height > 32767) return false;
- if (left < 0) left = pannel->area.Left;
- if (top < 0) top = pannel->area.Top;
- if (width <= 5) width = pannel->area.Right - pannel->area.Left + 1;
- if (height <= 5) height = pannel->area.Bottom - pannel->area.Top+ 1;
- pannel->Move({ (SHORT)left, (SHORT)top, (SHORT)(left + width - 1), (SHORT)(top + height - 1)});
- return true;
-}
-//ǰ
-bool ScrollPannelBackward(Pannel* pannel, int lineCount) {
- return pannel->ScrollBackward(lineCount);
-}
-//
-bool ScrollPannelForward(Pannel* pannel, int lineCount) {
- return pannel->ScrollForward(lineCount);
-}
-//ض
-bool ScrollPannelTo(Pannel* pannel, int lineTo) {
- return pannel->ScrollTo(lineTo);
-}
-//õضλ
-bool FocusOnPannel(Pannel* pannel, int offsetLeft, int offsetTop) {
- return pannel->Focus({ (SHORT)offsetLeft, (SHORT)offsetTop });
-}
-//һָߡ
-Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute) {
- if (length <= 0
- || left < 0 || left >= window->bufferSize.X
- || top < 0 || top >= window->bufferSize.Y
- ) return NULL;
- return window->NewSpliter({ (SHORT)left, (SHORT)top}, length, verticle, attribute);
-}
-//ɾָ
-void DestroySpliter(ConsoleWindow* window, Spliter* spliter) {
- window->RemoveSpliter(spliter);
-}
-//ƶ趨ָ߳
-bool MoveSpliter(Spliter* spliter, int left, int top, int len) {
- if (left < 0 || left > 32767 || top < 0 || top > 32767 || len < 0) return false;
- spliter->Move({ (SHORT)left, (SHORT)top }, len);
- return true;
-}
diff --git a/test_x64/conctrl.dll b/test_x64/conctrl.dll
deleted file mode 100644
index 2fae2ce..0000000
Binary files a/test_x64/conctrl.dll and /dev/null differ
diff --git a/test_x64/conctrl.h b/test_x64/conctrl.h
deleted file mode 100644
index b215540..0000000
--- a/test_x64/conctrl.h
+++ /dev/null
@@ -1,106 +0,0 @@
-// ConsoleController
-// 2018-11-28
-// By Mattuy
-#ifndef _HEAD_CONSOLE_CONTROLLER_
-#define _HEAD_CONSOLE_CONTROLLER_
-#ifdef __cplusplus //cpp
-class ConsoleWindow;
-class Pannel;
-class Spliter;
-#else //C
-typedef void ConsoleWindow;
-typedef void Pannel;
-typedef void Spliter;
-#endif
-extern "C" {
- /**
- * ̨
- * @return value, ָǰ̨Ŀָ̨룬ΪIJͨ
- * ̨ʧܷ0
- * @param width, ĻȣЧΧ(5, 32767)Ĭ80
- * @param height, Ļ߶ȣЧΧ(5, 32767)Ĭ40
- */
- ConsoleWindow* CreateConsoleWindow(int width = 80, int height = 40);
- //ԭ̨ٿ
- void DestroyConsoleWindow(ConsoleWindow* window);
- //ôںͻС
- bool ResizeScreenBuffer(ConsoleWindow* window, int width, int height);
- /**
- * ÿ̨ڱ
- * @param window, ҪñĴ
- * @param title, Ҫõı
- * @param utf8, Ƿutf8롣UTF-8Ϊ0ANSI
- */
- bool SetConsoleWindowTitle(char* title, bool utf8 = false);
- /**
- * һ
- * @return value, ָһָ
- * @param window,
- * @param left, ԴڵˮƽƫƣЧΧ(5, 32767)
- * @param top, ԴڵֱƫƣЧΧ(5, 32767)
- * @param width, ĿȣЧΧ(5, 32767)
- * @param height, ĸ߶ȣЧΧ(5, 32767)
- */
- Pannel* CreatePannel(ConsoleWindow* window, int left, int top, int width, int height);
- //ɾ
- void DestroyPannel(ConsoleWindow* window, Pannel* pannel);
- //ôлС
- bool SetMaxLineCache(Pannel* pannel, int lineCount);
- /**
- * PannelıлһвǻзβáAddPannelLineӵģ
- * ıϲһСԭıҲᱻǡ
- * @param window,
- * @param text, Ҫӵַ
- * @param focus, Ƿƶӵı
- * @param utf8, Ƿutf8롣֧ANSIUTF-8룬UTF-8ҲתΪANSI
- * 롣ĬΪfalse
- * @param attribute, ıԣWindowsĿ̨ĬϺڵװ
- */
- void AddPannelText(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7);
- //AddTextΨһIJͬǣַԻзβԶ뻻з
- void AddPannelLine(Pannel* pannel, const char* text, bool focus, bool utf8 = false, int attribute = 7);
- //Pannel⽫ͬʱpannelл
- void ClearPannel(Pannel* pannel);
- //ƶıPannelСͬCreatePannelЧ÷ı
- bool MovePannel(Pannel* pannel, int left, int top, int width, int height);
- /**
- * ǰ
- * @return value, ǰѴfalsetrue
- * @param pannel, ҪĴ
- * @param lineCount, ҪС0һԴ
- */
- bool ScrollPannelBackward(Pannel* pannel, int lineCount);
- //
- bool ScrollPannelForward(Pannel* pannel, int lineCount);
- //ضСкС0кЧfalse
- bool ScrollPannelTo(Pannel* pannel, int lineTo);
- /**
- * õضλá
- * @return value, offsetΧʧ
- * @param pannel, ҪùڵĴ
- * @param offsetLeft, ԴϽǵˮƽƫƣĬΪ0
- * @param offsetTop, ԴϽǵĴֱƫƣĬΪ0
- */
- bool FocusOnPannel(Pannel* pannel, int offsetLeft = 0, int offsetTop = 0);
- /**
- * һָߡ
- * @return value, ָһָߵָ
- * @param window, Ĵ
- * @param left, ָԴڵˮƽƫƣЧΧ(5, 32767)
- * @param top, ָԴڵֱƫƣЧΧ(5, 32767)
- * @param length, ָߵijȻȡǰǺȡ@param verticle
- * @param verticle, ˮƽֱָָߡ0Ϊˮƽ0Ϊֱ
- * @param attribute, ָߵıԣWindowsĿ̨ĬϺڵװ
- */
- Spliter* CreateSpliter(ConsoleWindow* window, int left, int top, int length, bool verticle, int attribute = 7);
- //ɾָ
- void DestroySpliter(ConsoleWindow* window, Spliter* spliter);
- /**
- * ƶ趨ָߵij
- * @param left, ԴˮƽƫƣС0ı
- * @param top, ԴڵĴֱƫƣС0ı
- * @param len, µij/߶ȡС0ı
- */
- bool MoveSpliter(Spliter* spliter, int left, int top, int len);
-}
-#endif // !_HEAD_CONSOLE_CONTROLLER_
diff --git a/test_x64/conctrl.lib b/test_x64/conctrl.lib
deleted file mode 100644
index 9f1234a..0000000
Binary files a/test_x64/conctrl.lib and /dev/null differ
diff --git a/test_x64/main.cpp b/test_x64/main.cpp
deleted file mode 100644
index d994ad0..0000000
--- a/test_x64/main.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include
-#include
-#include
-#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);
- AddPannelText(messagePannel, "请在下方输入任意内容", true, true, 7);
- FocusOnPannel(writePannel, 0, 0);
- while (true) {
- char text[1024];
- gets(text);
- AddPannelText(messagePannel, text, false, false, FOREGROUND_RED | FOREGROUND_GREEN);
- ClearPannel(writePannel);
- FocusOnPannel(writePannel, 0, 0);
- }
-}
\ No newline at end of file