I think you have two problems:
- How to update a progress control
- Ensure that the update is executed (not blocked)
Updating such progress controls is usually performed by posting user defined messages from the worker code to the dialog:
#define WM_APP_PERCENT_PROGRESS (WM_APP + 0)
class CMyDialog : CDialog
{
...
LRESULT OnUpdateProgress(WPARAM wParam, LPARAM lParam);
...
};
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
...
ON_MESSAGE(WM_APP_PERCENT_PROGRESS, OnUpdateProgress)
END_MESSAGE_MAP()
CMyDialog::OnUpdateProgress(WPARAM wParam, LPARAM lParam)
{
unsigned long size_copied = static_cast<unsigned long>(wParam);
unsigned long max_size = static_cast<unsigned long>(lParam);
m_percent.Format(_T("%.2f %%"),
((double)size_copied/(double)max_size)*100.);
UpdateData(FALSE);
return 0:
}
::PostMessage(hWndDialog, WM_APP_PERCENT_PROGRESS, (WPARAM)size_copied, (LPARAM)max_size);
Solving the second problem is more complicated. If your copy code is executed from within the same thread as your dialog, the message processing of your dialog is blocked until copying has been finished. To solve this, the copying must be executed from within another thread. An example for such a worker thread would be too much code for a short answer. However, you may find lot of examples here at CodeProject and in the web.