• Advertisement

Archived

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

ClearScreen in VC++

This topic is 5804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

  
/* Stolen from Eric Tetz''s Win32 console wrapper */
bool Clear ()
{
HANDLE hconsole = GetStdHandle (STD_OUTPUT_HANDLE);

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

CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo (hconsole, &csbi))
return false;

COORD coordScreen = { 0, 0 }; // here''s where we''ll home the cursor

DWORD cCharsWritten; // number of chars written by console output routines

DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

// fill the entire screen with blanks

return (FillConsoleOutputCharacter (hconsole, '' '', dwConSize, coordScreen, &cCharsWritten) &&
FillConsoleOutputAttribute (hconsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten) &&
SetConsoleCursorPosition (hconsole, coordScreen));
}


Share this post


Link to post
Share on other sites
quote:
Original post by Arkainium
I believe there is a clrsrn() function or something like that in conio.h - try searching for it in help.

No, there''s not. Anyway, what you''re thinking of is clrscr().

Share this post


Link to post
Share on other sites
quote:
Original post by Arkainium
I believe there is a clrsrn() function or something like that in conio.h - try searching for it in help.


conio.h is non-standard. The Clear() function shown above will work fine. You can also use system("cls"), though a lot of people frown on using system().



MSVC++ 6
DirectX 7

[edited by - jdinger2 on June 1, 2002 9:08:32 PM]

Share this post


Link to post
Share on other sites

  • Advertisement