问题
I am trying to disable the quick edit mode of my console by my c++ program because in my application i don't want any selection. I also do not want any pause, as when someone clicks with this mode on it pauses the game. I have looked online and some documentation but i don't know what i have been doing wrong. I first tried below code from another question on stack overflow it didn't work.
#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;
int main(){
HANDLE hInput;
DWORD prev_mode;
GetConsoleMode(hInput, &prev_mode);
SetConsoleMode(hInput, prev_mode & ~ENABLE_QUICK_EDIT_MODE);
cout<<"The quick edit mode stopped now press any key to re enable it"<<endl;
_getch();
SetConsoleMode(hInput, prev_mode);
cout<<"Quick edit mode reenabled click any key to exit";
_getch();
return 0;
}
then i looked up this documentation and their i found something like this for SetConsoleMode
.
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.
Then i replaced ~ENABLE_QUICK_EDIT_MODE
with ENABLE_EXTENDED_FLAGS
and same result again i want to know what i am doing wrong.
I want to disable quick edit mode.
回答1:
There is a very silly mistake in the code. The problem with the code is that hInput HANDLE
wasn't initialized with STD_INPUT_HANDLE
and therefore the method SetConsoleMode
wasn't working. The working code is as below.
#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;
int main(){
HANDLE hInput;
DWORD prev_mode;
hInput = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hInput, &prev_mode);
SetConsoleMode(hInput, prev_mode & ENABLE_EXTENDED_FLAGS);
cout<<"The quick edit mode stopped now press any key to re enable it"<<endl;
_getch();
SetConsoleMode(hInput, prev_mode);
cout<<"Quick edit mode reenabled click any key to exit";
_getch();
return 0;
}
来源:https://stackoverflow.com/questions/55497407/disable-quick-edit-mode-for-console-from-c