Skip to main content
GameDev.net gamedev.net
🔒 Locked

Console IO

Started by Xgkkp Feb 18, 2003 at 7:10 AM 8 replies 250+ views
Original Post
Xgkkp
Xgkkp
Does anyone know how, using a console mode application in visual c++, I can do some simple console stuf like clearing the screen, setting the location of output and things like that. I just want to be able to do a percentage complete indicator that stays in the same place, much like format, and setting where the cursor is for typing. I can''t for the life of me work it out. Any help would be greatly appreciated!
ex4st
ex4st
Well the common way is to display the "backspace" character ...

for (int percent = 0; percent <= 100; percent++)
{
printf("%02d",percent);
Sleep(1000);
printf("%c%c",0x8,0x8);
}


Exood4 Studios


[edited by - brunow on February 18, 2003 8:32:53 AM]
niyaw
niyaw
try WriteConsoleOutput.
Maximus
Maximus
system("cls");

Thatll do it, iirc

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
Xgkkp
Xgkkp
Thanks a lot! I think I''ll use all of them!

how about setting the place where the blinking ''enter text'' cursor is?
Pipo DeClown
Pipo DeClown
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/conchar_3vg3.asp


.lick
Lektrix
Lektrix
quote:
Original post by Xgkkp
Does anyone know how, using a console mode application in visual c++, I can do some simple console stuf like clearing the screen, ...



Using the system() function is nice and easy, just pass "cls" to it, i.e. system("cls");. P.S. Try going into the MS-DOS prompt and type "cls" (without the quotation marks) to see how system() helps you in this particular case.

quote:
Original post by Xgkkp
setting the location of output and things like that.



Have a search for SetConsoleCursorPosition() on MSDN. I think you can call like this, but I'm not sure (I'm not on a computer with a compiler on at the moment):


      
#include <windows.h>

void SetCursor(int row, int col)
{
col =- 1; // hmmmm, I think you

row =- 1; // are meant to do this


COORD cursorCoords;
cursorCoords.X = col;
cursorCoords.Y = row;

HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(handle, cursorCoords);
}

I would recommend having a look on MSDN just to make sure though; might also be of some help.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on February 18, 2003 11:05:49 AM]
Tonic151
Tonic151

If you would like a great example of most of the the console commands. Download the DevC++ Compiler. and use the function from their conio.h file. It pure windows API fuctions for all the following and they should work with fine with visual studio.. only 1 tip.. on the goto x/y you will want to add a (y + 1) and ( x + 1 ) before the screen is drawn..

Xgkkp
Xgkkp
Thanks everyone, WriteConsoleOutput was the key. knowing that, I could use the c++ help file to extract all the rest of the information about console io, including setting colours/cursor stuff etc. Thanks!

One more question though..... How do I do the same sort of thing for Unix? I don''t have any help files for that!(all the functions are for windows consoles)

Topic Locked

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

Sign in to reply to this topic.