我想用GetSystemtime();得到系统时间并用TEXTOUT();显示出来要一直更新时间,就好像桌面右下角的时钟一样,那位高手能给我代码啊

解决方案 »

  1.   


    设定一个 1 秒的定时器即可:
    ::SetTimer(...);
      

  2.   

    http://www.codeproject.com/KB/dialog/YetAnotherClock.aspx
    我年前帮别人做的
      

  3.   

    得到当前时间不要使用GetSystemTime,这个函数是获取伦敦洛林威治时间的,要使用GetLocalTime,以下是数字时钟的代码:
    #pragma comment(lib,"WINMM.lib")
    #include "mmsystem.h"
    void DrawDigit(HDC hDC,int number)
    {
    static BOOL fSegment[10][7]={ 1,1,1,0,1,1,1,
                              0,0,1,0,0,1,0,
      1,0,1,1,1,0,6,
      1,0,1,1,0,1,1,
      0,1,1,1,0,1,0,
      1,1,0,1,0,1,1,
      1,1,0,1,1,1,1,
      1,1,1,0,0,1,0,
      1,1,1,1,1,1,1,
      1,1,1,1,0,1,1
                                };
    static POINT pCoordinate[7][6]={
                                          7,6,11,2,31,2,35,6,31,10,11,10,
      6,7,10,11,10,31,6,35,2,31,2,11,
      36,7,40,11,40,31,36,35,32,31,32,11,
      7,36,11,32,31,32,35,36,31,40,11,40,
      6,37,10,41,10,61,6,65,2,61,2,41,
      36,37,40,41,40,61,36,65,32,61,32,41,
      7,66,11,62,31,62,35,66,31,70,11,70
                                   };
    for(int i=0;i<7;++i)
    {
    if(fSegment[number][i])
    Polygon(hDC,pCoordinate[i],6);
    }
    }
    void DrawTwoDigits(HDC hDC,int number,BOOL bSupress)
    {
        if(!bSupress||number/10!=0)
    DrawDigit(hDC,number/10); OffsetWindowOrgEx(hDC,-42,0,NULL); DrawDigit(hDC,number%10); OffsetWindowOrgEx(hDC,-42,0,NULL);
    }void DrawColon(HDC hdc)
    {
    static POINT ptColon[2][4]={
                               2,21,6,17,10,21,6,25,
       2,51,6,47,10,51,6,55
                               };
    Polygon(hdc,ptColon[0],4);
    Polygon(hdc,ptColon[1],4);
    OffsetWindowOrgEx(hdc,-12,0,NULL);
    }void DrawTime(HDC hDC,BOOL fb24Hour,BOOL bSuppress)
    {
        SYSTEMTIME sysTime;
    GetLocalTime(&sysTime); if(fb24Hour)
    {
    DrawTwoDigits(hDC,sysTime.wHour,bSuppress);
    }
    else
    {
    DrawTwoDigits(hDC,sysTime.wHour%12 ?sysTime.wHour:12,bSuppress);
    }
    DrawColon(hDC);
    DrawTwoDigits(hDC,sysTime.wMinute,FALSE);
    DrawColon(hDC);
    DrawTwoDigits(hDC,sysTime.wSecond,FALSE);}void GetTimeInformation(BOOL& fB24Hour,BOOL& fSuppress,TCHAR* szHourFormat,TCHAR* szLZero)
    {
    GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_ITIME,szHourFormat,3);
    GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_ILZERO,szLZero,3);
    fB24Hour=(szHourFormat[0]==_T('1')?1:0);
    fSuppress=(szLZero[0]==_T('0')?1:0);
    }
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
        static HBRUSH hRedBrush;
        TCHAR szHourFormat[3];
    TCHAR szLZero[3];
    static BOOL fB24Hour;
    static BOOL fSuppress;
    static int cxClient,cyClient;
        RECT rect;
    switch (message)
    {
    case WM_CREATE:

    GetTimeInformation(fB24Hour,fSuppress,szHourFormat,szLZero);
    hRedBrush=CreateSolidBrush(RGB(255,0,0));
    SetTimer(hWnd,IDC_TIMER,1000,NULL);
    break;
    case WM_SETTINGCHANGE:
    GetTimeInformation(fB24Hour,fSuppress,szHourFormat,szLZero);
    InvalidateRect(hWnd,NULL,TRUE);
    break;
    case WM_SIZE:
            cxClient=LOWORD(lParam);
    cyClient=HIWORD(lParam);
    break;

    case WM_TIMER:

    rect.left=0;
    rect.top=cyClient/3-20;
    rect.bottom=2*cyClient/3+20;
    rect.right=cxClient;
    PlaySound(_T("C:\\WINDOWS\\Media\\ding.wav"),NULL,SND_ASYNC|SND_FILENAME);
    InvalidateRect(hWnd,&rect,TRUE);
    break;

    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps); SetMapMode(hdc,MM_ISOTROPIC);
    SetWindowExtEx(hdc,276,72,NULL);
    SetViewportExtEx(hdc,cxClient,cyClient,NULL);
    SetWindowOrgEx(hdc,138,36,NULL); SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);

    SelectObject(hdc,GetStockObject(NULL_PEN));
    SelectObject(hdc,hRedBrush);
    DrawTime(hdc,fB24Hour,fSuppress);
    // TODO: 在此添加任意绘图代码...
    EndPaint(hWnd, &ps);
    break;
    case WM_DESTROY:
    KillTimer(hWnd,IDC_TIMER);
    DeleteObject(hRedBrush);
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
    }