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. Update Edit Box text

Update Edit Box text

Scheduled Pinned Locked Moved C / C++ / MFC
c++beta-testingquestionannouncementcode-review
9 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
    clatten
    wrote on last edited by
    #1

    I'm not much of C++ programmer but am just putting together a very simple Dialog in Visual C++ 6.0. It's one button and two Edit Boxes. From the first I get user input and the second I use for user feedback. To the press button message handler I have added a function that is looping and for each loop I'd like to update the message in the second Edit Box. The code looks something like this: void CAppGUIDlg::OnButton1() { CAppGUIDlg::DoSomething(); } void CAppGUIDlg::DoSomething() { int *string; int max; char *tmpStr = ""; int total = 0; max = atoi(m_editStr1); //Get Edit Box 1 value while (total < max ) { //Do something with value from Edit Box 1 sprintf(tmpStr,"User message %i", total/1024); UpdateData(false); m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2 Sleep(200); UpdateData(false); } } What will happen is that Edit Box 2 will not be updated until the loop is finished. Is there a simple way to update it within every loop?

    D G 2 Replies Last reply
    0
    • C clatten

      I'm not much of C++ programmer but am just putting together a very simple Dialog in Visual C++ 6.0. It's one button and two Edit Boxes. From the first I get user input and the second I use for user feedback. To the press button message handler I have added a function that is looping and for each loop I'd like to update the message in the second Edit Box. The code looks something like this: void CAppGUIDlg::OnButton1() { CAppGUIDlg::DoSomething(); } void CAppGUIDlg::DoSomething() { int *string; int max; char *tmpStr = ""; int total = 0; max = atoi(m_editStr1); //Get Edit Box 1 value while (total < max ) { //Do something with value from Edit Box 1 sprintf(tmpStr,"User message %i", total/1024); UpdateData(false); m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2 Sleep(200); UpdateData(false); } } What will happen is that Edit Box 2 will not be updated until the loop is finished. Is there a simple way to update it within every loop?

      D Offline
      D Offline
      Diddy
      wrote on last edited by
      #2

      Either: Do each thing in a different thread. Or (more simply for this case) Pump messages in your loop. Change your loop to: while (total < max ) { //Do something with value from Edit Box 1 sprintf(tmpStr,"User message %i", total/1024); UpdateData(false); if(!PeekAndPump()) break; m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2 Sleep(200); UpdateData(false); } Then add this function to your class: BOOL PeekAndPump() { MSG dlgMsg; if (::PeekMessage (&dlgMsg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp ()->PumpMessage ()) { ::AfxPostQuitMessage (0); return FALSE; } return TRUE; } LONG lIdle = 0; while (AfxGetApp ()->OnIdle (lIdle++)); return FALSE; }

      C 1 Reply Last reply
      0
      • C clatten

        I'm not much of C++ programmer but am just putting together a very simple Dialog in Visual C++ 6.0. It's one button and two Edit Boxes. From the first I get user input and the second I use for user feedback. To the press button message handler I have added a function that is looping and for each loop I'd like to update the message in the second Edit Box. The code looks something like this: void CAppGUIDlg::OnButton1() { CAppGUIDlg::DoSomething(); } void CAppGUIDlg::DoSomething() { int *string; int max; char *tmpStr = ""; int total = 0; max = atoi(m_editStr1); //Get Edit Box 1 value while (total < max ) { //Do something with value from Edit Box 1 sprintf(tmpStr,"User message %i", total/1024); UpdateData(false); m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2 Sleep(200); UpdateData(false); } } What will happen is that Edit Box 2 will not be updated until the loop is finished. Is there a simple way to update it within every loop?

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        if you want to send a message to an edit box just use SetDlgItemText function and you have only 2 parameters in MFC VC++. gabby

        D 1 Reply Last reply
        0
        • G gamitech

          if you want to send a message to an edit box just use SetDlgItemText function and you have only 2 parameters in MFC VC++. gabby

          D Offline
          D Offline
          Diddy
          wrote on last edited by
          #4

          Wont help. If your looping around in that one function, you can do what you want to the other edit box, it wont redraw until you return from that function and contine to pump messages.

          G 1 Reply Last reply
          0
          • D Diddy

            Either: Do each thing in a different thread. Or (more simply for this case) Pump messages in your loop. Change your loop to: while (total < max ) { //Do something with value from Edit Box 1 sprintf(tmpStr,"User message %i", total/1024); UpdateData(false); if(!PeekAndPump()) break; m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2 Sleep(200); UpdateData(false); } Then add this function to your class: BOOL PeekAndPump() { MSG dlgMsg; if (::PeekMessage (&dlgMsg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp ()->PumpMessage ()) { ::AfxPostQuitMessage (0); return FALSE; } return TRUE; } LONG lIdle = 0; while (AfxGetApp ()->OnIdle (lIdle++)); return FALSE; }

            C Offline
            C Offline
            clatten
            wrote on last edited by
            #5

            Exactly what I was hoping for. Thanksa lot Diddy!

            D 1 Reply Last reply
            0
            • C clatten

              Exactly what I was hoping for. Thanksa lot Diddy!

              D Offline
              D Offline
              Diddy
              wrote on last edited by
              #6

              No problem :)

              1 Reply Last reply
              0
              • D Diddy

                Wont help. If your looping around in that one function, you can do what you want to the other edit box, it wont redraw until you return from that function and contine to pump messages.

                G Offline
                G Offline
                gamitech
                wrote on last edited by
                #7

                I AM pretty sure it works. gabby

                D D 2 Replies Last reply
                0
                • G gamitech

                  I AM pretty sure it works. gabby

                  D Offline
                  D Offline
                  Diddy
                  wrote on last edited by
                  #8

                  Try it - it doesnt. Yes SetDlgItemText changes the text - though really its the Win32 way of doing things. The way he has done it with UpdateData basically calls SetDlgItemText anyway under the hood - just using the DDX/DDV map to work out what to map to what. But just like UpdateData, SetDlgItemText will set the text after the loop has returned. If you are processing a message spinning in a loop then no other messages will come through when you are doing that (specifically, WM_PAINT's) until you return from that loop. Hence, yes u have changed the text in the edit box with SetDlgItemText but the edit box wont redraw until your function returns.

                  1 Reply Last reply
                  0
                  • G gamitech

                    I AM pretty sure it works. gabby

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    By updating the edit control (either by using SetDlgItemText() or UpdateData()) every 200 ms, none of the updates will be seen except for the last one after the loop terminates.


                    "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                    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