如何以编程方式禁用C#控制台应用程序的快速编辑模式? [英] How to programmatic disable C# Console Application's Quick Edit mode?

查看:492
本文介绍了如何以编程方式禁用C#控制台应用程序的快速编辑模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了几种解决方案,例如一种->

I,ve tried several solutions found, like the one ->

http://www.pcreview.co.uk/forums/console-writeline-hangs-if- user-click-into-console-window-t1412701.html

但是,我观察到GetConsoleMode(IntPtr hConsoleHandle,out int mode)中的模式为针对不同的控制台应用程序而不同。它不是恒定的。

But, i observed that mode in GetConsoleMode(IntPtr hConsoleHandle, out int mode) will be different for different console app. It is not constant.

我可以在控制台应用程序上禁用鼠标单击(向右/向左按钮)以实现相同的情况。我发现可以使用IMessageFilter做到这一点,但只能用于窗口窗体应用程序,而不能用于控制台应用程序。

Can I disable mouse clicks (right/left buttons) on a console application to achieve the same scenario. I found that it can be done with IMessageFilter but only for Window Form Application and not for console application.

请指导。

推荐答案

如果要禁用快速编辑模式,则需要调用 GetConsoleMode 获取当前模式。然后清除启用快速编辑的位,然后调用 SetConsoleMode 。假设您具有非托管函数的托管原型,则应编写:

If you want to disable quick edit mode, you need to call GetConsoleMode to get the current mode. Then clear the bit that enables quick edit, and call SetConsoleMode. Assuming you have the managed prototypes for the unmanaged functions, you would write:

const int ENABLE_QUICK_EDIT = 0x0040;

IntPtr consoleHandle = GetConsoleWindow();
UInt32 consoleMode;

// get current console mode
if (!GetConsoleMode(consoleHandle, out consoleMode))
{
    // Error: Unable to get console mode.
    return;
}

// Clear the quick edit bit in the mode flags
mode &= ~ENABLE_QUICK_EDIT;

// set the new mode
if (!SetConsoleMode(consoleHandle, consoleMode))
{
    // ERROR: Unable to set console mode
}

如果要禁用鼠标输入,则要清除鼠标输入位。

If you want to disable mouse input, you want to clear the mouse input bit.

const int ENABLE_MOUSE_INPUT = 0x0010;

mode &= ~ENABLE_MOUSE_INPUT;

这篇关于如何以编程方式禁用C#控制台应用程序的快速编辑模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