Announcement

Collapse
No announcement yet.

Wie geht Clear Screen in der Konsolenanwendung???

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wie geht Clear Screen in der Konsolenanwendung???

    Hallo,

    ich bin gerade dabei C++ zu erlernen. Ich verwende dazu Microsoft Visual c++6 Compiler.

    Nun folgendes ich habe ein leeres Konsolenprojekt geöffnet und wollte die Anzeige löschen.
    Dazu hab ich folgenden Code verwendet:

    #define CLS (cout << "\033[2J")

    Nur wenn ich dann im Programm CLS aufrufe wird nur : [2J <BR>
    ausgegeben!!<BR>
    <BR>
    Was mache ich hier falsch ich dachte die Bildschirmsteuerzeichen gehören <BR>auch VC++ Standard??<BR>

    Kann mir bitte jemand sagen wie unter VC6++ dir Clear Screen Funktion <BR>geschrieben wird.<BR>
    <BR>
    danke<BR>
    Stefan

  • #2
    Die Steuerzeichen, die Du verwendest, sind so genannte ANSI-Escape-Sequenzen. ESC[2J ist die zum Löschen des Bildschirms (genau genommen müsste man sogar noch ESC[0;0H hinzufügen, damit auch die Cursorposition links oben hin gesetzt wird.)
    Diese Sequenzen funktionieren aber nur, wenn der Treiber ANSI.SYS geladen ist, und das wird heutzutage unter Windows praktisch nicht mehr gemacht.

    Folgendes habe ich in den Tiefen des MSDN gefunden, viel Glück damit!

    <PRE>
    PSS ID Number: Q99261

    Authored 26-May-1993 Last modified 25-May-1995

    The information in this article applies to:

    - Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5,
    3.51, and 4.0

    SUMMARY

    There is no Win32 application programming interface (API) that will clear
    the screen in a console application. However, it is fairly easy to write a
    function that will programmatically clear the screen.

    MORE INFORMATION

    The following function clears the screen:

    void cls( HANDLE hConsole )
    {
    COORD coordScreen = { 0, 0 }; /* here's where we'll home the
    cursor */
    BOOL bSuccess;
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
    DWORD dwConSize; /* number of character cells in
    the current buffer */

    /* get the number of character cells in the current buffer */

    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
    PERR( bSuccess, "GetConsoleScreenBufferInfo" );
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

    /* fill the entire screen with blanks */

    bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
    dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputCharacter" );

    /* get the current text attribute */

    bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );

    PERR( bSuccess, "ConsoleScreenBufferInfo" );

    /* now set the buffer's attributes accordingly */

    bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
    dwConSize, coordScreen, &cCharsWritten );
    PERR( bSuccess, "FillConsoleOutputAttribute" );

    /* put the cursor at (0, 0) */

    bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
    PERR( bSuccess, "SetConsoleCursorPosition" );
    return;
    }

    Additional reference words: 3.10 3.50 4.00 95 clearscreen

    KBCategory: kbprg
    KBSubcategory: BseCon

    </PRE&gt

    Comment


    • #3
      Hallo Mathias,<BR><BR>

      ich habe es nun rausbekommen wie es funktioniert:<BR>

      Hier die Lösung:<BR><BR>

      #include <iostream><BR>
      #include <conio.h><BR>

      using namespace std;<BR><BR>

      void main()<BR>
      {<BR>
      cout << "Text1" <<endl;<BR>
      cin.get();<BR>
      system("cls");<BR>
      cin.get();<BR>
      cout<<"Text2"<<endl;<BR>
      };<BR>
      <BR>
      Vielen Dank trotzdem für deine Hilfe, ich dachte schon es hilft mir<BR>
      eh keiner )<BR><BR>
      mfg<BR>
      Stefa

      Comment

      Working...
      X