Click to See Complete Forum and Search --> : do-while loop & UpdateData(FALSE)
Dear all,
I have a button "Go" and an edit box with a member variable
associated m_var (type double).
When I pressed the button, the method associated "OnButtonGo" run
a do-while loop like this:
ccode
void CMyCodeDlg::OnButtonGo()
{
double err_toll = 0.0001;
do
{
.... //other math code
m_var = CalculateError();
UpdateData(FALSE);
} while (m_var < err_toll);
}
/ccode
the value of variable m_var change during the loop and I would like to see
the changes for every iteration, but on video is printed only the value
related to the last iteration. Why?
I hope that the question is clear. Sorry, for my english!
Thank, Giuseppe.
chiuyan
June 9th, 1999, 08:51 AM
it is probably changing like you want, it is just changing too fast for you to see the difference. Your do-while loop can probably execute about 1000 times a second (On a relatively new computer).
Try calling
Sleep (DWORD dwMilliseconds)
after the UpdateData to pause for a little while before the next iteration of the loop.
--michael
Roger Allen
June 9th, 1999, 08:53 AM
The varaible does not update because you need to allow other messages to be processed during your loop. Try adding the following code to the end of your loop aftere the UpdateData() :
MSG msg ;
SetDlgItemText(IDC_STATUS, text) ;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOYIELD | PM_REMOVE))
{
::TranslateMessage(&msg) ;
::DispatchMessage(&msg) ;
}
Warning : With this in the loop, all the buttons can be clicked on your dialog again, so you will need to block certain funtions from running again, as you could have two concurrent versions of your OnButtonGo() function running at the same time! The easiest wasy around this is to disable the button before your loop and then re-enable it at the end of the procedure.
GetDlgItem(IDC_GO_BUTTON)->EnableWindow(false) ;
// loop code
GetDlgItem(IDC_GO_BUTTON)->EnableWindow(true) ;
HTH
Roger Allen
giuseppe_muggeo
June 9th, 1999, 10:42 AM
Dear Roger Allen,
Thanks for your fast reply, I have insert your code in my application and now it is all ok. It makes what I want! A suggested for you. I have omitted the follow code:
(*) SetDlgItemText(IDC_STATUS, text) ;
because I have used UpdateData(FALSE) that updates all edit box. I think that (*) is necessary when I use GetDlgItem(IDC_STATUS) -> SetWindowText(text). What do you think about?
This Discussion Group is very excellent and I have submitted it. Bye, Bye from ITALIA. Sei stato fantastico (you are fantastic).
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.