Sign in to follow this  
dk32321

clearing a part of the console screen

Recommended Posts

I know that system("cls") clears the whole console screen, but i want to know how do you clear a certian part of the screen, and olny that part. If anybody can help i will apprecaite it

Share this post


Link to post
Share on other sites
Unfortunately, there isn't a standard way to do such things if you're using C or C++. If you're working on windows, you might want to look through the MSDN entries Console Functions and Consoles(Overview). Both contain a lot of helpful information, and somewhere between them I think there are a few examples of various things.

For linux or another OS, I have no idea how to do it.

Share this post


Link to post
Share on other sites
A very cheap way to do it would be to just output "std::cout << std::endl;" until you have the correct space. This is not that good if the player has the number of rows in the console set differently than you or something.

Share this post


Link to post
Share on other sites
Presuming Win32...

#include <windows.h>

void PartialConsoleClear( size_t start_column , size_t start_row , size_t end_column , size_t end_row ) {
//note: [begin,end) style ranges used (think iterators)
//this means [40,40) covers 0 elements.

HANDLE console_handle = GetStdHandle( STD_OUTPUT_HANDLE );

assert( start_column <= end_column );
assert( start_row <= end_row );

for ( size_t row = start_row ; row != end_row ; ++row ) {
COORD position;
position.X = start_column;
position.Y = row;
DWORD characters_writen;
FillConsoleOutputCharacter( console_handle , _T(' ') , end_column - start_column , position , & characters_written );
}
}


All gleaned from the insights of reading documentation.

Seriously check out the MSDN (allready linked) if you're going to be doing any windows specific programming.

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Unfortunately, there isn't a standard way to do such things if you're using C or C++. If you're working on windows, you might want to look through the MSDN entries Console Functions and Consoles(Overview). Both contain a lot of helpful information, and somewhere between them I think there are a few examples of various things.

For linux or another OS, I have no idea how to do it.


For your information there is a library called ncurses, accessible by curses.h. It is an incredible library and windows could seriously do with its own version.

ace

Share this post


Link to post
Share on other sites
This site teaches you how to make a console window of whatever size you want and then write to a back buffer so you can display whatever you want:

http://benryves.com/tutorials/?t=winconsole&c=all

I made a console debugger for my ingame objects with it. I can type in (seperate input which is great) a certain command like "display ____" and it will list off that objects stats. It's very sloppy code that needs cleaning up but took only a few hours. Hope this helps you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this