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. Problems with updating edit control

Problems with updating edit control

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsdebugginghelpquestion
5 Posts 2 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.
  • J Offline
    J Offline
    Janine
    wrote on last edited by
    #1

    Hello, I have a problem with an edit control. It doesn't get updated until I show a MessageBox. I have a variable attached to the edit control called m_szText. From outside view class I call a function

    void MyView::AddText(CString szNewText)
    {
    m_szText += szNewText;

    if ( UpdateData(FALSE) )
    	std::cout << "updated" << std::endl;
    else
    	std::cout << "not updated" << std::endl;
    

    }

    As those couts go to a debug console, I get to know, if updating has succeeded or failed. But the result is - no text in the edit control and debug window claims that updating succeeded. I checked with a small application, that normally this should work. Where should I continue searching for a mistake?? -Janetta

    D 1 Reply Last reply
    0
    • J Janine

      Hello, I have a problem with an edit control. It doesn't get updated until I show a MessageBox. I have a variable attached to the edit control called m_szText. From outside view class I call a function

      void MyView::AddText(CString szNewText)
      {
      m_szText += szNewText;

      if ( UpdateData(FALSE) )
      	std::cout << "updated" << std::endl;
      else
      	std::cout << "not updated" << std::endl;
      

      }

      As those couts go to a debug console, I get to know, if updating has succeeded or failed. But the result is - no text in the edit control and debug window claims that updating succeeded. I checked with a small application, that normally this should work. Where should I continue searching for a mistake?? -Janetta

      D Offline
      D Offline
      Daniel Lohmann
      wrote on last edited by
      #2

      Are you calling your AddText function in a lenghtly operation, that is initiated from within the same dialog or another modal dialog of the same thread? The edit box has no chance to display it's changed content until windows message processing occurs. -- Daniel Lohmann http://www.losoft.de

      J 1 Reply Last reply
      0
      • D Daniel Lohmann

        Are you calling your AddText function in a lenghtly operation, that is initiated from within the same dialog or another modal dialog of the same thread? The edit box has no chance to display it's changed content until windows message processing occurs. -- Daniel Lohmann http://www.losoft.de

        J Offline
        J Offline
        Janine
        wrote on last edited by
        #3

        Daniel Lohmann wrote: Are you calling your AddText function in a lenghtly operation, that is initiated from within the same dialog or another modal dialog of the same thread? I use SDI and CFormView. First I have an OnButton function in the view that calls a function in the Doc. Doc calls another function in another file (written in C) and that calls another function in another file that calls AddText. I hope I answered the question you asked. And I know it doesn't sound like a very good structure... I guess I could use your CEditLog in here, but this is so small thing that adding a couple of classes because of this seems too much. Daniel Lohmann wrote: The edit box has no chance to display it's changed content until windows message processing occurs. So should I add windows message handlers OnUpdateEdit and OnChangeEdit for my edit control and call those from AddText? And if so, what should I do in those functions? -Janetta

        D 1 Reply Last reply
        0
        • J Janine

          Daniel Lohmann wrote: Are you calling your AddText function in a lenghtly operation, that is initiated from within the same dialog or another modal dialog of the same thread? I use SDI and CFormView. First I have an OnButton function in the view that calls a function in the Doc. Doc calls another function in another file (written in C) and that calls another function in another file that calls AddText. I hope I answered the question you asked. And I know it doesn't sound like a very good structure... I guess I could use your CEditLog in here, but this is so small thing that adding a couple of classes because of this seems too much. Daniel Lohmann wrote: The edit box has no chance to display it's changed content until windows message processing occurs. So should I add windows message handlers OnUpdateEdit and OnChangeEdit for my edit control and call those from AddText? And if so, what should I do in those functions? -Janetta

          D Offline
          D Offline
          Daniel Lohmann
          wrote on last edited by
          #4

          Janetta wrote: use SDI and CFormView. First I have an OnButton function in the view that calls a function in the Doc. Doc calls another function in another file (written in C) and that calls another function in another file that calls AddText. I hope I answered the question you asked. And I know it doesn't sound like a very good structure... Yep, this sounds that there is no messange processing during perfoming a lengthy operation. Unless the thead returns from the OnButton function, no message processing occurs. You have, in prinicple, two possibilities:

          1. Perform the lenghty operation in it's own thread. In this case I recommend using CEditLog, because it is proven to be thread safe.

          2. Add some code to the end of your AddText() function that ensures all outstanding messages are processed. It's quite a long time ago I did this last, but AFAIR the following code should do it (taken with slight modifications from MSDN, do a search for "Idle Loop Processing":

            MSG msg;
            while ( ::PeekMessage( &msg, NULL, 0, 0, PM\_NOREMOVE ) ) 
            { 
                if ( !AfxGetThread()->PumpMessage( ) ) 
                { 
                    ::PostQuitMessage( ); 
                    break; 
                } 
            } 
            // let MFC do its idle processing
            LONG lIdle = 0;
            while ( AfxGetApp()->OnIdle(lIdle++ ) )
                ;  
            // Perform some background processing here 
            // using another call to OnIdle
            

            Note: I was not able to check this code and I am not an expert on this deep MFC stuff, but I assume it would work. Maybe somebody else with more in-depth MFC knowledge could comment on this.
            -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

          J 1 Reply Last reply
          0
          • D Daniel Lohmann

            Janetta wrote: use SDI and CFormView. First I have an OnButton function in the view that calls a function in the Doc. Doc calls another function in another file (written in C) and that calls another function in another file that calls AddText. I hope I answered the question you asked. And I know it doesn't sound like a very good structure... Yep, this sounds that there is no messange processing during perfoming a lengthy operation. Unless the thead returns from the OnButton function, no message processing occurs. You have, in prinicple, two possibilities:

            1. Perform the lenghty operation in it's own thread. In this case I recommend using CEditLog, because it is proven to be thread safe.

            2. Add some code to the end of your AddText() function that ensures all outstanding messages are processed. It's quite a long time ago I did this last, but AFAIR the following code should do it (taken with slight modifications from MSDN, do a search for "Idle Loop Processing":

              MSG msg;
              while ( ::PeekMessage( &msg, NULL, 0, 0, PM\_NOREMOVE ) ) 
              { 
                  if ( !AfxGetThread()->PumpMessage( ) ) 
                  { 
                      ::PostQuitMessage( ); 
                      break; 
                  } 
              } 
              // let MFC do its idle processing
              LONG lIdle = 0;
              while ( AfxGetApp()->OnIdle(lIdle++ ) )
                  ;  
              // Perform some background processing here 
              // using another call to OnIdle
              

              Note: I was not able to check this code and I am not an expert on this deep MFC stuff, but I assume it would work. Maybe somebody else with more in-depth MFC knowledge could comment on this.
              -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

            J Offline
            J Offline
            Janine
            wrote on last edited by
            #5

            Thanks! I tried number two and it worked. -Janetta

            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