添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
发财的饭卡  ·  天道圣经注释·  5 月前    · 
俊秀的小狗  ·  “钢锯岭”麒麟 vs. ...·  5 月前    · 
有腹肌的排球  ·  python 替换\n | 4os·  8 月前    · 
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. 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!
#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;
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... 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.... The ~ is a bitwise NOT yes.
This is the VB code snippet which doesn't work. It still echos the input. *SIGH* ....
'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 Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.