Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to add a delay in program

how to add a delay in program

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
7 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mr2003
    wrote on last edited by
    #1

    Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

    N M P H L 5 Replies Last reply
    0
    • M mr2003

      Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      Sleep() - but then people may think you program is buggy or broken.:( Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

      M 1 Reply Last reply
      0
      • M mr2003

        Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

        M Offline
        M Offline
        Marissa182
        wrote on last edited by
        #3

        maybe you want to use SetTimer SetTimer(TIMER_ID, time); Then just set up a message handler to check for TIMER_ID and do what you want in that message i think there are a few samples somewhere on this site :P

        1 Reply Last reply
        0
        • M mr2003

          Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

          P Offline
          P Offline
          parths
          wrote on last edited by
          #4

          1. Sleep, but it prevents the program from responding to any other event during the Sleep interval. 2. CreateEvent to create a dummy event, and then WaitForSingleObject "It was when I found out I could make mistakes that I knew I was on to something." -Ornette Coleman

          1 Reply Last reply
          0
          • M mr2003

            Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

            H Offline
            H Offline
            HPSI
            wrote on last edited by
            #5

            ////////////////////////////////////////////////////////////////////////////////
            // NAME
            // Delay -- pause for N milliseconds
            //
            // SYNOPSIS
            // void Delay(DWORD dwMsecs, BOOL bBlocking)
            //
            // DESCRIPTION
            // Delay pauses for the number of milliseconds specified by dwMsecs.
            // If bBlocking is FALSE, messages in the message queue will
            // be processed. If bBlocking is TRUE, the message queue will
            // not be processed until the delay period is expired.
            //
            // RETURN VALUE
            // None.
            //
            ////////////////////////////////////////////////////////////////////////////////
            void Delay(DWORD dwMsecs, BOOL bBlocking)
            {
            DWORD dwStrtmsecs, dwCurmsecs;

            dwStrtmsecs = dwCurmsecs = ::GetTickCount();
            
            do 
            {
                if (!bBlocking)
                {
                    MSG msg;
                    if (::PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE)) 
                    {
                        ::TranslateMessage(&msg);
                        ::DispatchMessage(&msg);
                    }
                }
            
                dwCurmsecs = ::GetTickCount();
            
                // check for timer overflow condition
                if (dwCurmsecs < dwStrtmsecs)
                    dwStrtmsecs = dwCurmsecs;
            
            } while ((dwCurmsecs < (dwMsecs + dwStrtmsecs)));
            

            }

            HPS HwndSpy - GUI developer's aid to visually locate and inspect windows. For the month of August only, use coupon code CP-81239 for 30% off.

            1 Reply Last reply
            0
            • M mr2003

              Hi, I would like to know how to add a delay of say 1sec in my MDI program !!! Ehsan Behboudi

              L Offline
              L Offline
              l a u r e n
              wrote on last edited by
              #6

              im assuming this is for startup reasons? what i do is after initialising all i need to simply send urself a message that "starts" the main app running hope i got the right angle here :)


              "there is no spoon"
              biz stuff   about me

              1 Reply Last reply
              0
              • N Neville Franks

                Sleep() - but then people may think you program is buggy or broken.:( Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

                M Offline
                M Offline
                Maxwell Chen
                wrote on last edited by
                #7

                :-D BuggyMax

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups