31

私は、見つかったいくつかの解決策を試しました - >

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

しかし、GetConsoleMode(IntPtr hConsoleHandle, out int mode) のモードは、コンソール アプリによって異なることがわかりました。一定ではありません。

同じシナリオを実現するために、コンソール アプリケーションでマウス クリック (右/左ボタン) を無効にすることはできますか? IMessageFilter で実行できることがわかりましたが、コンソール アプリケーションではなく、ウィンドウ フォーム アプリケーションでのみ実行できます。

ガイドしてください。

4

6 に答える 6

17

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;
于 2012-12-01T06:09:29.620 に答える
0

以下のコードを組み合わせて使用​​することで、クイック編集モードを有効または無効にすることができます。

const int ENABLE_QUICK_EDIT = 0x0040;

// STD_INPUT_HANDLE (DWORD): -10 is the standard input device.
const int STD_INPUT_HANDLE = -10;

[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle);

[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int lpMode);

[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode);

有効にするには、簡単に実行しますcurrentConsoleMode &= ENABLE_QUICK_EDIT;

無効にするには、次のようにします currentConsoleMode &= ~ENABLE_QUICK_EDIT

そして、SetConsoleModeを呼び出します。

于 2015-10-30T18:06:58.943 に答える