Re: CProgressCtrl help needed
There are a bunch of ways to fix your problem. The correct thing to do is
to drag and drop a progress control into your dialog set it's visible
property to false. Attach a variable to it m_ProgressBar. And in your OnOk
method, call m_ProgressBar.ShowWindow(SW_SHOW) to show the control, and do
your work with it, and before you get out of OnOK call
m_ProgressBar.ShowWindow(SW_HIDE) to hide it again.
Or you can change the progress control variable in OnOK from a pointer to an
instance. This way when OnOK exits the progress control gets destroyed.
Since you are not deleting the m_ProgressCtrl variable then it will stay
displayed on the screen, the next time OnOK is called then you are creating
a new progress control and putting it on top of the old one.
void CMyDialog::OnOK()
{
bool flag = false;
CProgressCtrl ProgressCtrl;
ProgressCtrl.Create(WS_CHILD | WS_VISIBLE, CRect(10,245,100,260),this,1);
ProgressCtrl.SetRange(1,100);
ProgressCtrl.SetPos(10);
ProgressCtrl.SetStep(25);
.....
}
Or you can simply call delete m_ProgressCtrl at the end of OnOK.
OnOK()
{
bool flag = false;
CProgressCtrl *m_ProgressCtrl = new CProgressCtrl1;
m_ProgressCtrl->Create(WS_CHILD | WS_VISIBLE, CRect(10,245,100,260),
this,1);
m_ProgressCtrl->SetRange(1,100);
m_ProgressCtrl->SetPos(10);
m_ProgressCtrl->SetStep(25);
.....
delete m_ProgressCtrl;
}
AliR.
P.S. I assmued that m_ProgressCtrl1 was a typo.
"triveni" <prabhu.triveni@gmail.com> wrote in message
news:e5560e60-9d39-4dc4-955a-18310813986c@1g2000prg.googlegroups.com...
Sorry for all the confusion... My code is shown below:
OnOK()
{
bool flag = false;
CProgressCtrl *m_ProgressCtrl1 = new CProgressCtrl1;
m_ProgressCtrl->Create(WS_CHILD | WS_VISIBLE, CRect(10,245,100,260),
this,1);
m_ProgressCtrl->SetRange(1,100);
m_ProgressCtrl->SetPos(10);
m_ProgressCtrl->SetStep(25);
while ( not end of table in db)
{
// Read one record in db.
// Verify it with user entered username and pwd.
// If not same, then
{
m_ProgressCtrl->StepIt();
Read next Record
}
else
{
while(m_ProgressCtrl->GetPos < 100)
m_ProgressCtrl->StepIt();
Close handle to Db
flag = true;
break;
}
}
if(flag)
{
//go to next dialog.
}
else
{
MessageBox("wrong credentials","app",MB_OK);
m_ProgressCtrl->SetPos(0);
}
}
I have not drag-dropped the control from resource editor. I am
creating it only when user clicks "OK" button. There is no thread
here. When I said background, In the same function OnOK() , while I am
increasing the step of progressCtrl , I also verify the username/pwd.
I hope my above code is more clear. Anyways, I tried delete
m_ProgressCtrl fix given by Alir which solved my problem. Thanks to
all who answered my query.
Regards,
Triveni.