HomeProjectsServicesContactus
» Guest
  Sign In     Register    
Unclassified » Win32 Console cls() function.
A function like the DOS cls command for clearing the Console Screen.
Author : Rich Burnham / Date : 2005-05-08 13:40
cls()

OS Min: Win9x / Win200/XP
Inc Header: Windows.h
Library: Kernel32.lib

This function is used to clear the console screen of console applications and return the caret to home. It is a win32 version of the msdos cls command.

Code:
//
// cls()
//
// Clear the console screen
//
void cls( void )
{
//get console output handle
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);

//get console info
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hCon, &csbi);

//calculate number of charaters in console
DWORD br;
DWORD N = csbi.dwSize.X * csbi.dwCursorPosition.Y + csbi.dwCursorPosition.X + 1;

//write spaces to the console thus clearing it
COORD curhome = {0,0};
    FillConsoleOutputCharacter(hCon, ' ', N, curhome, &br);

//set info
csbi.srWindow.Bottom -= csbi.srWindow.Top;
csbi.srWindow.Top = 0;
SetConsoleWindowInfo(hCon, TRUE, &csbi.srWindow);

//return the cursor to home
SetConsoleCursorPosition(hCon, curhome);
}
0 member(s), 15 guest(s)
| Site Map | Statistics | Terms of Use | Privacy Policy |
Copyright (C) GoCoding.Com 2004-2007
Powered by Seditio
Contacts