News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Switching console modes

Started by kkurkiewicz, November 09, 2024, 04:06:55 AM

Previous topic - Next topic

kkurkiewicz

I just came across the following code in the Microsoft's Windows-classic-samples GitHub repository:

//
// Only set the console mode if input has not been redirected.
//

if (Redirected  == FALSE) {
    GetConsoleMode(InputConsole, &PreviousMode);
    Result = SetConsoleMode(InputConsole, ENABLE_PROCESSED_INPUT);
    if (Result == FALSE) {
        goto GetPasswordEnd;
    }

     ConsoleModeSet = TRUE;
}
Windows-classic-samples/Samples/Win7Samples/winbase/WHEA/DumpRec/exe/dumprec.c

Given that ENABLE_PROCESSED_INPUT is only a bit flag, why is it not being ORed with PreviousMode similarly to how the variable dwNewMode is initialized in this article on processing mouse events? Can ENABLE_PROCESSED_INPUT really act as a standalone mode?
Kamil

kkurkiewicz

Also, is there any sort of Windows Console best practices guide?
Kamil

zedd151

Ventanas diez es el mejor.  :azn:

NoCforMe

Quote from: kkurkiewicz on November 09, 2024, 04:06:55 AMGiven that ENABLE_PROCESSED_INPUT is only a bit flag, why is it not being ORed with PreviousMode similarly to how the variable dwNewMode is initialized in this article on processing mouse events? Can ENABLE_PROCESSED_INPUT really act as a standalone mode?

The thing to do is to go to the source, in this case the documentation on the SetConsoleMode() function in the Microsoft Learn repository:

QuotedwMode [in]:
The input or output mode to be set.

If the hConsoleHandle parameter is an input handle, the mode can be one or more of the following values. When a console is created, all input modes except ENABLE_WINDOW_INPUT and ENABLE_VIRTUAL_TERMINAL_INPUT are enabled by default.

ENABLE_PROCESSED_INPUT (0x0001):
CTRL+C is processed by the system and is not placed in the input buffer. If the input buffer is being read by ReadFile or ReadConsole, other control keys are processed by the system and are not returned in the ReadFile or ReadConsole buffer. If the ENABLE_LINE_INPUT mode is also enabled, backspace, carriage return, and line feed characters are handled by the system.

So it looks like it's OK to use this flag by itself. Depends, of course, on what you're trying to do here.
Assembly language programming should be fun. That's why I do it.

kkurkiewicz

Hmm... the snippet comes from a function named DrGetPassword, so I think the only reason for calling SetConsoleMode here is to disable echoing.
Kamil

NoCforMe

Assembly language programming should be fun. That's why I do it.