📄 console.bas
字号:
Attribute VB_Name = "Console"'========================================================='File: Console.bas''Summary: Demonstrates how to create and manipulate a' console from Visual Basic.''Classes: None''Functions: ConsolePrint, ConsoleRead'=========================================================Option ExplicitPublic Declare Function AllocConsole Lib "kernel32" () As LongPublic Declare Function FreeConsole Lib "kernel32" () As LongPublic Declare Function GetStdHandle Lib "kernel32" _(ByVal nStdHandle As Long) As LongPublic Declare Function ReadConsole Lib "kernel32" Alias _"ReadConsoleA" (ByVal hConsoleInput As Long, _ByVal lpBuffer As String, ByVal nNumberOfCharsToRead As Long, _lpNumberOfCharsRead As Long, lpReserved As Any) As LongPublic Declare Function SetConsoleMode Lib "kernel32" (ByVal _hConsoleOutput As Long, dwMode As Long) As LongPublic Declare Function SetConsoleTextAttribute Lib _"kernel32" (ByVal hConsoleOutput As Long, ByVal _wAttributes As Long) As LongPublic Declare Function SetConsoleTitle Lib "kernel32" Alias _"SetConsoleTitleA" (ByVal lpConsoleTitle As String) As LongPublic Declare Function WriteConsole Lib "kernel32" Alias _"WriteConsoleA" (ByVal hConsoleOutput As Long, _ByVal lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, _lpNumberOfCharsWritten As Long, lpReserved As Any) As LongDeclare Function ReadFile Lib "kernel32" _ (ByVal hFile As Long, _ lpBuffer As Any, _ ByVal nNumberOfBytesToRead As Long, _ lpNumberOfBytesRead As Long, _ lpOverlapped As Any) As Long Declare Function WriteFile Lib "kernel32" _ (ByVal hFile As Long, _ ByVal lpBuffer As String, _ ByVal nNumberOfBytesToWrite As Long, _ lpNumberOfBytesWritten As Long, _ lpOverlapped As Any) As Long Declare Function SetFilePointer Lib "kernel32" _ (ByVal hFile As Long, _ ByVal lDistanceToMove As Long, _ lpDistanceToMoveHigh As Long, _ ByVal dwMoveMethod As Long) As Long Declare Function SetEndOfFile Lib "kernel32" _ (ByVal hFile As Long) As Long 'I/O handlers for the console window. These are much like the'hWnd handlers to form windows.Public Const STD_INPUT_HANDLE = -10&Public Const STD_OUTPUT_HANDLE = -11&Public Const STD_ERROR_HANDLE = -12&'Color values for SetConsoleTextAttribute.Public Const FOREGROUND_BLUE = &H1Public Const FOREGROUND_GREEN = &H2Public Const FOREGROUND_RED = &H4Public Const FOREGROUND_INTENSITY = &H8Public Const BACKGROUND_BLUE = &H10Public Const BACKGROUND_GREEN = &H20Public Const BACKGROUND_RED = &H40Public Const BACKGROUND_INTENSITY = &H80'For SetConsoleMode (input)Public Const ENABLE_LINE_INPUT = &H2Public Const ENABLE_ECHO_INPUT = &H4Public Const ENABLE_MOUSE_INPUT = &H10Public Const ENABLE_PROCESSED_INPUT = &H1Public Const ENABLE_WINDOW_INPUT = &H8'For SetConsoleMode (output)Public Const ENABLE_PROCESSED_OUTPUT = &H1Public Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2Public hConsoleIn As Long 'The console's input handlePublic hConsoleOut As Long 'The console's output handlePublic hConsoleErr As Long 'The console's error handle'========================================================='Function: ConsolePrint''Summary: Prints the output of a string''Args: String ConsolePrint'The string to be printed to the console's ouput buffer.''Returns: None'=========================================================Public Sub ConsolePrint(szOut As String)WriteConsole hConsoleOut, szOut, Len(szOut), vbNull, vbNullEnd Sub'========================================================='Function: ConsoleRead''Summary: Gets a line of input from the user.''Args: None''Returns: String ConsoleRead'The line of input from the user.'=========================================================Public Function ConsoleRead() As StringDim sUserInput As String * 256Call ReadConsole(hConsoleIn, sUserInput, Len(sUserInput), vbNull, vbNull)'Trim off the NULL charactors and the CRLF.ConsoleRead = Left$(sUserInput, InStr(sUserInput, Chr$(0)) - 3)End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -