Results 1 to 4 of 4

Thread: GetConsoleMode and SetConsoleMode example help

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Johannesburg, South Africa
    Posts
    2

    GetConsoleMode and SetConsoleMode example help

    I'm going batty .... !

    Wrote this snippet of code in C to block echoing in console window app. It works. Can't get the same thing to work in VB!!! No matter how many times I set the console mode it still echoes... Does anybody have an EXAMPLE of how to switch console input echoing on and off in Visual Basic? Much appreciated!

    Ian

    #include <windows.h>
    #include <stdio.h>

    int main(int argc, char **argv)
    {
    char passwd[128];
    char usrinput[128];
    HANDLE h;
    int md;

    /* set no echo */
    h = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(h, &md);
    SetConsoleMode(h, md & ~ENABLE_ECHO_INPUT);

    printf("Password:"); fflush(stdout);
    fgets(passwd, sizeof(passwd), stdin);

    /* reset echo */
    SetConsoleMode(h, md);
    printf("\n"); fflush(stdout);

    printf("got '%s'\n", passwd);
    fgets(usrinput, sizeof(usrinput), stdin);
    return 0;
    }

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    What does the tilde~ mean before the constant in C++
    SetConsoleMode(h, md & ~ENABLE_ECHO_INPUT);

    I've got a test version here, but I can't seem to turn it off at the mo...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    It's a Bitwise NOT isn't it. I cant work out how to replicate that in VB, I tried
    SetConsoleMode hConsole, Not ENABLE_ECHO_INPUT

    but that didn't work, i'm still trying....
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Johannesburg, South Africa
    Posts
    2
    Hi,

    The ~ is a bitwise NOT yes.

    This is the VB code snippet which doesn't work. It still echos the input. *SIGH* ....


    Ian


    'For SetConsoleMode (input)
    Private Const ENABLE_LINE_INPUT = &H2
    Private Const ENABLE_ECHO_INPUT = &H4
    Private Const ENABLE_MOUSE_INPUT = &H10
    Private Const ENABLE_PROCESSED_INPUT = &H1
    Private Const ENABLE_WINDOW_INPUT = &H8

    'For SetConsoleMode (output)
    Private Const ENABLE_PROCESSED_OUTPUT = &H1
    Private Const ENABLE_WRAP_AT_EOL_OUTPUT = &H8

    'Globals
    Private hConsoleIn As Long
    Private hConsoleOut As Long
    Private hConsoleErr As Long

    ' M A I N

    Private Sub Main()
    Dim szUserInput As String
    Dim sPrefix As String
    Dim dwModeFlags As Long
    Dim ConsoleRead As String
    Dim sUserInput As String * 256

    AllocConsole

    hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)

    GetConsoleMode hConsoleIn, dwModeFlags
    SetConsoleMode hConsoleIn, dwModeFlags And Not ENABLE_ECHO_INPUT

    Call ReadConsole(hConsoleIn, sUserInput, Len(sUserInput), vbNull, vbNull)
    ConsoleRead = Left$(sUserInput, InStr(sUserInput, Chr$(0)) - 3)


    FreeConsole
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width