I have a console game and i want to disable the mouse input. I've got the code from this page, but when i try to run it the GetConsoleMode function fails with errorcode 6, which stands for "Invalid Handle".
So my question: Why does the GetConsoleWindow() method return an invalid console handle?
Here my sourcecode:
private static void DisableMouseInput()
{
IntPtr consoleHandle = GetConsoleWindow();
uint consoleMode;
Console.WriteLine(Marshal.GetLastWin32Error()); // get current console mode
if (!GetConsoleMode(consoleHandle, out consoleMode))
{
// Error: Unable to get console mode.
Console.WriteLine(Marshal.GetLastWin32Error());
throw new Exception();
return;
}
// Clear the mouse input bit in the mode flags
consoleMode = consoleMode & 0xffbf; //0xffef = ~0x0040 = ~ENABLE_QUICK_EDIT
// set the new mode
if (!SetConsoleMode(consoleHandle, consoleMode))
{
// ERROR: Unable to set console mode
}
}