Kitchen Timer sugestions for improvements

This is a discussion on Kitchen Timer sugestions for improvements within the Windows Programming forums, part of the Platform Specific Boards category; Kitchen Timer sugestions for improvement. Here is the c file and the exe. delete the word and type the value ...

  1. #1
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Kitchen Timer sugestions for improvements

    Kitchen Timer sugestions for improvement. Here is the c file and the exe. delete the word and type the value then

    hit the start button and it will count up to whatever in seconds. I used the sleep(1) function because a kitchen

    timer does not have to be all that accurate. Some of the menu items do not work yet.

    One thing I want to add is a lap or pause function so that you can take whatever off of the heat let it sit then

    continue heating it later. the button is there but it does not work yet. I have more to do to finish it.

    I want it to be a little better than the kitchen timers you can buy in the store. wind and ding types. I will add a

    playwav() to it. It works as it is now but still not done. any sugestions for improvments?

    no exe invalid file type gulp.
    Attached Files Attached Files
    • File Type: c kt1.c (5.3 KB, 122 views)

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    kryptkat,

    I could take a look at it if you can zip the files up and post a link to the zip. From looking at the source code provided I'd suggest implimenting SetTimer, KillTimer, and handling WM_TIMER messages instead of the sleep function. Otherwise at least use windows Sleep function and get rid of sleep and dos.h.

    More later if you come through with the missing files and are still interested in feedback,
    Brian

  3. #3
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    Meow!

    i had first thought of doing it that way. Then i realized that i would have to set up a timerproc and case wm_timer. then find a way to sit there and wait for the tiimer to expire a second and not let it fall through to the next line of code while that timer is ticking away. then after the second is up then repeat. more lines of code meow! with sleep(1) two lines of code and done. aww simplisticiy of sleep().

    a for loop was out of the question because every computers processor speed is diff. and sleep was already set in seconds no need to figure out how many miliseconds in a second with settimer meow.

    with set timer still need to figure out how to exit when total time is up. if it is set up at the begining for the total time the seconds would not tick in the window so it had to be set for a second so the count would happen. meow.

    i redid the prog with settimer. meow

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Then i realized that i would have to set up a timerproc and case wm_timer. <<

    You need to provide one or the other, not both.

    >> then find a way to sit there and wait for the tiimer to expire a second and not let it fall through to the next line of code while that timer is ticking away. <<

    That's the point of SetTimer. You don't sit there. You return and let your application go back to processing messages. Every interval you will receive a WM_TIMER where you do the appropriate processing.

    The design of Windows means that you can not delay while processing a message. To remain responsive, your message loop must continue processing messages at all times.

    >> and sleep was already set in seconds no need to figure out how many miliseconds in a second with settimer meow. <<

    By definition, there are 1000 milliseconds in a second.

    >> with set timer still need to figure out how to exit when total time is up. <<

    Every time you receive a WM_TIMER event (say once per second), you should check if now - start >= countdown_time.

  5. #5
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    i ment or. in eigher case one would have to decide which would be best to use.

    That's the point of SetTimer. You don't sit there. You return and let your application go back to processing messages. Every interval you will receive a WM_TIMER where you do the appropriate processing.
    it fell through and the count fell through very quicky and did not wait for the timer. then i changed it. but i still see a problem if the message q gets backed up.it would not be a second.

    By definition, there are 1000 milliseconds in a second.
    i knew that. but if i did not then i would have to look it up aka more work.

    useing settimer is still more work than seep. aaand with settimer you may have to call killtimer to get the prog to stop counting when total count is done.

    thank you both for your comments. i did not mean to come off harsh but i just wanted you to realize that settimer is more work than sleep. so which way is better?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,261
    i did not mean to come off harsh but i just wanted you to realize that settimer is more work than sleep. so which way is better?
    SetTimer() is better. The reason is that Sleep() blocks your program's thread, so that it can't do anything else while it's sleeping.

    I made a post in this thread which demonstrates how to use SetTimer().

  7. #7
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    i redid the prog with settimer. meow
    i know how to use settimer meow. nice demo though.

    ok i will bite. hypothetcal if the prog did something else... how would you handle an overloaded backed up message q?

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,261
    i redid the prog with settimer. meow
    Sorry, I missed that

    hypothetcal if the prog did something else... how would you handle an overloaded backed up message q?
    If your program was CPU intensive, and your queue was getting backed up to the point where your timer was too innacurate, then you should change your design so that the intensive code is executed in a different thread than the thread which processes your queue.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 01:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 07:25 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21