?
Solved

My window will not clear itself (vc++)

Posted on 2003-03-11
6
Medium Priority
?
203 Views
Last Modified: 2010-04-01
Okay....here's an interesting problem. I am using Visual C++ (6.0). Well....I am trying to get my window to clear ( in a console app. ). Well, at school (that uses Borland C++ 5.01) I've always used clrscr() from the conio.h file. But....when I include the header file and try and use the funtion....it doesn't work, and gives me one or more (typically more) errors. What's wrong and what should I be doing that I'm not?
0
Comment
Question by:Mixolydian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:e12voltsdac
ID: 8115247
Try including conio.c

Your conio at home might be not be including the actual implementation of conio.

What are your errors?

If that still doesn't work, try:

system("cls");
and you'll need stdlib.h

Hope this helps.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8117876
Conio.h is screen-based, whereas Visual C++ is window-based. But I guess when you excute a new program, it starts automatically in a cleared window.

Mayank.
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8117909
This question is pretty often.

For years I've been using Borland C++ and can not imagine how hard is life without clrscr(), gotoxy(), textcolor() etc.

I can't believe Microsoft can not make it. Is there some license issue or something ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:Mayank S
ID: 8117947
That's why I prefer to work with Java. Its also platform-independent. But VC must be having some equivalent method I'm unaware of.

Mayank.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 8339249
It is rather silly to try to do GUI stuff in a console app (which is why Microsoft does not bother to supply a high-level library of fns like cls and the beloved Borland gotoxy -- what is this, 1985?).  But there is a complete set of primitives one can use to manipulate the console.  For instance, here is a cls() fn and an example of usage.

#include <windows.h>
#include <stdio.h>   // for printf

void cls()
{
     HANDLE hConScreen=  GetStdHandle( STD_OUTPUT_HANDLE );

     CONSOLE_SCREEN_BUFFER_INFO rCBI;
     GetConsoleScreenBufferInfo(hConScreen, &rCBI );
     int nScreenBytesTotal= rCBI.dwSize.X * rCBI.dwSize.Y;

     WORD ClrWhiteOnBlack= FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;

     COORD pt; pt.X=0; pt.Y=0;
     DWORD nActual;
     FillConsoleOutputCharacter( hConScreen, ' ', nScreenBytesTotal, pt, &nActual );
     FillConsoleOutputAttribute( hConScreen, ClrWhiteOnBlack , nScreenBytesTotal, pt, &nActual );
}

void main()
{
     printf("hi there\n");
     printf("hi there\n");
     printf("hi there\n");
     printf("hi there\n");
     printf("hi there\n");
     printf("hi there\n");
     printf("hi there\n");
     cls();
}
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9481832
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: DanRollins

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question