JiChen

I have a problem to update the log info in the CDialog while a heavy task was running which made the GUI window dead (the mouse was not active). I tried many approaches such as Message sending, syncromised multithread, and still didn't update the GUI part, only did when the program finished. Can someone provide good suggestions and advises

thanks,
Ji


Re: Visual C++ General how to update CWnd when runing a heavy task

Peter Ritchie

You should be performing the lengthy operation on another thread. You can communicate from that thread to your CWnd by posting messages.




Re: Visual C++ General how to update CWnd when runing a heavy task

scor7910

Hi Ms JiChen.

Did you tried Message Pumping

Read this concerned article on code project.

http://www.codeproject.com/threads/TemplatedLengthyOperation.asp

In conclusion, you can solve by calling below function.

Code Snippet

BOOL XXX::Pump()
{
MSG msg;
while (::PeekMessage(&msg, NULL, // pump message until none
NULL, NULL, PM_NOREMOVE)) // are left in the queue
{
AfxGetThread()->PumpMessage();
}
return m_bAbort;
}

Good Luck~






Re: Visual C++ General how to update CWnd when runing a heavy task

JiChen

Thanks, the article exactly answers my question and the code works well. Now I can update the log info. But there is a couple seconds period that the GUI Window frozend or dispeared, then back alive again, maybe need set sleep before runing next big job, or do you have a good suggestion

Thanks again and have a great weekend,
Ji




Re: Visual C++ General how to update CWnd when runing a heavy task

Peter Ritchie

You should read http://www.flounder.com/badprogram.htm#Using%20PeekMessage%20anywhere before you get too far with PeekMessage.




Re: Visual C++ General how to update CWnd when runing a heavy task

scor7910

Yesterday, I tried adding a timer procedure for message pumping.

I think there are many different ways. ^^;;






Re: Visual C++ General how to update CWnd when runing a heavy task

scor7910

A-ha..I forgot this issue..

Thanks.

Using PeekMessage is more appropriate.






Re: Visual C++ General how to update CWnd when runing a heavy task

JiChen

thanks Peter and scor7910 for the posts, it is a great help.




Re: Visual C++ General how to update CWnd when runing a heavy task

Simple Samples

There are many ways to do what you need to do and this has been discussed very frequently in other forums. You must read the relevant Microsoft documentation too; see Idle Loop Processing. It has a sample message loop override and it is best to use the official sample.

Note however that OnIdle is not processed for dialogs, or at least it was not in previous versions of MFC. I have a sample in my site for dialogs in case that helps.