Showing a modeless progress dialog while opening document with MFC 
Author Message
 Showing a modeless progress dialog while opening document with MFC

Dear VC++ pandits,

I would like to display a progress dialog while opening a document in an MDI
application. The deserialization is done through a factory, and it's quite
an intricate (recurrent) process, so I cannot just have a loop like:

Read
while (!EOF)
{
    DeserializeOneObject
    Progress.Step
    Read

Quote:
}

What I have done (please tell me if you have a "cleaner" solution) is that I
start a working thread in the OnOpenDocument like that:

BOOL MyDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
...

m_NrOfItems = 0;

m_isLoading = TRUE;

CWinThread* pThread = AfxBeginThread( ShowProgress, this ,
THREAD_PRIORITY_HIGHEST);

GetFactory().OpenDatabase( static_cast<RWCollectableString>( lpszPathName )
);

m_isLoading = FALSE;

...

Quote:
}

Where the ShowProgress function is implemented as follows:

UINT ShowProgress(LPVOID pParam)
{
 MyDoc& Doc = *static_cast<MyDoc*>( pParam );

Doc.m_ProgressDlg.m_ItemsOpened.SetRange( 0, Doc.m_TotalNrOfItems );

try
{
    while (Doc.isLoading())
    {
         Doc.m_ProgressDlg.m_ItemsOpened.SetPos( Doc.m_NrOfItems );
         Doc.m_ProgressDlg.ShowWindow( SW_SHOWNORMAL );
         Sleep( 200 );
    }

Quote:
}

 catch ( ... )
 {
 }

Doc.m_ProgressDlg.ShowWindow( SW_HIDE );

return 0;

Quote:
}

The m_NrOfItems attribute in the MyDoc class is incremented by each object
being loaded.

My problem is that the thread pauses at the:

Doc.m_ProgressDlg.m_ItemsOpened.SetRange( 0, Doc.m_TotalNrOfItems );

until the OnOpenDocument is finished (You will agree such a progress bar is
not that helpful;-). I guess some MFC objects must be locked through
Critical Sections. Is there a way to avoid that? Or do you have another
solution?

Otherwise the thread works fine if I replace the references to the dialog by
TRACE instructions.

I thank you for any information which can help me solve this problem.

Sincerely,

Mariano



Wed, 14 Nov 2001 03:00:00 GMT  
 Showing a modeless progress dialog while opening document with MFC
Mariano,
your trouble is that you create your thread as a worker thread (i.e. a
thread promising not to use the GUI). Unfortunately my experience with GUI
threads is very limited so I can only advise you on the diagnosis, not the
cure.

HTH Andreas



Thu, 15 Nov 2001 03:00:00 GMT  
 Showing a modeless progress dialog while opening document with MFC
Hi,

Quote:
>Dear VC++ pandits,

>I would like to display a progress dialog while opening a document in an
MDI
>application. The deserialization is done through a factory, and it's quite
>an intricate (recurrent) process,

Does your worker thread own the Progress Bar?
If not, then it won't be able to update it during it's CPU time.

Be sure to attach the handle for at least the Progress bar,
within yout worker thread.  You might also have to create it there.

Hope that points you in the right direction!

Ian

remove nospam- for direct replies!



Thu, 15 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to show progress during long document open?

2. Modeless dialog in a MFC document/view application

3. Modeless Dialog w/progress bar?????????

4. Modeless Dialog with Progress Bar

5. Progress bar not showing visual progress

6. Showing file loading/saving progress in progress bar?

7. Progress Bar only shows on dialog

8. App fails when creating/showing Modeless Dialog

9. Modal vs. Modeless dialog and controls not showing

10. Modeless dialogs in dlls showing help

11. modeless dialog not showing

12. Show modeless form in VB ActiveX DLL from C++ MFC DLL

 

 
Powered by phpBB® Forum Software