正文

电子表2006-04-19 11:03:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bruceteen/12743.html

分享到:

#define _CRT_SECURE_NO_DEPRECATE // 仅VC++2005才需要这个宏
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cassert>
#include <conio.h>
#include <windows.h>
using namespace std;
#pragma comment( lib, "Winmm" ) // 如果是dev-cpp, 手工在连接器中加入 libwinmm.a 文件路径,比如 C:/Dev-Cpp/lib/libwinmm.a

void __stdcall timecallback( UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2 )
{
    time_t t = time( 0 );
    tm* lt = localtime( &t );
    SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), *(COORD*)dwUser );
    cout << setw(4) << setfill('0') << right << ( 1900 + lt->tm_year ) << '/'
         << setw(2) << setfill('0') << right << ( 1 + lt->tm_mon )     << '/'
         << setw(2) << setfill('0') << right << ( lt->tm_mday )        << ' '
         << setw(2) << setfill('0') << right << ( lt->tm_hour )        << ':'
         << setw(2) << setfill('0') << right << ( lt->tm_min )         << ':'
         << setw(2) << setfill('0') << right << ( lt->tm_sec )         << endl;
}

int main( void )
{
    cout << "按任意键退出..." << endl;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &csbi );
    WORD wAttrnew = csbi.wAttributes|FOREGROUND_INTENSITY;
    SetConsoleTextAttribute( ::GetStdHandle(STD_OUTPUT_HANDLE), wAttrnew );
    CONSOLE_CURSOR_INFO cci;
    GetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &cci );
    BOOL bVisibleold = cci.bVisible;
    cci.bVisible = FALSE;
    SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &cci );
    timecallback( 0, 0, (DWORD_PTR)&csbi.dwCursorPosition, 0, 0 );
    MMRESULT id = timeSetEvent( 1000, 0, &timecallback, (DWORD_PTR)&csbi.dwCursorPosition, TIME_PERIODIC|TIME_CALLBACK_FUNCTION );
    assert( id );
    _getch();
    timeKillEvent( id );
    cci.bVisible = bVisibleold;
    SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &cci );
    SetConsoleTextAttribute( ::GetStdHandle(STD_OUTPUT_HANDLE), csbi.wAttributes );

    return 0;
}

阅读(3224) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册