Skip to content

Instantly share code, notes, and snippets.

@TrQ-Hoan
Created June 17, 2024 04:30
Show Gist options
  • Save TrQ-Hoan/acfc16d11e241262853fe14c63047bfd to your computer and use it in GitHub Desktop.
Save TrQ-Hoan/acfc16d11e241262853fe14c63047bfd to your computer and use it in GitHub Desktop.
Windows console toggle QUICK_EDIT_MODE
#include <windows.h>
#include <stdio.h>
/*
cl /EHsc /MT /nologo /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_USING_V110_SDK71_" quickedit.cpp
link /OUT:quickedit.exe /MACHINE:X86 /OPT:REF /SAFESEH /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 /SUBSYSTEM:CONSOLE",5.01" quickedit.obj
*/
int main(int argc, char* argv[]) {
HANDLE hIn;
DWORD Mode;
BOOL Ret = TRUE;
DWORD ErrCode = NOERROR;
hIn = GetStdHandle(STD_INPUT_HANDLE);
Ret = GetConsoleMode(hIn, &Mode);
if (argc == 1) {
if ((Mode & ENABLE_QUICK_EDIT_MODE) == ENABLE_QUICK_EDIT_MODE) {
fprintf(stderr, "QuickEdit On\n");
} else {
fprintf(stderr, "QuickEdit Off\n");
}
} else {
char* command = argv[1];
// Convert the first parameter to lowercase
for (int i = 0; i < strlen(command); ++i) {
command[i] = tolower(command[i]);
}
if (!strcmp(command, "on")) {
if ((Mode & ENABLE_QUICK_EDIT_MODE) == 0) {
Ret = SetConsoleMode(hIn, Mode | ENABLE_QUICK_EDIT_MODE);
}
if (Ret == FALSE) ErrCode = GetLastError();
} else if (!strcmp(command, "off")) {
if ((Mode & ENABLE_QUICK_EDIT_MODE) == ENABLE_QUICK_EDIT_MODE) {
Ret = SetConsoleMode(hIn, Mode & ~ENABLE_QUICK_EDIT_MODE);
}
if (Ret == FALSE) ErrCode = GetLastError();
} else {
fprintf(stderr, "Command not found!\nUsage: %s [on|off]\n", argv[0]);
}
if (Ret == FALSE && ErrCode != NOERROR) {
fprintf(stderr, "RET 0x%X - ErrCode 0x%X\n", Ret, ErrCode);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment