zoukankan      html  css  js  c++  java
  • [摘录]console 清屏

    #include <windows.h>
    
    void cls( HANDLE hConsole )
    {
       COORD coordScreen = { 0, 0 };    // home for the cursor 
       DWORD cCharsWritten;
       CONSOLE_SCREEN_BUFFER_INFO csbi; 
       DWORD dwConSize;
    
    // Get the number of character cells in the current buffer. 
    
       if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
       {
          return;
       }
    
       dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    
       // Fill the entire screen with blanks.
    
       if( !FillConsoleOutputCharacter( hConsole,        // Handle to console screen buffer 
                                        (TCHAR) ' ',     // Character to write to the buffer
                                        dwConSize,       // Number of cells to write 
                                        coordScreen,     // Coordinates of first cell 
                                        &cCharsWritten ))// Receive number of characters written
       {
          return;
       }
    
       // Get the current text attribute.
    
       if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
       {
          return;
       }
    
       // Set the buffer's attributes accordingly.
    
       if( !FillConsoleOutputAttribute( hConsole,         // Handle to console screen buffer 
                                        csbi.wAttributes, // Character attributes to use
                                        dwConSize,        // Number of cells to set attribute 
                                        coordScreen,      // Coordinates of first cell 
                                        &cCharsWritten )) // Receive number of characters written
       {
          return;
       }
    
       // Put the cursor at its home coordinates.
    
       SetConsoleCursorPosition( hConsole, coordScreen );
    }
    
    int main( void )
    {
        HANDLE hStdout;
    
        hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    
        cls(hStdout);
        
        return 0;
    }
    
    -------------------------------
    void ClearScreen ();
    
    HANDLE  hConsoleOut;        /* Handle to the console */
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;   /* Console information */
    
    int main(int argc, char* argv[])
    {
        hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
        GetConsoleScreenBufferInfo( hConsoleOut, &csbiInfo );
        ClearScreen();
        return 0;
    }
    
    void ClearScreen ()
    {
        DWORD    dummy;
        COORD    Home = { 0, 0 };
        FillConsoleOutputCharacter (hConsoleOut, ' ', csbiInfo.dwSize.X * csbiIn
    fo.dwSize.Y, Home, &dummy );
        SetConsoleCursorPosition (hConsoleOut, Home);
    }
    
  • 相关阅读:
    Android实战开发租赁管理软件(适配UI,数据的存储,多线程下载)课程分享
    随 机 数 算 法
    java 状态模式 解说演示样例代码
    数据挖掘 决策树算法 ID3 通俗演绎
    经常使用表单数据的验证方法
    编程基本功训练:流程图画法及练�
    log4net使用具体解释
    妄想性仮想人格障害 新手教程 +改动器
    使用VS插件在VS2012/2013上编辑和调试Quick-Cocos2d-x的Lua代码
    经典回忆Effective C++ 1
  • 原文地址:https://www.cnblogs.com/mathzzz/p/2845044.html
Copyright © 2011-2022 走看看