我应该如何在Windows上创建一个自定义图形控制台/终端?终端、自定义、控制台、创建一个

2023-09-04 01:31:28 作者:不期待不奢望不强求,

在Windows控制台界面(想想 CMD 窗口)是给用户带来了pretty的简单的GUI。效率与它处理的渲染,用户输入,和滚动水平然而非常高。用来创建这个接口中的方法,无疑是相当有别于传统的桌面图形用户界面。

The Windows console interface (think cmd window) is to the user a pretty simple GUI. The level of efficiency with which it handles rendering, user input, and scrolling is however very high. The methods used to create this interface are undoubtedly quite different to those of a traditional desktop GUI.

我有兴趣创建自己的自定义控制台/终端为Windows,pferably使用C#和.NET为基础的技术$ P $(如管理GDI +或WPF)。作为一个起点,我会很渴望简单地重新创建标准的简单的Windows外壳。我可以再扩大的事情,并从那里增加新的功能。

I am interested in creating my own custom console/terminal for Windows, preferably using C# and .NET-based technologies (e.g. managed GDI+ or WPF). As a starting point, I'd be quite keen simply to recreate the standard simple Windows shell. I could then expand things and add features from there.

我在寻找关于如何去建立这样一个控制台UI一般性指导,但一些具体要点包括:

I'm looking for general guidance on how to go about creating such a console UI, but some specific points include:

我应该用什么样的渲染模式?渲染循环?部分更新(如WPF)?该模型的WinForms(不知道这是如何工作)?

What sort of rendering model should I use? A render loop? Partial updates (like WPF)? The WinForms model (not sure how this works)?

被用在渲染模型什么样的缓存?

What sort of caching is used in the rendering model?

如何字体加载和它们是如何呈现的?他们是标准的TrueType字体,位图字体,还是其他什么东西?

How are fonts loaded and how are they rendered? Are they standard TrueType fonts, bitmap fonts, or something else?

如何滚动进行如此高效?

How is scrolled performed so efficiently?

还有什么,你认为可能是相关的!

Anything else you think might be relevant!

的内置Windows控制台界面(甚至优于Linux终端UI)如何做这些事情任何解释 - 我怎么能效仿他们 - 将是理想的,其实

Any explanation of how the inbuilt Windows console UI (or even the superior Linux terminal UI) do these things - and how I could emulate them - would be ideal, in fact.

编辑:要清楚,我真的要从头开始完全做到这一点。基于图形化框架,比如GDI +或WPF,但仅此而已。

To be clear, I really want to do this completely from scratch. Based on a graphical framework like GDI+ or WPF, but no more.

推荐答案

有一次我实现了一个文本输出窗口从头开始 - 我想一个工程像Visual Studio中的输出窗口。它原来是比我预期的复杂,而且是没有任何输入功能。

I once implemented a text output window from scratch - I wanted one that works like the Output window in Visual Studio. It turned out to be more complicated than I expected, and that was without any input capabilities.

不幸的是,code是在C ++中,属于前雇主,所以我不能与你分享。但是,我可以给你什么期望的想法。

Unfortunately the code is in C++ and belongs to a former employer, so I can't share it with you. But I can give you an idea of what to expect.

您需要一种方法来快速存储输出的线,你可以索引。如果你要去的地方的限制上的行数显示这还需要很容易清除从顶部线条。在C ++中一个双端队列<字符串> 是完美的,我不知道这个相当于什么(如果有的话),在C#

You need a way to store the lines of output that you can index quickly. If you're going to place a limit on the number of lines displayed it will also need to be easy to erase lines from the top. In C++ a deque<string> was perfect, I don't know what the equivalent is (if any) in C#.

您将需要处理程序下面的Windows消息,没有特定的顺序。

You'll need handlers for the following Windows messages, in no particular order.

