Advertisement

CLS in C++...

Started by April 10, 2002 08:41 PM
6 comments, last by Xier 22 years, 5 months ago
ok,... this should be the easiest question out there... "yet no one can answer it." How do you Clear the screen in win32app? "DOS scean?" I have a text thingy, and i would like to clean the screen when i am done... i have asked this question ever sense ive started C++ and no one could answer it. as for why im doing this "i like to learn all the basics and stuff before jumping into the big stuff" Thanks all! ~Xier ps... CLS is clear screan QBasic
Well, in DJGPP I remember there being a clrscr (sp?) function in conio.h, but it isn''t there in VC++ (that I''ve found). The next closest thing would be system("cls"). system should be declared in process.h or stdlib.h.
Advertisement
Well, if cls is in one of those header, what would the syntax look like? just a plane old:

cls; // ?

Thanks for the help!

~xier

  #include <stdlib.h> // Required includesystem("cls"); // Clear the screen  





_____________________________________________________

ICQ #: 149510932

Google - OpenGL - DirectX - Windows Guide Network - MSDN - Symantec Virus Info

"Imagination is more important than knowledge." - Albert Einstein

TO STAFF:

^ Why is the above all green? ^
You could make your own cls function.
-Forcaswriteln("Does this actually work?");
Advertisement
quote: Original post by Xier
ok,... this should be the easiest question out there... "yet no one can answer it."

Are you suggesting that all of humanity cannot provide an answer to this question? If no one can answer it, why are you asking?
Going to the MDSN and searching for "clear screen console" provided this bit of code :


  #include <windows.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include "console.h"void cls() {	HANDLE	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);	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);	if (!bSuccess) return;	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;	/* fill the entire screen with blanks */	bSuccess = FillConsoleOutputCharacter(hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten);	if (!bSuccess) return;	/* get the current text attribute */ 	bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi);	if (!bSuccess) return;	/* now set the buffer's attributes accordingly */ 	bSuccess = FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); 	if (!bSuccess) return;	/* put the cursor at (0, 0) */   	bSuccess = SetConsoleCursorPosition(hConsole, coordScreen); 	if (!bSuccess) return;	return;}  




Iain Hutchison
Programmer, Silicon Dreams
The views expressed here are my own, not those of my employer.

[edited by - pieman on April 11, 2002 10:43:49 AM]
Iain HutchisonProgrammer, Silicon DreamsThe views expressed here are my own, not those of my employer.

This topic is closed to new replies.

Advertisement