从C ++禁用控制台的快速编辑模式 [英] disable quick edit mode for console from c++

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

问题描述

我正在尝试通过我的C ++程序禁用控制台的快速编辑模式,因为在我的应用程序中,我不需要任何选择.我也不希望有任何暂停,因为当有人单击此模式时,它会暂停游戏.我在网上看过一些文档,但是我不知道自己做错了什么.我首先在堆栈溢出的另一个问题下尝试了下面的代码,但是它没有用.

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;
}

然后我查找了此文档,他们发现了一些东西像这样用于 SetConsoleMode .

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.

要启用此模式,请使用ENABLE_QUICK_EDIT_MODE |ENABLE_EXTENDED_FLAGS.要禁用此模式,请使用ENABLE_EXTENDED_FLAGS没有此标志.

To enable this mode, use ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS. To disable this mode, use ENABLE_EXTENDED_FLAGS without this flag.

然后我用 ENABLE_EXTENDED_FLAGS 替换了〜ENABLE_QUICK_EDIT_MODE ,同样的结果我想知道我在做什么错.我想禁用快速编辑模式.

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.

推荐答案

代码中有一个非常愚蠢的错误.该代码的问题是 hInput HANDLE 没有用 STD_INPUT_HANDLE 初始化,因此方法 SetConsoleMode 不起作用.工作代码如下.

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;
}

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

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