Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jun 30, 2001

CConsole - A class for creating console applications

' CCONSOLE Class
'
' Creates a console window and writes to it
' Example:
'     Dim cons As New CConsole
'     cons.WriteString "Hello World"

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
Const STD_OUTPUT_HANDLE = -11&

' the handle of this console
Dim hConsole As Long

Private Sub Class_Initialize()
    ' allocate a console when this object is created
    If AllocConsole() Then
        hConsole = GetStdHandle(STD_OUTPUT_HANDLE)
    End If
End Sub

Private Sub Class_Terminate()
    ' free the console when this object is destroyed
    If hConsole Then CloseHandle hConsole
    FreeConsole
End Sub

' write a string to the console

Sub WriteString(ByVal Text As String)
    Dim cWritten As Long
    WriteConsole hConsole, ByVal Text, Len(Text), cWritten, ByVal 0&
End Sub


Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date