Archived

This topic is now archived and is closed to further replies.

Ragadast

How do you clean the screen?

Recommended Posts

Ragadast    122
How do you clean the screen with C++? I have another question, is VC++ compiler different than Borland C++ one? I tried compiling a console program in VC++ but it didn''t work (working with iostream.h and string.h), and tried compiling with Borland C++ and it worked. What happened?

Share this post


Link to post
Share on other sites
bob_the_third    122
A program that cleans your screen? That would be awesome! Just kidding, I couldn''t resist As to clearing the screen in console mode I''ve had trouble with that myself...apparently Microsoft doesn''t really want people to write console apps. However it''s probably possible; I usually just print enough blank lines to push everything off the screen.

Share this post


Link to post
Share on other sites
Fruny    1658
There is no standard way of clearing the screen.
C++ doesn''t even have a notion of "screen".

Either use platform-dependent libraries (e.g. conio.h as b.bunny pointed out), or ANSI escape sequences.

Yes, VC++ is different from BC++

Finally, don''t use iostream.h but iostream unless you want the Code Police to raid your computer. (iostream.h is a deprecated header for backward compatibility only.)

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

Share this post


Link to post
Share on other sites
a person    118
ms dont mind, its just there is no standard way. search the win32 api for the console functions, all the control you want (including make the console size large, moving the cursor, fill the console up, using different pages, etc.). they give you stupendous control, in fact so much you could do double buffered animation.

also look into ansi codes (make sure ansi.sys is loaded).

Share this post


Link to post
Share on other sites
LordLethis    122
There is the code for such a function in MSDN, I''ll copy & paste it in here:

/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here''s where we''ll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */

/* get the number of character cells in the current buffer */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

/* fill the entire screen with blanks */

bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) '' '',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );

/* get the current text attribute */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );

/* now set the buffer''s attributes accordingly */

bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );

/* put the cursor at (0, 0) */

bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}

As parameter u can give GetStdHandle( STD_OUTPUT_HANDLE).

Share this post


Link to post
Share on other sites
aftermath    100
quote:
Original post by Rickmeister
Yet another ugly way to clear the console...


#include <iostream.H> // muahahahaha

void clear_screen()
{
system("cls");
}



Maby im wrong, but who ever said we are using Windows/DOS here. Maby we arem but THAT ^ would only work on Wundows/DOS. Maby im worong.

[ my engine ][ my game ][ my email ]
SPAM

Share this post


Link to post
Share on other sites
Rickmeister    182
quote:
Original post by AfTeRmAtH
Maby im wrong, but who ever said we are using Windows/DOS here. Maby we arem but THAT ^ would only work on Wundows/DOS. Maby im worong.


Actually system(const char*) is ANSI-C standard.. What command you decide to send is OS dependant.. But a wild guess is that Radagast uses Win32..

Share this post


Link to post
Share on other sites
TheMuuj    122
You should avoid system("cls") because it involves loading COMMAND.COM, calling the CLS command, and returning. This is entirely too much work/memory for something as simple as a clear screen.

If you are using Windows and don''t want to call the Windows console functions, then you can always output 25 blank lines. Of course, your cursor will start at the bottom, but it will get the job done. Moving the cursor back to the top will probably require the Windows console functions anyway.

If you are looking for a cross-platform solution, there simply is not one that I know of (although I''m sure SOMEone has done it before).

But if you write a program to CLEAN the screen, I''ll pay money for it. Those stupid monitor wipes simply don''t work. :-)

I can do it in 16-bit x86 Assembly code, and with time I could probably write a 32-bit inline function (unless Windows blocks out INT 10h). Then again, I''m sure others have done this before. Do some searching on google.

--TheMuuj

Share this post


Link to post
Share on other sites