| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 17494 人关注过本帖, 1 人收藏
标题:怎么样用c语言写一个倒计时程序
只看楼主 加入收藏
heroinearth
Rank: 10Rank: 10Rank: 10
来 自:云南曲靖
等 级:青峰侠
帖 子:430
专家分:1506
注 册:2011-10-24
收藏
得分:0 
回复 9楼 laznrbfe
tc2.0    !!!!!!!
2011-11-03 22:52
wang155423
Rank: 6Rank: 6
等 级:侠之大者
帖 子:216
专家分:408
注 册:2011-9-4
收藏
得分:0 
好,学到了
2011-11-03 22:54
cstudent
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-11-2
收藏
得分:0 
回复 8楼 laznrbfe
可以用
2011-11-03 23:01
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
程序:
test_Time.exe.zip (15 KB)

无压缩可执行文件,下载后将扩展名改回.exe运行。运行环境:.NETFramework 4.0

执行画面:


程序代码:
 // 系统时间测试程序

#include <Windows.h>
#include <conio.h>
#include <Screen.h>

// 全局变量
Screen screen;

// 函数声明
VOID ShowDigit(const WCHAR digit, COORD location);

// 程序主入口
VOID wmain(VOID)
{
    screen.SetTitle(L"系统时间测试程序");
    screen.SetTextAttribute(FOREGROUND_WHITE | BACKGROUND_BLUE).Cls();
    screen.SetCursorVisible(false);

    screen.MoveCursor(0, screen.GetRows() - 1).WriteText(L"====按Esc键停止====");
    while (!(_kbhit() && (screen.ReadKey() == screen.K_ESC)))
    {
        static WORD second(-1);
        SYSTEMTIME st;
        GetLocalTime(&st);
        if (st.wSecond != second)
        {
            COORD location = {5, 2};
            WCHAR buffer[50];
            swprintf_s(buffer, L"%4d-%02d-%02d  %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
            for (size_t i = 0; i < wcslen(buffer); ++i)
            {
                ShowDigit(buffer[i], location);
                location.X += 3;
            }
            second = st.wSecond;
        }
    }

    screen.SetCursorVisible(true);
}

// 显示LED数字
VOID ShowDigit(const WCHAR digit, COORD location)
{
    const WORD attr(screen.GetTextAttribute());
    const WCHAR character = L' ';

    switch (digit)
    {
    case '-':
        screen.MoveCursor(location).SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case ':':
        screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·');
        ++location.Y;
        screen.MoveCursor(location).SetTextAttribute(attr).WriteText(L'·');
        break;
    case '0':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '1':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        screen.SetTextAttribute(attr).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        screen.SetTextAttribute(attr).WriteText(character);
        break;
    case '2':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '3':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '4':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '5':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '6':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '7':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL).WriteText(character);
        break;
    case '8':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    case '9':
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        ++location.Y;
        screen.MoveCursor(location);
        screen.SetTextAttribute(attr | COMMON_LVB_UNDERSCORE).WriteText(character);
        screen.SetTextAttribute(attr | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_UNDERSCORE).WriteText(character);
        break;
    }

    screen.SetTextAttribute(attr);
}


[ 本帖最后由 TonyDeng 于 2011-11-4 01:29 编辑 ]

授人以渔,不授人以鱼。
2011-11-04 01:01
我是特种兵
Rank: 1
等 级:新手上路
帖 子:23
专家分:3
注 册:2011-8-30
收藏
得分:0 
哈!学会了
2011-11-04 16:52
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
学会了?

授人以渔,不授人以鱼。
2011-11-04 17:13
快速回复:怎么样用c语言写一个倒计时程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041722 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved