PDA

Click to See Complete Forum and Search --> : Writing Console-Mode Applications in Visual Basic


pramod kumar
Feb 12th, 2001, 06:30 AM
Hi Scott Lloyd,

Thanx 4 publishing such a work. U helped me read input from console. Thanx again.
I had some doubt about the console application.
How to cls ?
How to changebkcolor ?
plz, help me.
with MSDN help I created some function but it not working

with regards
pramod kumar

Public Sub ClrScr(hconsole As Long)
Dim coordScreen As coord
coordScreen.x = 0
coordScreen.y = 0 '/* here's where we'll home the
' cursor */
Dim bSuccess As Long
Dim cCharsWritten As Long
Dim csbi As CONSOLE_SCREEN_BUFFER_INFO ' /* to get buffer info */
Dim dwConSize As Long '/* number of character cells in
' the current buffer */
'/* get the number of character cells in the current buffer */

bSuccess = GetConsoleScreenBufferInfo(hconsole, csbi)
dwConSize = csbi.dwSize.x * csbi.dwSize.y

'/* fill the entire screen with blanks */
Dim x As Integer
bSuccess = FillConsoleOutputCharacter(hconsole, x, dwConSize, coordScreen, cCharsWritten)

'/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo(hconsole, csbi)

'/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute(hconsole, csbi.wAttributes, dwConSize, coordScreen, cCharsWritten)

'/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition(hconsole, coordScreen)
End Sub

Public Function CahngeBkColor(hconsole As Long) As Boolean
Dim lpszString As String
lpszString = "Character String"
Dim cWritten As Long
Dim fSuccess As Long
Dim coord As coord
Dim wColors(3), wColor
Dim chFillChar

'// Write a string of characters to a screen buffer.

coord.x = 0 '// start at first cell
coord.y = 0 '// of first row
fSuccess = WriteConsoleOutputCharacter(hconsole, lpszString, Len(lpszString), coord, cWritten) ' // actual number written
If (Not fSuccess) Then CahngeBkColor = False

'// Write a string of colors to a screen buffer.

wColors(0) = BACKGROUND_RED
wColors(1) = BACKGROUND_RED Or BACKGROUND_GREEN Or BACKGROUND_BLUE
wColors(2) = BACKGROUND_BLUE
Dim i As Integer
i = 0
'testing any change
While (fSuccess And coord.x < 50)
coord.x = coord.x + 3
fSuccess = WriteConsoleOutputAttribute(hconsole, wColors(i), 3, coord, cWritten)
i = i + 1
If i > 2 Then i = 0
Wend
If (Not fSuccess) Then CahngeBkColor = False

End Function

KrishnaSantosh
Feb 16th, 2001, 06:21 AM
Try Using SendKeys.

pramod kumar
Feb 16th, 2001, 08:30 AM
How can clear the console application by senkey ?