The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cman on March 21, 2005, 03:23:36 PM

Title: Clearing The Screen
Post by: cman on March 21, 2005, 03:23:36 PM
Is there a function for "clearing the screen" in console applications? I also wondered if anyone had code for a version of clrscr()  ( Borland conio.h library function ) to Visual C++ ? I'd like to write a version in assembler and use the function in VC++ programs. Thanks.....
Title: Re: Clearing The Screen
Post by: Tedd on March 21, 2005, 06:27:39 PM
I don't think there is. I think it's a case of getting the console sizes and then either filling it with spaces or newlines :bdg and then resetting the cursor position.
Title: Re: Clearing The Screen
Post by: GregL on March 21, 2005, 06:39:47 PM
http://www.mvps.org/vcfaq/lang/7.htm

http://support.microsoft.com/kb/q99261/

MASM32 has a ClearScreen procedure.
Title: Re: Clearing The Screen
Post by: hitchhikr on March 21, 2005, 06:45:06 PM

void Cls_Function(HANDLE hStdOut, WORD Clear_Color) {
COORD Dest_Coord = { 0, 0 };
DWORD Attr_Write;
TCHAR Char_To_Clear = ' ';
DWORD Chars_Number;
CONSOLE_SCREEN_BUFFER_INFO Window_Size;

GetConsoleScreenBufferInfo(hStdOut, &Window_Size);
Chars_Number = Window_Size.dwSize.X * Window_Size.dwSize.Y;
FillConsoleOutputAttribute(hStdOut, Clear_Color << 4, Chars_Number, Dest_Coord, &Attr_Write);
FillConsoleOutputCharacter(hStdOut, Char_To_Clear, Chars_Number, Dest_Coord, &Attr_Write);
Caret_Position.Y = 0;
Caret_Position.X = 0;
SetConsoleCursorPosition(hStdOut, Caret_Position);
}



Cls_Function(GetStdHandle(STD_OUTPUT_HANDLE), 0x2);

Title: Re: Clearing The Screen
Post by: rags on March 21, 2005, 07:00:29 PM
From The Masm32 Lib Reference:

ClearScreen

ClearScreen proc

Description
ClearScreen clears the console window and places the text cursor at position 0,0.
It takes no parameters and does not return a value.

The following macro makes this procedure easier and faster to use.


      cls MACRO

        invoke ClearScreen

      ENDM
Title: Re: Clearing The Screen
Post by: P1 on March 21, 2005, 07:44:39 PM
Maybe what you want to look into is to create a new desktop with CreateDesktop.

Regards,  P1  :8)
Title: Re: Clearing The Screen
Post by: cman on March 21, 2005, 09:07:02 PM
Wow , thanks guys! How would I take something like the macro:


      cls MACRO

        invoke ClearScreen

      ENDM




And use MASM to create a header file that I could call in a VC++ program? I would really be interesting to me to create my own custom header files with MASM. How would this be done? Thanks guys!!!!
Title: Re: Clearing The Screen
Post by: GregL on March 22, 2005, 12:11:08 AM
cman,

Clearing the screen in Win32 console-mode programs is done with Win32 API functions. If you look at the source code for the MASM32 ClearScreen procedure you'll see what I mean. I don't know of any other way to do it. So, coding it in MASM isn't going to get you any substantial performance gains.

Maybe you want to call a MASM procedure from C just for the experience of doing it?
Title: Re: Clearing The Screen
Post by: hutch-- on March 22, 2005, 01:50:37 AM
I don't remember the macro system in C well enough but I imagine that a single command like "cls" would have to be easy enough to implement. The API code is trivial so its a matter of naming a function that is convenient and perhaps trying a C macro to make it easier to use.
Title: Re: Clearing The Screen
Post by: cman on March 25, 2005, 12:51:28 AM
Thanks for the information! I really wanted to add some functions from Borland Turbo to Visual C++. For instance , VC++ does not a function named clrscr() to clear the screen in a DOS box application ( I don't think I understand the difference between a DOS box application and a WIN32 console application  :red , could someone explain the difference? ). I'd like to write and add some Borland functions in a header file that I can use in VC++ ( I have thousands of lines of Turbo C++ that won't quite compile with VC++ ) . Writing my own header files in asm sounds like great fun , too!  :bg
Title: Re: Clearing The Screen
Post by: hutch-- on March 25, 2005, 02:16:18 AM
A 16 bit DOS application will run in the 16 bit subsystem where a 32 bit console app runs in 32 bit Windows and displays a console as well. If you are writing 32 bit code, you use the console APIs to read / write to the console.
Title: Re: Clearing The Screen
Post by: Vortex on March 25, 2005, 11:12:16 AM
Hi cman,

With Masm, You can use the clrscr function provided by msvcrt.dll / crtdll.dll
Title: Re: Clearing The Screen
Post by: cman on March 26, 2005, 02:37:13 PM
Quote from: hutch-- on March 25, 2005, 02:16:18 AM
A 16 bit DOS application will run in the 16 bit subsystem where a 32 bit console app runs in 32 bit Windows and displays a console as well. If you are writing 32 bit code, you use the console APIs to read / write to the console.

So a Win32 console application is just a 32-bit character-cell type program ( like a DOS application )? I guess I've been confused about these two types of applications.....
Title: Re: Clearing The Screen
Post by: P1 on March 28, 2005, 01:44:21 PM
An old console trick was to print a formfeed, most would print the right number of linefeeds to clear the screen.

Regards,  P1  :8)