windows - 未记录的控制台输入模式标志

标签 windows winapi console

我正在 Rust 中开发我的库,以便使用 Windows API 在终端中制作 GUI。

当我实现获取和设置控制台模式时,我注意到输入模式的默认值为 503。我去检查 documentation对于标志,但没有记录值 128 和 256,没有它们就无法获得 503。

无论哪种方式,它们都是默认启用的,如文档中所述:

When a console is created, all input modes except ENABLE_WINDOW_INPUT and ENABLE_VIRTUAL_TERMINAL_INPUT are enabled by default.

当包含 128 和 256 时,计算结果为 503,即我得到的值!

这两个标志是微软不想记住的过去的事情吗?他们的职能是什么?

我已经在互联网上查找过,但找不到有关文档中缺少的两个标志的任何注释。

最佳答案

模式是一个位掩码。整数值 503 包含以下标志,如 wincon.hconsoleapi.h 中定义:

0x0001 ENABLE_PROCESSED_INPUT
0x0002 ENABLE_LINE_INPUT
0x0004 ENABLE_ECHO_INPUT
0x0010 ENABLE_MOUSE_INPUT
0x0020 ENABLE_INSERT_MODE
0x0040 ENABLE_QUICK_EDIT_MODE
0x0080 ENABLE_EXTENDED_FLAGS
0x0100 ENABLE_AUTO_POSITION

您询问的两个标志是ENABLE_EXTENDED_FLAGSENABLE_AUTO_POSITION

我在 MSDN 上能找到的唯一提及 ENABLE_EXTENDED_FLAGS 的内容是 SetConsoleMode()文档:

Value Meaning
ENABLE_QUICK_EDIT_MODE 0x0040 This flag enables the user to use the mouse to select and edit text. To enable this mode, use ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS. To disable this mode, use ENABLE_EXTENDED_FLAGS without this flag.

参见How to disable user selection in Windows console举个例子。

MSDN 上未记录

ENABLE_AUTO_POSITION。我在网上唯一能找到的就是以下简介:

https://txwizard.github.io/WizardWrx_NET_API/api/WizardWrx.ConsoleStreams.StandardHandleInfo.ConsoleModes.html

Name Description
ENABLE_AUTO_POSITION Though defined in WinCon.h, this flag is otherwise undocumented.

My initial best guess is that it is related to the "Let system position window" check box on the property sheet of a CMD.EXE window, though I have yet to test this theory.

同一页面还提到了ENABLE_EXTENDED_FLAGS:

Name Description
ENABLE_EXTENDED_FLAGS Required to enable or disable extended flags.

See ENABLE_INSERT_MODE and ENABLE_QUICK_EDIT_MODE.
ENABLE_INSERT_MODE When enabled, text entered in a console window will be inserted at the current cursor location and all text following that location will not be overwritten. When disabled, all following text will be overwritten.

To enable this mode, use ENABLE_INSERT_MODE | ENABLE_EXTENDED_FLAGS.

To disable this mode, use ENABLE_EXTENDED_FLAGS without this flag.
ENABLE_QUICK_EDIT_MODE This flag enables the user to use the mouse to select and edit text.

To enable this mode, use ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS.

To disable this mode, use ENABLE_EXTENDED_FLAGS without this flag.

关于windows - 未记录的控制台输入模式标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76156132/

相关文章:

java - SSL Socket OutputStream Write Slow only on Windows

c++ - Windows 是否支持从内存运行程序?

C# 控制台列格式设置和定位

c++ - 在运行时创建 Command 对象

javascript - console.log 打印值而不向其传递任何参数

windows - 使用 KBDLLHOOKSTRUCT 确定第一次按键

c++ - 有没有办法用windows获取系统中安装的cpu(套接字)数量?

c++ - 如何在写入图标 (.ico) 时为鼠标光标应用掩码

c - 如何从 Windows 线程函数返回 char *

c++ - 可扩展的内存分配器体验