How to clean the console in the assembly?

I am looking for a win32 api function that clears the console like the cls command Thank you! Devjeet

+1
assembly masm winapi
May 03 '11 at 7:41
source share
2 answers

It's pretty old, but it should still work. Switching to assembly language is left as an exercise for the reader, but should not be terribly difficult (most of them are just function calls, and multiplication is trivial):

 #include <windows.h> void clear_screen(char fill = ' ') { COORD tl = {0,0}; CONSOLE_SCREEN_BUFFER_INFO s; HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(console, &s); DWORD written, cells = s.dwSize.X * s.dwSize.Y; FillConsoleOutputCharacter(console, fill, cells, tl, &written); FillConsoleOutputAttribute(console, s.wAttributes, cells, tl, &written); SetConsoleCursorPosition(console, tl); } 
+8
May 03 '11 at 7:53 a.m.
source share

There is no Win32 API that clears the console directly - you need to use something like FillConsoleOutputCharacter .

+3
May 03 '11 at 7:46
source share



All Articles