Dialog question
-
I am using MFC's CDialog derived class to do some lengthy task. I use a button to trigger the process. The problem I am having is: after I click the button, the lengthy task begins. However, after I switch to other programs, the dialog won't respond my click on it until the task is done. Is there any way I can do to get rid of the problem.
-
I am using MFC's CDialog derived class to do some lengthy task. I use a button to trigger the process. The problem I am having is: after I click the button, the lengthy task begins. However, after I switch to other programs, the dialog won't respond my click on it until the task is done. Is there any way I can do to get rid of the problem.
It's normal: your application has only one thread, in which the Windows messages are processed (mouse click, click on button, ...). So, if in this thread you start a lenghty process, Windows messages are not processed anymore and your GUI will freeze (not able to respond to any messages, event not the WM_PAINT message). The solution is to start this process in a separate thread and to keep the main dialog informed about the status by sending custom messages to it. I suggest you read this excellent article[^], it's worth the time you will take to read it.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
I am using MFC's CDialog derived class to do some lengthy task. I use a button to trigger the process. The problem I am having is: after I click the button, the lengthy task begins. However, after I switch to other programs, the dialog won't respond my click on it until the task is done. Is there any way I can do to get rid of the problem.
I had the same issue and found a simple solution. In the process/task that you are triggering from this dialog, insert the following code so it gets called periodically while that process/task progresses. MSG msgs; while( ::PeekMessage( &msgs, NULL, 0, 0 , PM_NOREMOVE ) ) { if( !AfxGetThread()->PumpMessage() ) { ::PostQuitMessage(0); break; } }
-
I had the same issue and found a simple solution. In the process/task that you are triggering from this dialog, insert the following code so it gets called periodically while that process/task progresses. MSG msgs; while( ::PeekMessage( &msgs, NULL, 0, 0 , PM_NOREMOVE ) ) { if( !AfxGetThread()->PumpMessage() ) { ::PostQuitMessage(0); break; } }