Страница: 1 |
|
Вопрос: VB6 в командной строке
|
Добавлено: 21.08.07 12:32
|
|
Автор вопроса: KreAtoR
|
Скажите плиз возможно ли через Бейсик работать с командной строкой. Когда то я баловался с С++ и это было обычным делом, а с Бейсиком я такого еще ниразу не встречал.
Если такое возможно и вы знаете как, дайте плиз примерчик, типа вывод строки "Hallo, World!"
Ответить
|
Номер ответа: 6 Автор ответа: KreAtoR
Вопросов: 120 Ответов: 438
|
Профиль | | #6
|
Добавлено: 21.08.07 16:40
|
„~„u „Ѓ„Ђ„t„ѓ„{„p„w„y„„„u „{„p„{ „ѓ„t„u„|„p„„„Ћ „‰„„„Ђ„q „Ѓ„‚„Ђ„s„p „~„u „r„Ќ„|„u„„„p„|„p „Ѓ„‚„y „Ѓ„Ђ„Ѓ„Ќ„„„{„u „x„p„{„‚„Ќ„„„Ћ „{„Ђ„~„ѓ„Ђ„|„Ћ „~„p„w„p„„„y„u„} „~„p „{„‚„u„ѓ„„„y„{???
„r„Ќ„{„|„p„t„Ќ„r„p„ђ, „‰„„„Ђ „‘ „~„p„{„p„‚„‘„q„p„| „…„w„u
Main.frm
Option Explicit
Private Sub Form_Load()
Dim szUserInput As String
AllocConsole
SetConsoleTitle "Console Name Test"
hConsoleIn = GetStdHandle(STD_INPUT_HANDLE)
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
hConsoleErr = GetStdHandle(STD_ERROR_HANDLE)
SetConsoleTextAttribute hConsoleOut, FOREGROUND_INTENSITY Or FOREGROUND_RED _
Or BACKGROUND_GREEN
ConsolePrint "Hello, World" & vbCrLf
SetConsoleTextAttribute hConsoleOut, FOREGROUND_INTENSITY Or FOREGROUND_YELLOW
ConsolePrint "Enter your name --> "
szUserInput = ConsoleRead()
If Not szUserInput = vbNullString Then
ConsolePrint "Hello, " & szUserInput & "!" & vbCrLf
Else
ConsolePrint "Hello, whoever you are!" & vbCrLf
End If
ConsolePrint "Press Enter to exit"
Call ConsoleRead
FreeConsole
End Sub
ModConsole.bas
Option Explicit
Public Declare Function AllocConsole Lib "kernel32" () As Long 'create console window
Public Declare Function FreeConsole Lib "kernel32" () As Long 'destroy the console window
Public Declare Function GetStdHandle Lib "kernel32" ( ByVal nStdHandle As Long) As Long 'Handle to the console
'Console have tree handle
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&
Public Const STD_ERROR_HANDLE = -12&
Public 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 Long 'writing to the console
Public Declare Function SetConsoleTitle Lib "kernel32" Alias "SetConsoleTitleA" _
  ByVal lpConsoleTitle As String) As Long 'Title of the console
Public Declare Function SetConsoleTextAttribute Lib "kernel32" _
  ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long 'Console color
'these values are passed in the wAttributes argument
Public Const FOREGROUND_BLUE = &H1
Public Const FOREGROUND_GREEN = &H2
Public Const FOREGROUND_RED = &H4
Public Const FOREGROUND_INTENSITY = &H8
Public Const BACKGROUND_BLUE = &H10
Public Const BACKGROUND_GREEN = &H20
Public Const BACKGROUND_RED = &H40
Public Const BACKGROUND_INTENSITY = &H80
Public Const FOREGROUND_YELLOW = FOREGROUND_RED Or FOREGROUND_GREEN
Public Declare Function SetConsoleMode Lib "kernel32" ( ByVal hConsoleOutput As Long, _
dwMode As Long) As Long
Public 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 Long
'For SetConsoleMode (input)
Public Const ENABLE_LINE_INPUT = &H2
Public Const ENABLE_ECHO_INPUT = &H4
Public Const ENABLE_MOUSE_INPUT = &H10
Public Const ENABLE_PROCESSED_INPUT = &H1
Public Const ENABLE_WINDOW_INPUT = &H8
'For SetConsoleMode (output)
Public Const ENABLE_PROCESSED_OUTPUT = &H1
Public Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2
Public hConsoleIn As Long 'The consoleЃLs input handle
Public hConsoleOut As Long 'The consoleЃLs output handle
Public hConsoleErr As Long 'The consoleЃLs error handle
Public Sub ConsolePrint(szOut As String)
WriteConsole hConsoleOut, szOut, Len(szOut), vbNull, vbNull
End Sub
Public Function ConsoleRead() As String
Dim sUserInput As String * 256
Call ReadConsole(hConsoleIn, sUserInput, Len(sUserInput), vbNull, vbNull)
ConsoleRead = Left$(sUserInput, InStr(sUserInput, Chr$(0)) - 3)
End Function
„y „u„ѓ„|„y „{„„„Ђ „}„Ђ„w„u„„ „Ѓ„Ђ„t„ѓ„{„p„w„y„„„u, „{„p„{ „}„Ђ„w„~„Ђ „Ђ„„„{„‚„Ќ„„„Ћ „ѓ„„„p„~„t„p„‚„„„~„…„ђ „{„Ђ„~„ѓ„Ђ„|„Ћ „r„y„~„t„Ќ. „B„u„t„Ћ „Џ„„„… VB „ѓ„p„} „ѓ„Ђ„x„t„p„u„„ „u„ѓ„|„y „‘ „~„u „Ђ„Љ„y„q„p„ђ„ѓ„Ћ
Ответить
|
Номер ответа: 12 Автор ответа: ZagZag
ICQ: 295002202
Вопросов: 87 Ответов: 1684
|
Профиль | | #12
|
Добавлено: 22.08.07 16:59
|
К примеру вот:
'Example submitted by X-MaD (x-mad@zolnetwork.com)
'Visit his homepage at http://www.zolnetwork.com/x-mad/
'To use this example:
'Add a BAS Module and Remove the Form
'Put the code into the BAS Module
'Make sure the Project's Startup Object is set to 'Sub Main'
'(you can change this by going to Project->Project Properties->
'General Tab->Startup Object)
Option Explicit
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private 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 Long
Private Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long
Private Declare Function SetConsoleTitle Lib "kernel32" Alias "SetConsoleTitleA" (ByVal lpConsoleTitle As String) As Long
Private 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 Long
Private Const STD_INPUT_HANDLE = -10&
Private Const STD_OUTPUT_HANDLE = -11&
Private Const STD_ERROR_HANDLE = -12&
Private Const FOREGROUND_RED = &H4
Private Const FOREGROUND_GREEN = &H2
Private Const FOREGROUND_BLUE = &H1
Private Const FOREGROUND_INTENSITY = &H8
Private Const BACKGROUND_RED = &H40
Private Const BACKGROUND_GREEN = &H20
Private Const BACKGROUND_BLUE = &H10
Private Const BACKGROUND_INTENSITY = &H80
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
Private Const ENABLE_PROCESSED_OUTPUT = &H1
Private Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2
Private hCmdIn As Long
Private hCmdOut As Long
Private hCmdError As Long
Sub Main()
Dim CmdIn As String * 256
Dim CmdOUT As String
'Open New Console Window
AllocConsole
'Set te Console Title
SetConsoleTitle "My Cmd Console"
'Get The Console Handler
hCmdIn = GetStdHandle(STD_INPUT_HANDLE)
hCmdOut = GetStdHandle(STD_OUTPUT_HANDLE)
hCmdError = GetStdHandle(STD_ERROR_HANDLE)
'Set The Console Color Attribute
SetConsoleTextAttribute hCmdOut, FOREGROUND_GREEN Or FOREGROUND_INTENSITY
CmdOUT = "Command Line OutPut" & vbCrLf
'Write The Output on CommandLine Console
WriteConsole hCmdOut, CmdOUT, Len(CmdOUT), vbNull, vbNull
CmdOUT = "Keyb Input: "
'Write The Output on CommandLine Console
WriteConsole hCmdOut, CmdOUT, Len(CmdOUT), vbNull, vbNull
'Read The Input on CommandLine Console
Call ReadConsole(hCmdIn, CmdIn, Len(CmdIn), vbNull, vbNull)
CmdOUT = "You Are Type: " & Left$(CmdIn, InStr(CmdIn, Chr$(0)) - 3) & vbCrLf
'Write The Output on CommandLine Console
WriteConsole hCmdOut, CmdOUT, Len(CmdOUT), vbNull, vbNull
'Read The Input on CommandLine Console
Call ReadConsole(hCmdIn, CmdIn, Len(CmdIn), vbNull, vbNull)
'Close Console Window
FreeConsole
End Sub
Чтобы не появлялась вторая консоль, надо пропатчить скомпиллированый экзешник. Заменить байт 02h (offset: 113h) на 03h
Ответить
|
Страница: 1 |
Поиск по форуму