Autor
|
Tema: crear conosola con VB6?? :S (Leído 2,419 veces)
|
Xephiro
|
Hi, bueno me gustaria saber si es posible hacer una consola como la de win, pero en VB6...
Lo que quiero es poder tener en una sola pantalla mas de una consola funcionando y no tener varias ventanas ... ademas de agregarle algunos otros botones para otras cosas, no quiero que sea remoto, sino que suseda en el mismo PC donde lo abro..
|
|
|
En línea
|
|
|
|
~~
|
Lo q tu necesitas es crear un pipe para otenr la salida de la consola (si creas varios podras tener varias consolas a la vez). Busca sobre la api CreatePipe, en la api guide viene un ejemplo
|
|
|
En línea
|
|
|
|
Jareth
Desconectado
Mensajes: 334
|
Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Command1_Click() Dim ruta As String On Error Resume Next ruta = "c:\hi.txt" Kill ruta Kill "c:\tio.bat" Open "c:\tio.bat" For Binary As #1 Put #1, , "@echo off" & vbCrLf Put #1, , Text1.Text & ">>C:\hi.txt" & vbCrLf Put #1, , "exit" Close #1 Shell "c:\tio.bat", vbHide Sleep 1000 Open "C:\hi.txt" For Input As #1 Dim resultado As String Do While Not EOF(1) Line Input #1, resultado If Not resultado = "" Then Text2.Text = Text2.Text & vbCrLf & resultado Loop
Close #1
End Sub
Private Sub Command2_Click() Text2.Text = "" End Sub
Private Sub Form_Load() Me.Caption = "Shell" End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 Call Command1_Click End If End Sub
Espero qeu te sriva,es bastante sencilla y creo qeu servirá para tu proposito. Evidentemente no es una consola,peor los comandos se envian y se lee las respuestas. Saludos.
|
|
|
En línea
|
|
|
|
Xephiro
|
nose si sera posible que me peguen una ayudita con api CreatePipe porquen o encuentro nada en VB sobre ello solo cosas con C++
|
|
|
En línea
|
|
|
|
Xephiro
|
Bueno XD no tomen encuenta mi post anterios, ahora tengo una nueva pregunta XD porque no me funciona tal cual como CMD ?? hay carias cosasque no me corren :S
lo que pasa es que quiero hacer que se habra un server de L2 por medio de esa consola, para que quede un poco mejor ...
lo malo es que cuando trato de hacelo partir no me deja conectar con la DB desde la consola de VB6 pepi pero por medio de bat tal como es no hay problema :S porque esa diterencia ?? siendo que ambos estan en la misma carpeta, o tendre que agregar algo mas??
|
|
|
En línea
|
|
|
|
~~
|
nose si sera posible que me peguen una ayudita con api CreatePipe porquen o encuentro nada en VB sobre ello solo cosas con C++
Pues podias poner algun ejemplillo en C++ q andube buscandolos hace algun tiempo Para VB te dejo dos ejemplos, el de la api guide: 'Redirects output from console program to textbox. 'Requires two textboxes and one command button. 'Set MultiLine property of Text2 to true. ' 'Original bcx version of this program was made by ' dl <dl@tks.cjb.net> 'VB port was made by Jernej Simoncic <jernej@isg.si> 'Visit Jernejs site at http://www2.arnes.si/~sopjsimo/ ' 'Note: don't run plain DOS programs with this example 'under Windows 95,98 and ME, as the program freezes when 'execution of program is finnished. Option Explicit Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO) Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Long End Type Private Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadId As Long End Type Private Type STARTUPINFO cb As Long lpReserved As Long lpDesktop As Long lpTitle As Long dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Integer cbReserved2 As Integer lpReserved2 As Byte hStdInput As Long hStdOutput As Long hStdError As Long End Type Private Type OVERLAPPED ternal As Long ternalHigh As Long offset As Long OffsetHigh As Long hEvent As Long End Type Private Const STARTF_USESHOWWINDOW = &H1 Private Const STARTF_USESTDHANDLES = &H100 Private Const SW_HIDE = 0 Private Const EM_SETSEL = &HB1 Private Const EM_REPLACESEL = &HC2 Private Sub Command1_Click() Command1.Enabled = False Redirect Text1.Text, Text2 Command1.Enabled = True End Sub Private Sub Form_Load() Text1.Text = "ping" End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If Command1.Enabled = False Then Cancel = True End Sub Sub Redirect(cmdLine As String, objTarget As Object) Dim i%, t$ Dim pa As SECURITY_ATTRIBUTES Dim pra As SECURITY_ATTRIBUTES Dim tra As SECURITY_ATTRIBUTES Dim pi As PROCESS_INFORMATION Dim sui As STARTUPINFO Dim hRead As Long Dim hWrite As Long Dim bRead As Long Dim lpBuffer(1024) As Byte pa.nLength = Len(pa) pa.lpSecurityDescriptor = 0 pa.bInheritHandle = True pra.nLength = Len(pra) tra.nLength = Len(tra) If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then sui.cb = Len(sui) GetStartupInfo sui sui.hStdOutput = hWrite sui.hStdError = hWrite sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES sui.wShowWindow = SW_HIDE If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then SetWindowText objTarget.hwnd, "" Do Erase lpBuffer() If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then SendMessage objTarget.hwnd, EM_SETSEL, -1, 0 SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0) DoEvents Else CloseHandle pi.hThread CloseHandle pi.hProcess Exit Do End If CloseHandle hWrite Loop CloseHandle hRead End If End If End Sub
Y otro un poco mas profesional q me baje en planet source code (me parece): http://rapidshare.com/files/41320261/Shell_Pipes.zip.htmlEspero q te sirvan
|
|
|
En línea
|
|
|
|
Hendrix
|
Si se puede crear una consola...te dejo un ejemplo de la APIGuide Private Const FOREGROUND_BLUE = &H1 Private Const FOREGROUND_GREEN = &H2 Private Const FOREGROUND_RED = &H4 Private Const BACKGROUND_BLUE = &H10 Private Const BACKGROUND_GREEN = &H20 Private Const BACKGROUND_RED = &H40 Private Const BACKGROUND_INTENSITY = &H80& Private Const BACKGROUND_SEARCH = &H20& Private Const FOREGROUND_INTENSITY = &H8& Private Const FOREGROUND_SEARCH = (&H10&) 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 Const STD_OUTPUT_HANDLE = -11& Private Const STD_INPUT_HANDLE = -10& Private Const STD_ERROR_HANDLE = -12& Private Const INVALID_HANDLE_VALUE = -1& Private Declare Function AllocConsole Lib "kernel32" () As Long Private Declare Function FreeConsole Lib "kernel32" () As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) 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 hConsoleOut As Long, hConsoleIn As Long, hConsoleErr As Long Private Sub Form_Load() 'KPD-Team 2001 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@Allapi.net 'Create console If AllocConsole() Then hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE) If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDOUT" hConsoleIn = GetStdHandle(STD_INPUT_HANDLE) If hConsoleOut = INVALID_HANDLE_VALUE Then MsgBox "Unable to get STDIN" Else MsgBox "Couldn't allocate console" End If 'Set the caption of the console window SetConsoleTitle "The KPD-Team 2001" 'Set the background color of the text in the console to bright YELLOW text 'on a BLUE background SetConsoleTextAttribute hConsoleOut, FOREGROUND_RED Or FOREGROUND_GREEN Or FOREGROUND_INTENSITY Or BACKGROUND_BLUE 'Write something in the console ConsoleWriteLine "Hello World!" ConsoleWrite "Please enter your name: " 'Ask for user input and show it in the caption Me.Caption = "Your name: " + ConsoleReadLine() End Sub Private Sub Form_Unload(Cancel As Integer) 'Delete console CloseHandle hConsoleOut CloseHandle hConsoleIn FreeConsole End Sub Sub ConsoleWriteLine(sInput As String) ConsoleWrite sInput + vbCrLf End Sub Sub ConsoleWrite(sInput As String) Dim cWritten As Long WriteConsole hConsoleOut, ByVal sInput, Len(sInput), cWritten, ByVal 0& End Sub Function ConsoleReadLine() As String Dim ZeroPos As Long 'Create a buffer ConsoleReadLine = String(10, 0) 'Read the input ReadConsole hConsoleIn, ConsoleReadLine, Len(ConsoleReadLine), vbNull, vbNull 'Strip off trailing vbCrLf and Chr$(0)'s ZeroPos = InStr(ConsoleReadLine, Chr$(0)) If ZeroPos > 0 Then ConsoleReadLine = Left$(ConsoleReadLine, ZeroPos - 3) End Function
Un Saludo.
|
|
|
En línea
|
"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián
|
|
|
Xephiro
|
ñp qie àsa es que cpn el Pepi no me conecta a las DB de mi PC como lo hacon un archivo.bar :S porque puede ser¿¿
|
|
|
En línea
|
|
|
|
Hendrix
|
Puede hablar.....mmmmm.....Can you speak spanish???
|
|
|
En línea
|
"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián
|
|
|
Xephiro
|
XD no se que hice con el texto anterior, bueno lo que pasa esque cuando quiero archivos java que se conectar a la DB desde la consola, por medio de la API Pepi no me funciona, pero por medio de un archivo .bat funciona exelente... :S como puedo solucionar eso ?? Esta es la parte que trata de hacer conexion con la DB, pero no me deja :S INFO : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource@110c424[ acquireIncrement -> 5, acquireRetryAttempts -> 0, acquireRetryDelay -> 500, autoCommitOnClose -> true, automaticTestTable -> connection_test_table, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 110c424, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/l2jdb, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnection -> 100, minPoolSize -> 1, numHelperThreads -> 20, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 300, testConnectionOnCheckin -> true, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] WARNING SQL Error: 0, SQLState: 08S01 SEVERE Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException MESSAGE: java.net.SocketException: Unrecognized Windows Sockets error: 10106: create
asi me queda cuando lo uso con un archivo .bat en forma directa :S INFO : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource@110c4 24[ acquireIncrement -> 5, acquireRetryAttempts -> 0, acquireRetryDelay -> 500, autoCommitOnClose -> true, automaticTestTable -> connection_test_table, breakAft erAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> co m.mchange.v2.c3p0.impl.DefaultConnectionTester, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTr ansactions -> false, identityToken -> 110c424, idleConnectionTestPeriod -> 60, i nitialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost/l2jdb, loginTimeout -> 0, maxIdleTime -> 0, maxPoolSize -> 20, maxStatements -> 0, maxStatementsPerConnec tion -> 100, minPoolSize -> 1, numHelperThreads -> 20, preferredTestQuery -> nul l, properties -> {user=******, password=******}, propertyCycle -> 300, testConne ctionOnCheckin -> true, testConnectionOnCheckout -> false, usesTraditionalReflec tiveProxies -> false ]
Luego comienza a cargar de inmediato los archivos de la DB
|
|
« Última modificación: 6 Julio 2007, 20:02 pm por Hacktor »
|
En línea
|
|
|
|
|
|