Countdown timer that plays music at the end.

As the title suggests I'm trying to make a countdown timer that will play a music file at the end. I'm new to C/C++ and truly have no idea what to do, I've looked around on this site and found the basic "countdown started, 10 to 1 then fire" code but I was wondering if there was anyway to modify that to use minutes and play a music file at the end. Thank you for any constructive replies ahead of time.
if you don't have to do milliseconds or anything, you could just use time() to get the seconds and after a given amount of seconds do what you want.
Is there any way for it to transition from like 5 minutes down to like 1 minute then from there go into seconds or does it have to stay one unit of time?
This is the code I use to output minutes and seconds within a timer loop. This routine is in my main dialog callback procedure. It counts down from a value set in EntryTimeRemaining to 0. When 0 it outputs various messages. All you would need to do is call your music routine instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    switch(uMsg)
    {

    case WM_TIMER:
    {
        EntryTimeRemaining -= 1;
        sprintf(ConvertedTime,"%d:%.2d",(EntryTimeRemaining / 60),(EntryTimeRemaining % 60));
        if(EntryTimeRemaining >= 0)
        {
            SetDlgItemText(hwndDlg,TimeValue,ConvertedTime);
        }

        if (EntryTimeRemaining == 0)
        {
            KillTimer(hwndDlg, Timer1);
            EnableWindow(GetDlgItem(hwndDlg,WordEntry),false);
            EnableWindow( GetDlgItem(hwndDlg, WordSubmit), false);
            sprintf(NoOfWords,"%d",WordCount);
            sprintf(cPossibles,"%d",Possibles);
            for(int h=0; h<50; h++) MessageText2[h] = '\0';
            strcat(MessageText2," You got ");
            strcat(MessageText2,NoOfWords);
            strcat(MessageText2," out of ");
            strcat(MessageText2,cPossibles);
            MessageBox(0,MessageText2,"Congratulations",0);
            CheckHighScore();
        }
    }
}


This is where I set the time in seconds and then start the timer. The 1000 is the number of milliseconds between ticks (therefore 1 second).

1
2
            EntryTimeRemaining = 180;
            SetTimer(hwndDlg,Timer1,1000,(TIMERPROC)NULL);


Hope this helps.

TonyM
Topic archived. No new replies allowed.