Output in Console Program

Hello,

I'm using VC++ 6.0 and trying to find out how the following are done in a console application :

- Retrieve and set the cursor location on the screen.
- Set the text color and the background text color.
- Read characters back from the screen.
- Clear the screen.

It's really strange, I used to do C programing (a while ago) and these weren't really issues, but I cannot seem to locate functions that will do the above listed tasks in VC++.   If somebody has had experience with such issues I'd appreciate any help you can provide.

Sincerely,
Razvan L.
razvanlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

laeuchliCommented:
take a look at msdn.microsoft.com for these functions:
FillConsoleOutputCharacter
ReadConsoleInput
WriteConsole
SetConsoleSursorPosition
This are easy to use, and will do what you want, but you should know a bit about windows programming. You need a book. I recommand Windows 95 Programming in 21 Days.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
razvanlAuthor Commented:


0
laeuchliCommented:
Nice comment :-)
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

razvanlAuthor Commented:
Hi,

There wasn't any comment.  The only function I found useful was the SetconsoleCursorPosition, but the one for color modification as well as a method to clear the screen where also in the database at msdn.microsoft.com and I've located them.   Now, all I have left is finding out what the hell is the handle for the console so I can pass it to the functions.  But it is good to know the tools are there...

Sincerely,
Razvan L.
0
laeuchliCommented:
I think that you should read a book about it, some of the conecpts are hard to grasp if you don't read a book.
0
razvanlAuthor Commented:
Hi,

It isn't exactly the concepts that bother me, it's the implementation.  In any case, I am certain I'll figure it out one way or another.  And yes, I do have books for C++, but they either cover MFC or just C++ as the language itself... neither is useful in this case.

Sincerely,
Razvan L.
0
nietodCommented:
You might find some of the following functions useful.

enum Color
{
   Red,
   Green,
   Blue,
   Yellow,
   Purple,
   Cyan,  
   White,
   Black
};

void GotoXY(int X,int Y)
{
      HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD Coord = {X,Y};
      SetConsoleCursorPosition(StdOut,Coord);
}
void OutputStr(const char *S)
{
      HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      int StrLen = strlen(S);
      DWORD LenWrt;
      WriteConsole(StdOut,S,StrLen,&LenWrt,NULL);
}
void OutputStr(int X,int Y,const char *S)
{
      GotoXY(X,Y);
      OutputStr(S);
}

void ClearScreen()
{
   HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
   CONSOLE_SCREEN_BUFFER_INFO BufInf;
   COORD Origin = {0,0};
   DWORD LenWrt;

   GetConsoleScreenBufferInfo(StdOut,&BufInf); // Get screen rows and columns.
 
   int ChrCnt = BufInf.dwSize.X * BufInf.dwSize.Y; // Number of chars on screen.
   
   FillConsoleOutputAttribute(StdOut,0,ChrCnt,Origin,&LenWrt);
   FillConsoleOutputCharacter(StdOut,' ',ChrCnt,Origin,&LenWrt);
}
void SetColor(Color TxtCol,Color BckCol)
{
   HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
   WORD   Col    = 0;

   switch (TxtCol)
   {
   case Red:    Col |= FOREGROUND_RED;   break;
   case Green:  Col |= FOREGROUND_GREEN; break;
   case Blue:   Col |= FOREGROUND_BLUE;  break;
   case Yellow: Col |= FOREGROUND_RED | FOREGROUND_GREEN;   break;
   case Purple: Col |= FOREGROUND_RED | FOREGROUND_BLUE;    break;
   case Cyan:   Col |= FOREGROUND_GREEN | FOREGROUND_BLUE;  break;
   case White:  Col |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
   }
   switch (BckCol)
   {
   case Red:    Col |= BACKGROUND_RED;   break;
   case Green:  Col |= BACKGROUND_GREEN; break;
   case Blue:   Col |= BACKGROUND_BLUE;  break;
   case Yellow: Col |= BACKGROUND_RED | BACKGROUND_GREEN;   break;
   case Purple: Col |= BACKGROUND_RED | BACKGROUND_BLUE;    break;
   case Cyan:   Col |= BACKGROUND_GREEN | BACKGROUND_BLUE;  break;
   case White:  Col |= BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE; break;
   }
   SetConsoleTextAttribute(StdOut,Col);
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.