繁体   English   中英

C ++ / Win32如何创建Egg-Timer

[英]C++/Win32 How to create an Egg-Timer

嘿,我一直在考虑制作某种计时器,例如煮蛋计时器。 我认为这也是一种更好地使用Win32的好方法。 好吧,到目前为止,这个想法是一个普通的窗口,小而简单,带有一个“开始”和一个“退出”按钮。 如果我单击“开始”按钮,它将启动一个计时器,该计时器可能从5分钟左右开始倒计时,到0时它将停止并发出声音。 现在,我想知道如何才能使窗口实际计数,并在可能的情况下创建进度条。 如果有人可以给我一点帮助,那只是很小的一个东西,这样我就可以工作了。自定义声音,例如倒计时结束声音的.wav或.mp3?

提前非常感谢您:3

使用SetTimer函数启动定期计时器-每次触发时,您都会收到WM_TIMER消息。 在该消息的处理程序中,减少您的计数器,然后使用InvalidateRect导致重新绘制窗口。

在这里,我知道如何制作计时器,这非常简单:

#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;

int main()
{
    system("Color A");
    long long int time;
    cout<<"Enter the amount of time."<<endl;
    cin>>time;//how many seconds you want
    cout<<time<<'\r'<<flush;
    while(time>10)//repeat this until the time in under 10 seconds
    {
        Sleep(800);
        time--;
        Beep(500,200);
        cout<<time<<'\r'<<flush;
    }
    while(time>3)//repeat this until the time in under 3 seconds
    {
        Sleep(500);
        Beep(800,166);
        time--;
        Beep(800,166);
        cout<<time<<'\r'<<flush;
        Beep(800,166);
    }
    while(time>0)//repeat this until the time is up
    {
        Sleep(100);
        Beep(1000,150);
        Beep(1000,150);
        time--;
        Beep(1000,150);
        Beep(1000,150);
        cout<<time<<'\r'<<flush;
        Beep(1000,150);
        Beep(1000,150);
    }
    cout<<"times up!"<<endl;
    return 0;
}

系统("Color *letter or number*"); 更改文本的颜色,Beep( tonetime ); 播放声音。

希望它能起作用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM