Thread: Pause for less than a second

  1. #1
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Question Pause for less than a second

    Ok guys, feed me with knowledge. I've created these cool '3D' buttons in C and they behave pretty much like those in Windows. They user highlights them, hits ENTER and the button depresses.

    That works fine.

    However, because the code is executed so fast, the depress action is barely visible, except on a really slow computer. The best I could do was to make it sleep for 1 second in between it being pressed down and popping back up to its original position.

    Sleeping for 1 second each time the button is depressed becomes pretty unnerving very quickly. So here's my question:

    How do you get C to sleep or Pause for less than a second? Like 0.7 seconds or something like that? I've used other programming languages that allow you to sleep in milliseconds and that is fine. But there seems to be no standard way of doing it in C.

    I'd appreciate any assistance. Thanks.
    Excuse me, while I water my money tree.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    The API function - Sleep() takes a param for the number of miliseconds........as long as the value is less than 1000....you should get less than a second's pause......

    The func isnt too accurate, but should be ok for this

  3. #3
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Sleep or sleep?

    Is that Sleep? (capital S) or did you mean it as an extension of sleep?
    Excuse me, while I water my money tree.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Sleep is a Winapi function......you can also use sleep()........but it will require that you #include an extra lib

  5. #5
    Registered User johnnyd's Avatar
    Join Date
    Mar 2002
    Posts
    70

    Lightbulb It works

    Thanks man. It works beautifully.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can also use 'select' with null values and a time in milliseconds.

    And just like all your other implementations, this too is OS specific.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >And just like all your other implementations, this too is OS specific.
    Let's have some fun with standard functions. This should work across all platforms.
    Code:
    void sleep ( long m )
    {
      clock_t limit, cl = clock();
      limit = cl + m;
      while ( limit > cl )
        cl = clock();
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  3. Dev-C++ Compile and Run with Pause
    By xmltorrent in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2006, 11:55 PM
  4. pause program at console
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 03-27-2003, 12:36 AM
  5. Pause function ???
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 09-02-2001, 08:22 PM