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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. UpdateData won't cut it

UpdateData won't cut it

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
5 Posts 5 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am designing a program that acts as a countdown timer. However, because the function called from the GUI doesn't stop running until the time has decremented to zero, the GUI can't show how much time is remaining. Here's the source: void CtimerDlg::OnBnClickedStart() { int currentTime = 0; int timeInSeconds = 0; char min[5] = ""; char sec[5] = ""; char setTime[12] = ""; UpdateData(true); currentTime = time(NULL); minutesRemaining = setMinutes; secondsRemaining = setSeconds; sprintf(min, "%i", setMinutes); sprintf(sec, "%i", setSeconds); strcpy(setTime, min); strcat(setTime, " : "); strcat(setTime, sec); startTime = setTime; timeInSeconds = ((setMinutes * 60) + setSeconds); while(timeInSeconds != 0) { if(currentTime != time(NULL)) { if(secondsRemaining == 0) secondsRemaining = 60; timeInSeconds--; secondsRemaining--; sprintf(sec, "%i", secondsRemaining); secLeft.SetWindowText(sec); currentTime = time(NULL); } if(secondsRemaining == 59) { minutesRemaining--; sprintf(min, "%i", minutesRemaining); minLeft.SetWindowText(min); } } UpdateData(false); } // end code How can I get the GUI to update while the progam is executing? -Thanks

    E B V RaviBeeR 4 Replies Last reply
    0
    • L Lost User

      I am designing a program that acts as a countdown timer. However, because the function called from the GUI doesn't stop running until the time has decremented to zero, the GUI can't show how much time is remaining. Here's the source: void CtimerDlg::OnBnClickedStart() { int currentTime = 0; int timeInSeconds = 0; char min[5] = ""; char sec[5] = ""; char setTime[12] = ""; UpdateData(true); currentTime = time(NULL); minutesRemaining = setMinutes; secondsRemaining = setSeconds; sprintf(min, "%i", setMinutes); sprintf(sec, "%i", setSeconds); strcpy(setTime, min); strcat(setTime, " : "); strcat(setTime, sec); startTime = setTime; timeInSeconds = ((setMinutes * 60) + setSeconds); while(timeInSeconds != 0) { if(currentTime != time(NULL)) { if(secondsRemaining == 0) secondsRemaining = 60; timeInSeconds--; secondsRemaining--; sprintf(sec, "%i", secondsRemaining); secLeft.SetWindowText(sec); currentTime = time(NULL); } if(secondsRemaining == 59) { minutesRemaining--; sprintf(min, "%i", minutesRemaining); minLeft.SetWindowText(min); } } UpdateData(false); } // end code How can I get the GUI to update while the progam is executing? -Thanks

      E Offline
      E Offline
      electronicman_x
      wrote on last edited by
      #2

      Maybe you should spawn a thread to countdown? Jeff Rothenberg Project Engineer Vector CANtech, Inc.

      1 Reply Last reply
      0
      • L Lost User

        I am designing a program that acts as a countdown timer. However, because the function called from the GUI doesn't stop running until the time has decremented to zero, the GUI can't show how much time is remaining. Here's the source: void CtimerDlg::OnBnClickedStart() { int currentTime = 0; int timeInSeconds = 0; char min[5] = ""; char sec[5] = ""; char setTime[12] = ""; UpdateData(true); currentTime = time(NULL); minutesRemaining = setMinutes; secondsRemaining = setSeconds; sprintf(min, "%i", setMinutes); sprintf(sec, "%i", setSeconds); strcpy(setTime, min); strcat(setTime, " : "); strcat(setTime, sec); startTime = setTime; timeInSeconds = ((setMinutes * 60) + setSeconds); while(timeInSeconds != 0) { if(currentTime != time(NULL)) { if(secondsRemaining == 0) secondsRemaining = 60; timeInSeconds--; secondsRemaining--; sprintf(sec, "%i", secondsRemaining); secLeft.SetWindowText(sec); currentTime = time(NULL); } if(secondsRemaining == 59) { minutesRemaining--; sprintf(min, "%i", minutesRemaining); minLeft.SetWindowText(min); } } UpdateData(false); } // end code How can I get the GUI to update while the progam is executing? -Thanks

        B Offline
        B Offline
        benjymous
        wrote on last edited by
        #3

        I'd use a timer instead, then you can have a handler function that gets called every second, which will allow normal GUI operations to continue -- Help me! I'm turning into a grapefruit!

        1 Reply Last reply
        0
        • L Lost User

          I am designing a program that acts as a countdown timer. However, because the function called from the GUI doesn't stop running until the time has decremented to zero, the GUI can't show how much time is remaining. Here's the source: void CtimerDlg::OnBnClickedStart() { int currentTime = 0; int timeInSeconds = 0; char min[5] = ""; char sec[5] = ""; char setTime[12] = ""; UpdateData(true); currentTime = time(NULL); minutesRemaining = setMinutes; secondsRemaining = setSeconds; sprintf(min, "%i", setMinutes); sprintf(sec, "%i", setSeconds); strcpy(setTime, min); strcat(setTime, " : "); strcat(setTime, sec); startTime = setTime; timeInSeconds = ((setMinutes * 60) + setSeconds); while(timeInSeconds != 0) { if(currentTime != time(NULL)) { if(secondsRemaining == 0) secondsRemaining = 60; timeInSeconds--; secondsRemaining--; sprintf(sec, "%i", secondsRemaining); secLeft.SetWindowText(sec); currentTime = time(NULL); } if(secondsRemaining == 59) { minutesRemaining--; sprintf(min, "%i", minutesRemaining); minLeft.SetWindowText(min); } } UpdateData(false); } // end code How can I get the GUI to update while the progam is executing? -Thanks

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          There are several soltuions. One solutin is a timer queue timer that will call a callback after upon tick. Kuphryn

          1 Reply Last reply
          0
          • L Lost User

            I am designing a program that acts as a countdown timer. However, because the function called from the GUI doesn't stop running until the time has decremented to zero, the GUI can't show how much time is remaining. Here's the source: void CtimerDlg::OnBnClickedStart() { int currentTime = 0; int timeInSeconds = 0; char min[5] = ""; char sec[5] = ""; char setTime[12] = ""; UpdateData(true); currentTime = time(NULL); minutesRemaining = setMinutes; secondsRemaining = setSeconds; sprintf(min, "%i", setMinutes); sprintf(sec, "%i", setSeconds); strcpy(setTime, min); strcat(setTime, " : "); strcat(setTime, sec); startTime = setTime; timeInSeconds = ((setMinutes * 60) + setSeconds); while(timeInSeconds != 0) { if(currentTime != time(NULL)) { if(secondsRemaining == 0) secondsRemaining = 60; timeInSeconds--; secondsRemaining--; sprintf(sec, "%i", secondsRemaining); secLeft.SetWindowText(sec); currentTime = time(NULL); } if(secondsRemaining == 59) { minutesRemaining--; sprintf(min, "%i", minutesRemaining); minLeft.SetWindowText(min); } } UpdateData(false); } // end code How can I get the GUI to update while the progam is executing? -Thanks

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            kvan07 wrote: How can I get the GUI to update while the progam is executing? Pump the message queue. See my TaskTimer[^] article for instructions. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            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