Computing.Net > Forums > Programming > clrscr() in Visual C++ 6.0

clrscr() in Visual C++ 6.0

Reply to Message Icon

Original Message
Name: Jarryd
Date: November 20, 2002 at 20:47:43 Pacific
Subject: clrscr() in Visual C++ 6.0
OS: Windows 98
CPU/Ram: P4 2.4Ghz/512 DDR
Comment:

I can't get clrscr() to work in my program. I even tried the alternative system("clr"), but that didn't work either. I included conio.h and I initialized clrscr()- void clrscr(void). for the system("clr"), the program executes, but everytime it is supposed to clear the screen, it says "bad command or file name." in the DOS window, but keeps going. anyone have any ideas about what's going on?

also, does anyone know of a function that checks the keyboard to see if anything is being pressed, and returns true or false?


Report Offensive Message For Removal

Response Number 1
Name: Ronin1
Date: November 21, 2002 at 11:23:59 Pacific
Subject: clrscr() in Visual C++ 6.0
Reply: (edit)

system ("cls");

Look at the return types defined for kbhit() or getch... both of those are in MSVC 6 under conio.h. getch() expects a key to be pressed and will return its integer value as a scan code. As for a logical test, you could use getch() in a loop and compare specific values inputted to one that you desire to make it "true"

unsigned key;

key = getch();

if(key == '\xD') enter key pressed
do something
else
continue loop

I don't know if there is a specific bool keyboard function or not.



Report Offensive Follow Up For Removal

Response Number 2
Name: kev
Date: November 21, 2002 at 13:34:37 Pacific
Subject: clrscr() in Visual C++ 6.0
Reply: (edit)

Yea, it's system("cls");

Not "clr".



Report Offensive Follow Up For Removal

Response Number 3
Name: Jarryd
Date: November 21, 2002 at 15:03:32 Pacific
Subject: clrscr() in Visual C++ 6.0
Reply: (edit)

chalk that up to inexperience. but does anyone know what to do about the clrscr() not working?


Report Offensive Follow Up For Removal

Response Number 4
Name: Jarryd
Date: November 21, 2002 at 16:14:06 Pacific
Subject: clrscr() in Visual C++ 6.0
Reply: (edit)

kbhit() was perfect. thank you very much.


Report Offensive Follow Up For Removal

Response Number 5
Name: rosser
Date: November 27, 2002 at 20:51:13 Pacific
Subject: clrscr() in Visual C++ 6.0
Reply: (edit)

The clrscr() function you are referring to is in the Borland extended library conio.h. This is a non-ANSI library that is implemented by a number of compiler developers. However, in the Microsoft Visual C++ implementation conio.h has no clrscr() function.

I have written a Win 32 API version of clear screen for console windows. It uses the FillConsoleOutputCharacter() function. There are demo program and driver example files at the following URL:

http://www.mc.cc.md.us/faculty/~rfarley/public_html/courses/cs225/examples/clrscr/

I have also developed a Win 32 version of getch() (another non-ANSI function) using the ReadConsole() function. An example of basic use is as follows:

SetConsoleMode( hConIn, ENABLE_PROCESSED_INPUT ); // read ctrl+C, no echo
FlushConsoleInputBuffer( hConIn ); // flush input buffer
ReadConsole(hConIn, &ch, 1, &numIn, NULL ); // Windows "getch()"

If you want to simulate getche() you need to use something like this after the ReadConsole:

putchar( ch ); // simulate getche keyboard echo with ReadConsole

Hope you find this enlightening...



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: clrscr() in Visual C++ 6.0

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software