Skip to main content
gamedev.net
🔒 Locked

Clear Screen

Started by gamechampionx 18 replies 1k views
IndirectX
IndirectX
I believe there''s clrscr or _clrscr or something similar in conio.h.
---visit #directxdev on afternet <- not just for directx, despite the name
IndirectX
IndirectX
quote:
Original post by gamechampionx
I can''t get anything to work!!!

This is not a question, and can''t be answered.
---visit #directxdev on afternet <- not just for directx, despite the name
Magriep
Magriep
you want to include the windows.h library (if that isn''t it then it''s windowsx.h). Then you use the function system("cls");. The clrscr(); function only works on DOS compilers.
GroZZleR
GroZZleR
You could also clear the screen by using a loop that cout''s endlines, and then reposition the cursor to the top left corner.
IndirectX
IndirectX
quote:
Original post by GroZZleR
You could also clear the screen by using a loop that cout''s endlines, and then reposition the cursor to the top left corner.

Slow and ugly-looking.
---visit #directxdev on afternet <- not just for directx, despite the name
clrscr
clrscr
Its clrscr()
And I think its conio.h


"The most likely way for the world to be destroyed, most experts agree, is by accident. That''s where we come in; we''re computer professionals. We cause accidents."
-Nathaniel Borenstein
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
lackluster
lackluster
can''t you like System("cls") or something similar?
henrym
henrym
Wouldn''t a call to the system be slow?
IndirectX
IndirectX
Just looked at conio.h in my MSVC6: I think a LOT of stuff is missing compared to BC++ 3.1 I used a while ago! No clrscr, no nothing. Anyone know what happened to these?

After some MSDN searching, the following Win32 functions came up:

GetSTDHandle
SetConsoleCursorPosition
WriteConsoleOutput

These should clear the window and move the cursor.
---visit #directxdev on afternet <- not just for directx, despite the name
Arild Fines
Arild Fines
quote:
Original post by IndirectX
I think a LOT of stuff is missing compared to BC++ 3.1 I used a while ago! No clrscr, no nothing. Anyone know what happened to these?


They are legacy DOS functions. If you want to write Win32, write Win32.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Spiral
Spiral

  

DWORD writtenchars, writtenattrs;
COORD coord = {0, 0};
CONSOLE_SCREEN_BUFFER_INFO cbsi;
HANDLE standardout;

AllocConsole();
standardout = GetStdHandle( STD_OUTPUT_HANDLE );

GetConsoleScreenBufferInfo(standardout, &cbsi);
FillConsoleOutputCharacter(standardout, 0, cbsi.dwSize.X*cbsi.dwSize.Y, coord, &writtenchars);
FillConsoleOutputAttribute(standardout, cbsi.wAttributes, cbsi.dwSize.X*cbsi.dwSize.Y, coord, &writtenattrs);
SetConsoleCursorPosition(standardout, coord);

CloseHandle(standardout);
FreeConsole();

--------------------Go Stick Your Head In A Pig
Arild Fines
Arild Fines
Ah, what the hell...

  
HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );

//get the size of the window

CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo( hStdOut, &info );

int noChars = info.dwSize.X * info.dwSize.Y;

//upper left

COORD coord;
coord.X = 0;
coord.Y = 0;

//fill the screen with spaces

DWORD written;
FillConsoleOutputCharacter( hStdOut, '' '', noChars, coord, &written );

//reset the cursor

SetConsoleCursorPosition( hStdOut, coord );

You might want to reset the console attributes too if you have been messing with them, but I couldnt be bothered to look up the parameters. The API call in that case is FillConsoleOutputAttribute.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Spiral
Spiral
That is "console stuff". Look up each function in msdn. It should become clear.
--------------------Go Stick Your Head In A Pig
Arild Fines
Arild Fines
quote:
Original post by gamechampionx
I only know Console-design stuff, like cout, cin, ...

Strictly speaking, neither cout nor cin has anything to do with the console.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.