Problems with updating edit control
-
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
-
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
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
-
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
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
-
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
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:
-
Perform the lenghty operation in it's own thread. In this case I recommend using CEditLog, because it is proven to be thread safe.
-
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 )
-
-
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:
-
Perform the lenghty operation in it's own thread. In this case I recommend using CEditLog, because it is proven to be thread safe.
-
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 )
-