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. On Timer

On Timer

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 4 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.
  • C Offline
    C Offline
    Chandrasekharan P
    wrote on last edited by
    #1

    i jus wanted to know how do i show the values in the edit box when i use the timer. this value should get updated every second. till a range. for example till 100. in the edit box it should display from 1 to 100. actually i am using a for loop to iterate te value till 100. but only the last value is printing. i have set the timer lik this OnButton Function: & SetTimer(1,100,NULL); and on the OnTimer function:P CString str1; if (nIDEvent==1) { for(int i=0;i<=100;i++) { str1.Format("%d",i); if(i%2==0) { m_listbox.AddString(str1); m_edit.SetWindowText(str1); } } } i know its a simple mistake. but i am not being able to figure out.

    K G P 3 Replies Last reply
    0
    • C Chandrasekharan P

      i jus wanted to know how do i show the values in the edit box when i use the timer. this value should get updated every second. till a range. for example till 100. in the edit box it should display from 1 to 100. actually i am using a for loop to iterate te value till 100. but only the last value is printing. i have set the timer lik this OnButton Function: & SetTimer(1,100,NULL); and on the OnTimer function:P CString str1; if (nIDEvent==1) { for(int i=0;i<=100;i++) { str1.Format("%d",i); if(i%2==0) { m_listbox.AddString(str1); m_edit.SetWindowText(str1); } } } i know its a simple mistake. but i am not being able to figure out.

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Read what the SetTimer() does. It sets up a timer in ms. And in the handler you run to 100

      Greetings from Germany

      1 Reply Last reply
      0
      • C Chandrasekharan P

        i jus wanted to know how do i show the values in the edit box when i use the timer. this value should get updated every second. till a range. for example till 100. in the edit box it should display from 1 to 100. actually i am using a for loop to iterate te value till 100. but only the last value is printing. i have set the timer lik this OnButton Function: & SetTimer(1,100,NULL); and on the OnTimer function:P CString str1; if (nIDEvent==1) { for(int i=0;i<=100;i++) { str1.Format("%d",i); if(i%2==0) { m_listbox.AddString(str1); m_edit.SetWindowText(str1); } } } i know its a simple mistake. but i am not being able to figure out.

        G Offline
        G Offline
        GauranG Shah
        wrote on last edited by
        #3

        might be the followig code work as u desire. Try it and let me know whether it worked or not. ( i know its in win32 and you are using MFC but i know u can make to use it )

        #define ONE_SEC 1
        int i=0;

        case WM_INITDIALOG:
        SetTimer(hdlg,ONE_SEC,10*100,NULL);

        break;

        case WM_TIMER:
        if (wParam == ONE_SEC)
        {
        SetDlgItemInt(hdlg,IDC_EDIT1,i++,FALSE);
        }
        break;

        [ Screen Capture ][ Tool Tip ][ Muliple Desktops ][Greeting Card ]

        1 Reply Last reply
        0
        • C Chandrasekharan P

          i jus wanted to know how do i show the values in the edit box when i use the timer. this value should get updated every second. till a range. for example till 100. in the edit box it should display from 1 to 100. actually i am using a for loop to iterate te value till 100. but only the last value is printing. i have set the timer lik this OnButton Function: & SetTimer(1,100,NULL); and on the OnTimer function:P CString str1; if (nIDEvent==1) { for(int i=0;i<=100;i++) { str1.Format("%d",i); if(i%2==0) { m_listbox.AddString(str1); m_edit.SetWindowText(str1); } } } i know its a simple mistake. but i am not being able to figure out.

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

          You have not specified what is not working as expected, so please tell us what you want to do! What do you need a timer for this?

          C 1 Reply Last reply
          0
          • P pierre_ribery

            You have not specified what is not working as expected, so please tell us what you want to do! What do you need a timer for this?

            C Offline
            C Offline
            Chandrasekharan P
            wrote on last edited by
            #5

            i dont know if there is another way other than timer to increment the value in a edit box every sec or millisecond. the problem is it only shows the last number that is 100. i have to show it from 1 to 100.

            P 1 Reply Last reply
            0
            • C Chandrasekharan P

              i dont know if there is another way other than timer to increment the value in a edit box every sec or millisecond. the problem is it only shows the last number that is 100. i have to show it from 1 to 100.

              P Offline
              P Offline
              pierre_ribery
              wrote on last edited by
              #6

              ok, if I understand you correc, you want to increment the value of an edit box every 1 second, starting from 0 going to 100. If that is the case, then a timer is the way to go. Your timer needs to be set up for 1000ms(1sec). You have set it up for 100ms only. SetTimer(1,1000,NULL); Now create a member variable for your edit control of type "value" and set its datatype to int. Lets call it "value". In OnTimer: if (nIDEvent==1) { if(value < 100) { value++; UpdateData(FALSE); } }

              C 1 Reply Last reply
              0
              • P pierre_ribery

                ok, if I understand you correc, you want to increment the value of an edit box every 1 second, starting from 0 going to 100. If that is the case, then a timer is the way to go. Your timer needs to be set up for 1000ms(1sec). You have set it up for 100ms only. SetTimer(1,1000,NULL); Now create a member variable for your edit control of type "value" and set its datatype to int. Lets call it "value". In OnTimer: if (nIDEvent==1) { if(value < 100) { value++; UpdateData(FALSE); } }

                C Offline
                C Offline
                Chandrasekharan P
                wrote on last edited by
                #7

                thanks a lot dude..

                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