From: Joseph M. Newcomer on
Basic design rule: putting Sleep() in the main GUI thread is *always* a programming error,
and should be treated as such. In the exceptionally rare (once per decade or so for a
prolific programmer) situation where this would make sense, you will recognize the
exception.
joe

On Tue, 13 May 2008 08:05:01 -0700, nexolite <nexolite(a)discussions.microsoft.com> wrote:

>thnx the idea of using other thread for computation came to my mind but I
>thought it as the last option(dont know why!)
>but now I am able to do it with SetWindowText() with or without Sleep()
>thnx all.
>
>"Joseph M. Newcomer" wrote:
>
>> Actually, for a variety of reasons, this is exceptionally bad code.
>>
>> First, I believe that using UpdateData at all is a fundamental design error. I have spent
>> far too much of my life fixing code that uses it, and my "fix" is to always remove it
>> completely. If you want to set a window to have a value, you will call SetWindowText to
>> do so.
>>
>> Second, you are doing this inside some loop. Until you return to the main message pump,
>> the WM_PAINT message that causes the control to be redrawn will not be sent, so there is
>> no way to see it change.
>>
>> Third, the solution, which is to do SetWindowText followed by UpdateWindow, is VERY
>> expensive, and will substantially delay your loop.
>>
>> In general, if you have a long computation loop, the correct code would involve creating a
>> secondary thread to do the computation, and it would PostMessage requests back to the main
>> GUI thread to request updates of fields.
>> joe
>>
>> On Tue, 13 May 2008 03:20:01 -0700, nexolite <nexolite(a)discussions.microsoft.com> wrote:
>>
>> >I have made a simple MFC(dialog based) program in which the dialog box has
>> >a CEdit box i have defined a DoDataExchange
>> >so my problem is whenever I do something like this
>> > for(i=0;;i++)
>> > {
>> > e=i;
>> > UpdateData(false);
>> > }
>> >where "e" is associated with the edit box
>> >The values as they should be instantaneously displayed in the box the moment
>> >they change, but nothing happens and dialog box freezes.
>> >but if I call a MessageBox("fh"); after UpDateData(false) then the message
>> >box is displayed and the value change is also displayed ,but I want it
>> >without this message box....plz help me
>> >
>> Joseph M. Newcomer [MVP]
>> email: newcomer(a)flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm