Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UpdateData() problem

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
0
0
US
Iam trying to monitor progress within a for loop. I use the UpdateData(FALSE) function to update text boxes on the form. However, the updates are not recorded until it exits the loop. Only the last set of variables are updated to the text boxes.

// Start the process
for (int i = 1; i < Y; i++)
{
for (int j = i + 1; j < X; j++)
{
ulFind = FindResult(i, j);
if (ulFind > (unsigned) m_Result)
{
// Update the variables
m_Result = (long)ulFind;
m_Stage1 = i;
m_Stage2 = j;
UpdateData(FALSE);
}
}
}
 
Yes, that's what happens when your code runs in a tight loop like that. Your never allowing your UI code to execute until after you exit the loop. You could try placing an Invalidate() call after UpdateData(FALSE).

If it performs a SendMessage(WM_PAINT), rather than PostMessage(), it should work, but if your machine is fast enough you still won’t see anything but some flickering since your loop just rolls back around and changes it again.

Your really need a different design using a worker thread or a timer or something like that.

-pete


 
Pete,
The Invalidate() did not work, but it pointed me in the right direction. I found an example and it used UpdateWindow(). This worked. Thanks for the help.

HyperEngineer
 
>> Your really need a different design using a worker thread or a timer or something like that.

Palbano is right on target here.

Even if you can get the window to update itself, realize though that it will not respond to any windows messages during the processing, particularly important ones such as WM_CLOSE or WM_SYSCOMMAND.

It is probably a good idea if you have a function that takes a considerable amount of time, put it in a worker thread so it can run in the background.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top