Advertisement

Clearing the screen in dos

Started by April 28, 2001 01:22 PM
5 comments, last by Glandalf 23 years, 9 months ago
I can''t seem to remember what the clear screen funciton is in dos. Or where I have to get it from. I remeber clrscn or something like that. Any help here would be great thanks
I forget the exact name of the function, it usually depends on what compiler you have.

But, whatever the function is, you should be able to find it in the #include file "conio.h" - open it up with a text editor and see if you can find it!

// CHRIS
// CHRIS [win32mfc]
Advertisement
If you''re using the latest version of Visual C++ you may be out of luck. For some reason Microsoft didn''t include all the conio.h functions. Useful functions like clrscr() and gotoxy() are missing.
Thanks thats the function I was forgetting, been awhile since I messed with dos, thanks again

Glandalf
MSVC cannot compile for DOS. It can, however, compile to a Windows Console mode application, which means you can use Windows Console API functions, like this:
  bool Clear() {   HANDLE hconsole = GetStdHandle (STD_OUTPUT_HANDLE);   // get the number of character cells in the current buffer   CONSOLE_SCREEN_BUFFER_INFO csbi;   if (!GetConsoleScreenBufferInfo (hconsole, &csbi))       return false;   COORD coordScreen = { 0, 0 };    // here''s where we''ll home the cursor   DWORD cCharsWritten;             // number of chars written by console output routines   DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;   // fill the entire screen with blanks   return (FillConsoleOutputCharacter (hconsole, '' '', dwConSize, coordScreen, &cCharsWritten)              &&           FillConsoleOutputAttribute (hconsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten) &&           SetConsoleCursorPosition   (hconsole, coordScreen));}  


Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/
or you can do a cheap:
system("cls");
Advertisement
..or you could do it fast, which is what you should do. Some inline asm for ya:

  void ClearScreen(void){_asm {xor al, al ; Blank entire windowxor cx, cx ; Start at upper left (0,0)mov dh,24  ; Bottom line is y = 24mov dl,79  ; Right side is x = 79mov bh,7   ; Use normal attributesmov ah,6   ; Set SCROLL-UP functionint 10h    ; Call interrupt to clear DOS window}}  

This topic is closed to new replies.

Advertisement