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

2 ?'s With Win32 Console Program

Started by Tonic151 Jul 19, 2002 at 10:48 AM 5 replies 300+ views
Original Post
Tonic151
Tonic151
First i was wondering what the best function to use for a console program to display or ouput Colored Text in the window.. And also Cursor Position... Next i was wondering what is a good way to go about creating a percentage bar in a console application for when you running through processes you output % done.. or like in those cool old dos aps and installers they useta have the ANSI text with the bars that go accross [********............30%....................] etc.. Thanks. [edited by - tonic151 on July 19, 2002 11:49:58 AM]
Arild Fines
Arild Fines
Take a look at the Win32 console API[1]

[1]http://msdn.microsoft.com/library/en-us/dllproc/conchar_3vg3.asp


"The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your fucking mouth shut and hadn''t asked any questions."
Frank Zappa
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Neff
Neff
I have a nice library, msoftcon. I''m not sure if it is free or not, it might be... Basically they took existing Win32 functions and made some nice easy to use ones. The color function does this:

SetConsoleTextAttribute( hConsole,
(WORD)((background << 4) | foreground) );

where background and foreground are ints, and hConsole is:

HANDLE hConsole;
hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

That could help you if you haven''t figured it out yet:

COORD cursor_pos;
//... give cursor_pos some values ...
SetConsoleCursorPosition(hConsole, cursor_pos);

So yeah...

About that percentage bar:
I would write a class PERCENTAGE_BAR, say, that held currentPercentage, and had display functions to do the graphics, and updatePercentage(float newPercent) to update it, or whatever. In the list of files you install, you could make a call to updatePercentage based on what file it was being installed... just a quick idea... hope it helps!

Neff
Tonic151
Tonic151
Great.. Thanks for the Tips.. Found the basic commands.. But i''m still looking for one to get current cursor position.. hmm i''ll keep looking thoguh..
Tonic151
Tonic151
Hmm small help, i got most of the Basic console function.. but i can''t find anything that will GET the Current Cursor Position.. I have Text, Write to a X Y Position,, but no Get Current Position.. is that anything i can use or a function i can write to get that information??

Thanks
Martee
Martee
Have a look at GetConsoleScreenBufferInfo().
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Tonic151
Tonic151
quote:
Original post by Martee
Have a look at GetConsoleScreenBufferInfo().


thanks man, but i found something a lot easier..
luckly DevC++ is sweet enough to include the sourse for their library functions for conio.h.. and the wherey() and wherex() are just what i needed.. =) and a lot easier..





[edited by - Tonic151 on July 20, 2002 8:31:38 PM]

Topic Locked

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

Sign in to reply to this topic.