How to disable user selection in Windows console(如何在 Windows 控制台中禁用用户选择)
问题描述
我需要在 Windows 控制台中禁用用户鼠标选择.有可能吗?怎么做?我尝试了函数 SetConsoleMode()
来禁用鼠标输入,但它没有按我的预期工作.仍然可以选择.
I need to disable user mouse selection in the Windows console. Is it possible and how? I tried the function SetConsoleMode()
to disable mouse input with it, but it did not work as I expected. Selecting was still possible.
推荐答案
控制台的快速编辑模式允许用户使用鼠标快速选择和复制文本,而无需先进入标记模式(即Ctrl+M,或菜单上的编辑 -> 标记).启用快速编辑模式通常很方便,但它确实会干扰获取鼠标输入.您可以使用控制台输入缓冲区的句柄禁用它,如下所示:
The console's quick-edit mode allows the user to quickly select and copy text using the mouse, without having to first enter mark mode (i.e. Ctrl+M, or Edit -> Mark on the menu). It's usually convenient to enable quick-edit mode, but it does interfere with getting mouse input. You can disable it using a handle for the console input buffer as follows:
DWORD prev_mode;
GetConsoleMode(hInput, &prev_mode);
SetConsoleMode(hInput, ENABLE_EXTENDED_FLAGS |
(prev_mode & ~ENABLE_QUICK_EDIT_MODE));
记得在退出时恢复之前的模式.
Remember to restore the previous mode at exit.
这篇关于如何在 Windows 控制台中禁用用户选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Windows 控制台中禁用用户选择


基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09