|
-
Aug 22nd, 2001, 03:22 AM
#1
Thread Starter
New Member
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;
}
-
Aug 22nd, 2001, 05:47 AM
#2
Fanatic Member
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]
-
Aug 22nd, 2001, 06:14 AM
#3
Fanatic Member
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]
-
Aug 22nd, 2001, 06:58 AM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|