Sunday, June 17, 2012

Membuat Aplikasi Console Dengan Visual Basic 6.0

Option Explicit

Declare Function AllocConsole Lib "kernel32" () As Long
Declare Function FreeConsole Lib "kernel32" () As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
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

Public Const STD_OUTPUT_HANDLE = -11&
Dim hConsole As Long

Private Sub Command1_Click()
Dim Result As Long, sOut As String, cWritten As Long
sOut = "Hi There" & vbCrLf
Result = WriteConsole(hConsole, ByVal sOut, Len(sOut), cWritten, ByVal 0&)
Shell "C:\TEST.BAT"
End Sub

Private Sub Form_Load()
If AllocConsole() Then
hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
If hConsole = 0 Then MsgBox "Couldn"
Else
MsgBox "Couldn"
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
CloseHandle hConsole
FreeConsole
End Sub