Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

My window will not clear itself (vc++)

Posted on 2003-03-11
6
Medium Priority
?
204 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
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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

581 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