Question about a progress dialog...

Bsically I'm going to be doing some action which will take a while to complete and i want to show a progress dialog while this takes place. Now, I create the dialog and as i get further and further through my long process, i use the member variables of teh dialog to update the controls and show the user how long there is left, is it proper to do it that way? or should i be sending messages to the dialog instead of accessing it's member variables like i am doing now?
[481 byte] By [noods] at [2007-11-18 1:38:29]
# 1 Re: Question about a progress dialog...
Sending a message is a better idea, it will require less processing than polling a variable.
mwilliamson at 2007-11-10 8:53:59 >
# 2 Re: Question about a progress dialog...
Upto, developers convinience, or rather what suits more to the application.

1. If the operational class has to give progress notification every 1% increase in the progress of operation, then sending(posting) messages will be good option.

2. Or else, there can be a timer which checks the operation status every 1 second. In that case accessing variables is the way to go.
pppsandeep at 2007-11-10 8:55:08 >
# 3 Re: Question about a progress dialog...
I am not sure I understand how you are using the member variables of the dialog to update the controls but probably updating the controls is a better idea since it would bypass calling Windows and therefore would require less processing.
Sam Hobbs at 2007-11-10 8:56:07 >
# 4 Re: Question about a progress dialog...
well, this is sort of my code right now...

void CSetupDlg::OnInstall()
{
CProgressDlg* pDlg = new CProgressDlg;

pDlg->Create(IDD_PROGRESS, this);

// install blah
pDlg->m_strMessage = "Installing blah...";
pDlg->UpdateData(FALSE);
Install("blah\\setup.exe", " /sp- /verysilent");
pDlg->m_pPC.StepIt();


// install blah1
pDlg->m_strMessage = "Installing blah1...";
pDlg->UpdateData(FALSE);
// Install("blah1\\blah1.exe", NULL);
Sleep(1000);
pDlg->m_pPC.StepIt();

// install blah2
pDlg->m_strMessage = "Installing blah2 drivers...";
pDlg->UpdateData(FALSE);
// Install("blah2\\setup.exe", " -s");
Sleep(1000);
pDlg->m_pPC.StepIt();

// install blah3
pDlg->m_strMessage = "Installing blah3...";
pDlg->UpdateData(FALSE);
// Install("blah3\\blah3.exe", " /silent /install");
Sleep(1000);
pDlg->m_pPC.StepIt();

// we're done
Sleep(250);
pDlg->EndDialog(IDOK);

// ::SendMessage(pDlg->m_hWnd, WM_CLOSE, 0, 0);
}

i'm just not quite sure if i should be sending messages to the dialog instead of accessing it's variables, i dunno if this causes problems between thrads and whatnot, if it's fine to just use the variables like that, then that's fine
noods at 2007-11-10 8:57:11 >
# 5 Re: Question about a progress dialog...
You are calling EndDialog for a modeless dialog. EndDialog must not be used for modeless dialogs.
Sam Hobbs at 2007-11-10 8:58:04 >
# 6 Re: Question about a progress dialog...
Oops, OK i have changed it to call DestroyWindow() and also overriden PostNCDestroy to delete the this pointer; but is it OK to access the variables like i'm doing or should i be sending messages to it instead?
noods at 2007-11-10 8:59:13 >
# 7 Re: Question about a progress dialog...
Personally I avoid sending messages within my application. If it is possible to call a function directly I would do that. If an application is a multiple-thread application then messages can be a good solution for communicating from a thread to another thread.
Sam Hobbs at 2007-11-10 9:00:06 >
# 8 Re: Question about a progress dialog...
May I suggest that the progess dialog be implemented in a different thread, this way you won't have refresh problems.
proxima centaur at 2007-11-10 9:01:09 >
# 9 Re: Question about a progress dialog...
As far as I know everything else you have is great. I assume the Sleep is just for testing purposes.

I have a suggestion but it is only a suggestion. Instead of using a "Value" type member variable and using UpdateData you can use a "Control" type member variable as in:pDlg->m_ctlMessage.SetWindowText("Installing blah...");
pDlg->m_ctlMessage.UpdateWindow();
Sam Hobbs at 2007-11-10 9:02:16 >
# 10 Re: Question about a progress dialog...
Originally posted by proxima centaur
May I suggest that the progess dialog be implemented in a different thread, this way you won't have refresh problems. What refresh problems?
Sam Hobbs at 2007-11-10 9:03:16 >
# 11 Re: Question about a progress dialog...
When you're in a single thread and you are doing a time consuming task and you switch application (ALT-TAB) then come back to your application, the WM_PAINT message is not processed until the time consuming task is finished. The progress bar will therefore only be updated when the task asks it to update.
proxima centaur at 2007-11-10 9:04:14 >