News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Clearing The Screen

Started by cman, March 21, 2005, 03:23:36 PM

Previous topic - Next topic

cman

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.....

Tedd

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.
No snowflake in an avalanche feels responsible.

GregL


hitchhikr


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);


rags

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
God made Man, but the monkey applied the glue -DEVO

P1

Maybe what you want to look into is to create a new desktop with CreateDesktop.

Regards,  P1  :8)

cman

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!!!!

GregL

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?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

cman

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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi cman,

With Masm, You can use the clrscr function provided by msvcrt.dll / crtdll.dll

cman

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.....

P1

An old console trick was to print a formfeed, most would print the right number of linefeeds to clear the screen.

Regards,  P1  :8)