Keith Sheppard
2005-01-13 17:48:41 UTC
I want to have a simple progress bar displayed whilst my MFC application is
doing a lengthy operation. To do this, I am creating a user interface
thread which displays a dialog containing a progress bar control.
This is implemented using two classes:
class CProgressDlg : public CDialog
class CProgressThread : public CWinThread
The CProgressThread class has a member variable: CProgressDlg m_Dlg;
At the start of the lengthy operation I create a new instance of
CProgressThread, and set the m_bAutoDelete member TRUE before calling
CProgressThread::CreateThread();
In CProgressThread::InitInstance I have the following code:
if (!IsWindow(m_Dlg.m_hWnd))
m_Dlg.Create(IDD_PROGRESS_DLG, NULL);
m_Dlg.ShowWindow(SW_SHOW);
During the lengthy operation, I post update messages to the dialog box and
the progress bar is updated as expected.
When the operation is finished, I post a "completed" message to the dialog
box which causes it to call EndDialog(). The dialog then disappears as
expected.
All works perfectly until I close the application. Whereupon visual studio,
in debug mode, reports memory leaks - one for every CProgressThread object
created during the lifetime of the application.
If I try to explicitly delete the CProgressThread object when I've finished
with it, the program asserts.
Any suggestions?
Keith
doing a lengthy operation. To do this, I am creating a user interface
thread which displays a dialog containing a progress bar control.
This is implemented using two classes:
class CProgressDlg : public CDialog
class CProgressThread : public CWinThread
The CProgressThread class has a member variable: CProgressDlg m_Dlg;
At the start of the lengthy operation I create a new instance of
CProgressThread, and set the m_bAutoDelete member TRUE before calling
CProgressThread::CreateThread();
In CProgressThread::InitInstance I have the following code:
if (!IsWindow(m_Dlg.m_hWnd))
m_Dlg.Create(IDD_PROGRESS_DLG, NULL);
m_Dlg.ShowWindow(SW_SHOW);
During the lengthy operation, I post update messages to the dialog box and
the progress bar is updated as expected.
When the operation is finished, I post a "completed" message to the dialog
box which causes it to call EndDialog(). The dialog then disappears as
expected.
All works perfectly until I close the application. Whereupon visual studio,
in debug mode, reports memory leaks - one for every CProgressThread object
created during the lifetime of the application.
If I try to explicitly delete the CProgressThread object when I've finished
with it, the program asserts.
Any suggestions?
Keith