WM_LBUTTONDOWN - 开始选择。使用SetCapture跟踪鼠标,而按键时。 WM_LBUTTONUP - 最终选择 WM_RBUTTONUP - 翻译成WM_CONTEXTMENU WM_CONTEXTMENU - 显示与复制/剪切/粘贴,并且希望其他任何一个菜单。 WM_KEYDOWN - 向4光标键,Home / End键,上一页/下一页回应。按Ctrl-A / CTRL-C / CTRL-X / CTRL-V /按Ctrl-D。 WM_PAINT - 来绘制窗口中的内容。 WM_SIZE - 更新滚动条时,窗口大小的变化 WM_VSCROLL - 在垂直滚动更新窗口的可见部分 WM_HSCROLL - 水平滚动期间来更新窗口的可见部分 WM_CREATE - 用于创建窗口时,初始化 WM_SETFOCUS - 创建一个系统插入符号,以显示在窗口中的当前位置。 WM_KILLFOCUS - 杀插入符号,因为只有目前的重点窗口将显示一个插入符。 WM_MOUSEMOVE - 跟踪更改的选择,而鼠标左键是向下 WM_CAPTURECHANGED - 最终选择 WM_TIMER - 自动滚动,当光标在选择离开窗口 WM_GETDLG code - 添加DLGC_WANTARROWS使箭头键将打通。 WM_MOUSEWHEEL - 响应鼠标滚轮滚动。 WM_LBUTTONDOWN - to start a selection. Use SetCapture to track the mouse while the button is down. WM_LBUTTONUP - to end a selection. WM_RBUTTONUP - translate into WM_CONTEXTMENU. WM_CONTEXTMENU - to display a menu with Copy/Cut/Paste and whatever else you want. WM_KEYDOWN - to respond to the 4 cursor keys, Home/End, PageUp/PageDown. Ctrl-A/Ctrl-C/Ctrl-X/Ctrl-V/Ctrl-D. WM_PAINT - to paint the contents of the window. WM_SIZE - to update the scrollbars when the window size changes. WM_VSCROLL - to update the visible portion of the window during vertical scrolling. WM_HSCROLL - to update the visible portion of the window during horizontal scrolling. WM_CREATE - for initialization when the window is created. WM_SETFOCUS - to create a system caret to show the current position in the window. WM_KILLFOCUS - to kill the caret since only the currently focused window should show a caret. WM_MOUSEMOVE - to track changes to the selection while the left mouse button is down. WM_CAPTURECHANGED - to end a selection. WM_TIMER - to auto-scroll when the cursor leaves the window during a selection. WM_GETDLGCODE - to add DLGC_WANTARROWS so that the arrow keys will get through. WM_MOUSEWHEEL - to respond to the mouse wheel for scrolling.

正如行被添加到文本缓冲器,调整滚动条的范围内。垂直滚动范围将是行的总数,和水平滚动条范围将是最宽的线的宽度。

As lines are added to the text buffer, adjust the range of the scrollbars. The vertical scrollbar range will be the total number of lines, and the horizontal scrollbar range will be the width of the widest line.

最好是有这等宽单个字体 - 它使计算变得更加简单。具体字体技术不要紧这么多。你只需要能够跟踪字符的位置。

It is best to have a single font which is monospaced - it makes the calculations a lot easier. The specific font technology doesn't matter so much. You just need to be able to track the positions of the characters.

如何滚动进行如此高效?您跟踪窗口的顶部和底部的线条,因为它滚动,而当绘制消息来只绘制当前可见的线条。其他人仍然在缓冲区,但他们没有得到感动。这是可能的块复制该窗口中的内容,因为它滚动,只画了进来,从顶部或底部的部分,但今天的处理器,这是一个无用功 - 窗口会做一个完整的重绘如此之快,你不会注意到

How is scrolled performed so efficiently? You track the top and bottom lines of the window as it scrolls, and when a paint message comes you only paint the lines that are currently visible. The others are still in the buffer but they don't get touched. It's possible to blit the contents of the window as it scrolls and only paint the parts that come in from the top or bottom, but with today's processors it's a wasted effort - the window will do a full repaint so quickly that you won't notice.

编辑:巧的是我碰到这个微软指南,滚动条应该是必不可少的阅读这一任务。 http://msdn.microsoft.com/en-us/library/windows/desktop/bb787527.aspx

Coincidentally I came across this Microsoft guide to scroll bars which should be essential reading for this task. http://msdn.microsoft.com/en-us/library/windows/desktop/bb787527.aspx