Chinaunix首页 | 论坛 | 博客
  • 博客访问: 735259
  • 博文数量: 769
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 4985
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:37
文章分类

全部博文(769)

文章存档

2011年(1)

2008年(768)

我的朋友

分类:

2008-10-15 16:40:18

#include
    #include
    #include
    #include
    #include

    class Console
    {
    public:
    Console()
    {
    hStdOutput = INVALID_HANDLE_VALUE;
    hStdError = INVALID_HANDLE_VALUE;
    }
    bool Open( void )
    {
    hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
    hStdError = GetStdHandle( STD_ERROR_HANDLE );
    return INVALID_HANDLE_VALUE!=hStdOutput && INVALID_HANDLE_VALUE!=hStdError;
    }
    inline bool SetTitle( char* title ) // 设置标题
    {
    return TRUE==SetConsoleTitle(title);
    }
    bool RemoveCursor( void ) // 去处光标
    {
    CONSOLE_CURSOR_INFO cci;
    if( !GetConsoleCursorInfo( hStdOutput, &cci ) ) return false;
    cci.bVisible = false;
    if( !SetConsoleCursorInfo( hStdOutput, &cci ) ) return false;
    if( !GetConsoleCursorInfo( hStdError, &cci ) ) return false;
    cci.bVisible = false;
    if( !SetConsoleCursorInfo( hStdError, &cci ) ) return false;
    return true;
    }
    bool SetWindowRect( short x, short y ) // 设置窗体尺寸
    {
    SMALL_RECT wrt = { 0, 0, x, y };
    if( !SetConsoleWindowInfo( hStdOutput, TRUE, &wrt ) ) return false;
    if( !SetConsoleWindowInfo( hStdError, TRUE, &wrt ) ) return false;
    return true;
    }
    bool SetBufSize( short x, short y ) // 设置缓冲尺寸
    {
    COORD coord = { x, y };
    if( !SetConsoleScreenBufferSize( hStdOutput, coord ) ) return false;
    if( !SetConsoleScreenBufferSize( hStdError, coord ) ) return false;
    return true;
    }

    bool GotoXY( short x, short y ) // 移动光标
    {
    COORD coord = { x, y };
    if( !SetConsoleCursorPosition( hStdOutput, coord ) ) return false;
    if( !SetConsoleCursorPosition( hStdError, coord ) ) return false;
    return true;
    }
    bool SetColor( WORD color ) // 设置前景色/背景色
    {
    if( !SetConsoleTextAttribute( hStdOutput, color ) ) return false;
    if( !SetConsoleTextAttribute( hStdError, color ) ) return false;
    return true;
    }
    bool OutputString( const char* pstr, size_t len=0 ) // 输出字符串
    {
    DWORD n = 0;
    return TRUE==WriteConsole( hStdOutput, pstr, len?len:strlen(pstr), &n, NULL );
    }

    bool OutputStringNoMove( short x, short y, const char* pstr, size_t len=0 ) // 输出字符串
    {
    COORD coord = { x, y };
    DWORD n = 0;
    return TRUE==WriteConsoleOutputCharacter( hStdOutput, pstr, len?len:strlen(pstr), coord, &n );
    }
    private:
    HANDLE hStdOutput;
    HANDLE hStdError;
    };

    const char bg[] =
    "┏━━━━━━━━━━━┓ "
    "┃■■■■■■■■■■■┃ ←↓→ ↑"
    "┃■■■■■■■■■■■┃ Begin "
    "┃■■■■■■■■■■■┃ Voice = Yes"
    "┃■■■■■■■■■■■┃ Sleep "
    "┃■■■■■■■■■■■┃ Quit "
    "┃■■■■■■■■■■■┃ "
    "┃■■■■■■■■■■■┃ "
    "┃■■■■■■■■■■■┃ NEXT "
    "┃■■■■■■■■■■■┃┏━━━━┓"
    "┃■■■■■■■■■■■┃┃    ┃"
    "┃■■■■■■■■■■■┃┃    ┃"
    "┃■■■■■■■■■■■┃┗━━━━┛"
    "┃■■■■■■■■■■■┃ LEVEL "
    "┃■■■■■■■■■■■┃┏━━━━┓"
    "┃■■■■■■■■■■■┃┃ 0┃"
    "┃■■■■■■■■■■■┃┗━━━━┛"
    "┃■■■■■■■■■■■┃ SCORE "
    "┃■■■■■■■■■■■┃┏━━━━┓"
    "┃■■■■■■■■■■■┃┃ 00000┃"
    "┗━━━━━━━━━━━┛┗━━━━┛";

[1]     

【责编:huangchunmei】

--------------------next---------------------

阅读(392) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~