🔒 Locked
Clear Screen
Advertisement
Original Post
In C++, how would I clear the screan, and reset output to the top of the window (Win32 Console App.)?
I can''t get anything to work!!!
can''t you like System("cls") or something similar?
Undefined functions!!!
I can''t define any function with any header so that it can clear the screen. Also, how do I bring the cursor to the top-left. Examples are appreciated.
I can''t define any function with any header so that it can clear the screen. Also, how do I bring the cursor to the top-left. Examples are appreciated.
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.
After some MSDN searching, the following Win32 functions came up:
GetSTDHandle
SetConsoleCursorPosition
WriteConsoleOutput
These should clear the window and move the cursor.
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.
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();
What''s that code do?? I only know Console-design stuff, like cout, cin, variables, procedures..., no grafix.
Ah, what the hell...
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.
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.
I''m too slow, it seems.
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement