Skip to content

Instantly share code, notes, and snippets.

@TrQ-Hoan
Last active June 27, 2024 04:13
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>
#include <string.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
*/
#pragma comment(lib, "User32.lib")
void DisableQuickEdit() {
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD Mode;
if (GetConsoleMode(hIn, &Mode)) {
Mode &= ~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hIn, Mode);
}
}
void EnableQuickEdit() {
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
DWORD Mode;
if (GetConsoleMode(hIn, &Mode)) {
Mode |= ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hIn, Mode);
}
}
void HideConsole() {
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
}
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 < 2 || argc > 3) {
if ((Mode & ENABLE_QUICK_EDIT_MODE) == ENABLE_QUICK_EDIT_MODE) {
fprintf(stderr, "[QuickEdit] On\n");
} else {
fprintf(stderr, "[QuickEdit] Off\n");
}
return 0;
}
bool hideConsole = false;
char* command = argv[1];
// Check if the optional /hidden parameter is provided
if (argc == 3 && _stricmp(argv[2], "/hidden") == 0) {
hideConsole = true;
}
// Process the main command (on or off)
if (_stricmp(command, "on") == 0) {
EnableQuickEdit();
} else if (_stricmp(command, "off") == 0) {
DisableQuickEdit();
} else {
fprintf(stderr, "Invalid command!\nUsage: %s [on|off] [/hidden]\n", argv[0]);
return 1;
}
// Hide the console if the /hidden parameter is provided
if (hideConsole) {
HideConsole();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment