Click to See Complete Forum and Search --> : Modeless Dialog Construction


Gamble
April 9th, 1999, 02:26 AM
This is troublesome...

I'm trying to create a simple modeless dialog to track the progress of a file processing function - it consists of a two static text controls and an icon. One of the text controls is updated by the function as it works to reflect the current directory. However... When I construct the dialog only the single text control appears, until every directory has been processed. After all this has been done, *then* the other line of text and the icon appear. The code I'm using is fairly simple:

// Reveal the modeless progress dialog
m_pScanDlg = new CScanningDialog;

m_pScanDlg->SetCurrentDir(szCurDir);
m_pScanDlg->ShowWindow(SW_SHOW);

//...
// Process and update dialog
//...

// Free up the progress dialog
delete m_pScanDlg;


SetCurrentDir() just updates the CString mapped to the text control and calls UpdateData() on the progress dialog. I'm really at a loss as to why this dialog isn't being fully displayed until its gone through all the directories. Can anyone tell me what I'm doing wrong?

Karl
April 9th, 1999, 03:59 AM
I suppose that your call the CDialog::Create in the constructor of your dialog (don't forgt to call CDialog::DestroyWindow before deleting it).
The problem may be that processing your directory don't allow the dialog to refresh. A modeless dialog is in fact a new thread; if your main thread takes all the CPU available, your dialog will wait that this main thread ends its processing; To avoid that, you could call SleepEx(10, FALSE) after processing each directory, which allows the system to run the others threads.

HTH.

K.

Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.

Gamble
April 9th, 1999, 05:19 AM
Bingo!

Apparently, the modeless dialog just didn't want to update itself while the directories were being processed. I tried a call to SleepEx(), but that didn't seem to help. Your suggestion *did*, however, lead me to the solution. I just placed a call to UpdateWindow() in the processing function and my problems disappeared. =)