Use the SetTimer
function to start a periodic timer - each time it fires you'll receive a WM_TIMER
message. In the handler for that message, decrement your counter and use InvalidateRect
to cause the window to be repainted.
C++/Win32 How to create an Egg-Timer
Question
Heey, i've been thinking about making some sort of timer, like an egg timer. I think it's a good way to get more used to win32 aswell. Well, the idea so far is a normal window, small and simple, with a "Start" and an "Exit" button. If i were to click at the "Start" button, it would start a timer which would countdown from maybe like 5 minutes or so and when it reaches 0, it stops and make a sound. Now, i wonder how i would be able to make so that the window actually counts, and if possible, create a progressbar. If someone could give me a little help, just something small so i have something to work with would be really nice :) I've looked around on Google and timers seems a little strange to be honest :/ Also, is it possible to add Custom sounds, like a .wav or .mp3 for the countdown end sound?
Thank you so much in advance :3
No correct solution
OTHER TIPS
Here I know how to make a timer, it is very easy:
#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;
}
The system("Color *letter or number*");
changes the color of the text, the Beep(tone, time); plays a sound.
Hope it works!