Skip to main content
gamedev.net
🔒 Locked

console problem

Started by ATronic 15 replies 600+ views
Original Post
ATronic
ATronic
Hey, I have tried to find this many places and failed. I want to clear the contents of my console app''s window. Such as in dos when you type CLS. I tried the known command
  system("cls");  
But it had no effect. Is there another way? It needs to be fairly fast so I can get a decent looking refresh rate for my ASCII based rpg. Thanks a ton to all who answer. Right now I''m stuck doing something equivilant to
  cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n...  
Thanks again. Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Martee
Martee
There are better ways, but this should do it ...
        
DWORD numCharactersWritten;
COORD consoleCoords = {0, 0};
GetConsoleScreenBufferInfo(consoleHandle, &consoleInfo);
FillConsoleOutputCharacter(consoleHandle, ' ', consoleInfo.dwSize.X * consoleInfo.dwSize.Y,
consoleCoords, &numCharactersWritten);
FillConsoleOutputAttribute(consoleHandle, consoleInfo.wAttributes,
consoleInfo.dwSize.X * consoleInfo.dwSize.Y, consoleCoords, &numCharactersWritten);

... where consoleInfo is a CONSOLE_SCREEN_BUFFER_INFO, and consoleHandle is a HANDLE to a console.

Edited by - Martee on January 8, 2002 10:57:45 PM
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
ATronic
ATronic
I don''t think this will work in my situation. This is the base of the console app, the skeleton code you begin with.

  
#include <iostream>
using namespace std;

int main( void )
{
cout << "This is a test" ;
return 0;
}


I have no win32 at all, nothing using windows.h! So how would I clear this screen. I have only basic knowledge on console apps, as you probably can see.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Martee
Martee
If you include windows.h, it should work. I used the above code in a similar program. But otherwise ... I don''t know of any non-Windows ways of doing it.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
ATronic
ATronic
I tried including windows.h, no luck. Thanks anyway. I decided to make it using win32 and win32 draw functions. I''m building my own basic cout with \n and so on. More flexible anyway I guess. Easy to port too. Thanks for your time.


Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Drakkor
Drakkor
It''s a little ugly, but you should be using a console buffer anyway... this might help you on your way...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/conchar_25b9.asp

D
Dredge-Master
Dredge-Master
is it win32 or dos based.

If it is not a win32 exe (if your lucky you can still pull it off) jsut #include <conio.h> and use clrscr();

there are equivilent functions and workarounds in stdio, but I forgot what they were as I always used conio.
Beer - the love catalystgood ol' homepage
ATronic
ATronic
win32 exe I believe. As usual, an emulated console.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
hewhay
hewhay
did you included cstdlib?
If you did what happened with system ("cls");
humanity will always be slaved by its ignorance
ATronic
ATronic
as my first post says, absolutely nothing.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
strtok
strtok
I''m not sure, but I think that Win32 consoles may support ANSI escape codes, because I seem to remember porting a really old BBS door game I wrote to Win32. There should be a code to clear the screen. Search the net for ANSI escape sequences and you''ll probably be able to find something useful.
hewhay
hewhay
I''m not sure why that happened and there are no compilers around here so if this doesn''t work, sorry. Try doing a cout << flush;
before the system("cls");. Because the buffer may be flushing after the call. Also i think that there is an exec function maybe it works there..

By the way there is the posibility of your compiler having conio.h, if you do there is a function call clearscreen or cls or something like that, read the header
humanity will always be slaved by its ignorance
ATronic
ATronic
Found what I needed in conio.h, thanks a ton. One other thing, anyone know how to input a single char without waiting for the user to hit return?

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
ironfroggy
ironfroggy
using C++ iostream of C IO functions? I personally enjoy the simplicity of some older C functions.
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
gavco98
gavco98
getch(). Cant remember what header its in though, its either conio.h or stdio.h try em both
Gavin Coates
[size="1"]IT Engineer / Web Developer / Aviation Consultant
[size="1"][ Taxiway Alpha ] [ Personal Home Page ]
ATronic
ATronic
Thanks a ton!

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"

Topic Locked

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

Sign in to reply to this topic.