4 Replies - 2158 Views - Last Post: 15 September 2011 - 03:01 AM Rate Topic: -----

#1 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Clear screen without system("CLS")

Posted 15 September 2011 - 02:20 AM

Is there a way to clear the screen with out system("CLS")?

Thanks for reading this topic.
Is This A Good Question/Topic? 0
  • +

Replies To: Clear screen without system("CLS")

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Clear screen without system("CLS")

Posted 15 September 2011 - 02:25 AM

There is no portable way to do so without relying on platform-specific console sizes.

Here is an (untested) example from MSDN with some questionable coding practice eliminated:
#include <windows.h>
 void cls( HANDLE hConsole )
 {
    COORD coordScreen = { 0, 0 };    
    BOOL bSuccess;
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi; 
    DWORD dwConSize;                 

    GetConsoleScreenBufferInfo( hConsole, &csbi );
    FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
       dwConSize, coordScreen, &cCharsWritten );

    GetConsoleScreenBufferInfo( hConsole, &csbi );
    FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
       dwConSize, coordScreen, &cCharsWritten );

    SetConsoleCursorPosition( hConsole, coordScreen );
 }
It seems to work by moving the cursor the the start, getting the size, filling the console and moving it back.

You can get the console handle by using GetConsoleWindow.

This post has been edited by PlasticineGuy: 15 September 2011 - 02:26 AM

Was This Post Helpful? 2
  • +
  • -

#3 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: Clear screen without system("CLS")

Posted 15 September 2011 - 02:40 AM

What about for a console application?
Thanks for your effort by the way. :)
Was This Post Helpful? 0
  • +
  • -

#4 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Clear screen without system("CLS")

Posted 15 September 2011 - 02:44 AM

It IS for a console application. The WinAPI deals with any window, GUI or otherwise.
Was This Post Helpful? 2
  • +
  • -

#5 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: Clear screen without system("CLS")

Posted 15 September 2011 - 03:01 AM

I suck . . . >.<
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1