Results 1 to 3 of 3

Thread: Writing Console-Mode Applications in Visual Basic

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Location
    Kerala, India
    Posts
    42

    Exclamation How to clear console window ?

    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
    Last edited by pramod kumar; Feb 12th, 2001 at 08:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width