【发布时间】:2011-02-17 06:15:25
【问题描述】:
谁能告诉我为什么在我的基于 VC++ 对话框的应用程序中调用消息框之前调用 UpdateData(FALSE) 不起作用?运行时窗口保持不变,直到我调用:
MessageBoxW(cDisp, L"!!!Data Count!!!", MB_OK | MB_ICONINFORMATION)
我的一段代码sn-p是这样的……
for(int j=0;j<50;j++)
{
if(ferr==0)
{
double X[15][4],splusn[15],m_dBiasC,WOld[1][4],alpha,err,WNew[1][4],y[15][1],WTransOld[4][1];
//do
// {
int iGraphX,iGraphY;
CString cDisp1(""),cDisp;
m_dBiasC=m_dC;
err=m_dError;
alpha=m_dAlpha;
char ch;
double dummy1,dummy2;
cDisp.Format(L"%d",j);
m_sCount.Format(L"%d",m_iInterval);
UpdateData(FALSE);
BeginWaitCursor();
for(int i=0;i<15;i++)
{
f[0]>>dummy1>>ch>>dummy2;
Time[i]=dummy1;
m_dAccX[i]=dummy2;
if(!f[0].good())
{
MessageBox(L"The end of first data file encountered",L"Caution");
MessageBoxW(L"Quiting Program ",L"Caution");
ferr=2;
//break;
exit(1);
}
iGraphX=static_cast<int>(Time[i]*100.0);
iGraphY=static_cast<int>(m_dAccX[i]);
m_Graph[0].RemovePoint(0,0);
m_Graph[0].AddPoint(iGraphX,iGraphY);
cDisp.Format(L"%lf %lf",Time[i],m_dAccX[i]);
cDisp1+=cDisp;
cDisp1+="\r\n";
f[1]>>dummy1>>ch>>dummy2;
Time[i]=dummy1;
m_dAccY[i]=dummy2;
if(!f[1].good())
{
MessageBox(L"The end of second data file encountered",L"Caution");
MessageBoxW(L"Quiting Program ",L"Caution");
ferr=3;
//break;
exit(1);
}
iGraphX=static_cast<int>(Time[i]*50.0);
iGraphY=static_cast<int>(m_dAccY[i]*10);
m_Graph[1].RemovePoint(0,0);
m_Graph[1].AddPoint(iGraphX,iGraphY);
f[2]>>dummy1>>ch>>dummy2;
Time[i]=dummy1;
m_dAccZ[i]=dummy2;
if(!f[2].good())
{
MessageBox(L"The end of third data file encountered",L"Caution");
MessageBoxW(L"Quiting Program ",L"Caution");
ferr=4;
//break;
exit(1);
}
iGraphX=static_cast<int>(Time[i]*50.0);
iGraphY=static_cast<int>(m_dAccZ[i]);
m_Graph[2].RemovePoint(0,0);
m_Graph[2].AddPoint(iGraphX,iGraphY);
f[3]>>dummy1>>ch>>dummy2;
Time[i]=dummy1;
m_dECG[i]=dummy2;
if(!f[3].good())
{
MessageBox(L"The end of fourth data file encountered",L"Caution");
MessageBoxW(L"Quiting Program ",L"Caution");
ferr=5;
//break;
exit(1);
}
iGraphX=static_cast<int>(Time[i]*100.0);
iGraphY=static_cast<int>(m_dECG[i]*100);
m_Graph[3].RemovePoint(0,0);
m_Graph[3].AddPoint(iGraphX,iGraphY);
}
Sleep(500);
GetDlgItem(IDC_DISPLAYFILE)->SetWindowTextW(cDisp1);
UpdateData(FALSE);
EndWaitCursor();
cDisp.Format(L"Data Read till now: %d",((j+1)*15));
MessageBox(cDisp,L"!!!Data Count!!!",MB_OK|MB_ICONINFORMATION);
UpdateData(FALSE);
//This part is for adaptive filter calculations
for(int r=0;r<15;r++)
{
splusn[r]=static_cast<double>(m_dECG[r]);
X[r][0]=m_dBiasC;
X[r][1]=static_cast<double>(m_dAccX[r]*m_dScaleX);
X[r][2]=static_cast<double>(m_dAccY[r]*m_dScaleY);
X[r][3]=static_cast<double>(m_dAccZ[r]*m_dScaleZ);
}
WOld[0][0]=m_dW0;
WOld[0][1]=m_dW1;
WOld[0][2]=m_dW2;
WOld[0][3]=m_dW3;
for(int q=0;q<4;q++)
WNew[0][q]=WOld[0][q];
for(int p=0;p<15;p++)
{
for(int iRectCnt=0;iRectCnt<60;iRectCnt++)
{
f[4]<<setiosflags(ios::fixed)<<setw(8)<<setprecision(4)<<p<<" ";
for(int iWCnt=0;iWCnt<4;iWCnt++)
f[4]<<setw(8)<<setprecision(2)<<WOld[0][iWCnt];
f[4]<<endl;
y[p][0]=0.0;
for(int q=0;q<4;q++)
WTransOld[q][0]=WOld[0][q];
for(int r=0;r<4;r++)
{
y[p][0]=y[p][0]+(X[p][r]*WTransOld[r][0]);
}
err=splusn[p]-y[p][0];
for(int q=0;q<4;q++)
WNew[0][q]=WOld[0][q]+(2.0*alpha*err*X[p][q]);
for(int q=0;q<4;q++)
WOld[0][q]=WNew[0][q];
}
cDisp.Format(L"%lf",err);
GetDlgItem(IDC_ERROR)->SetWindowTextW(cDisp);
splusn[p]=splusn[p]-err;
}
for(int p=0;p<15;p++)
{
iGraphX=static_cast<int>(Time[p]*100.0);
iGraphY=static_cast<int>(splusn[p]*100);
m_Graph[4].RemovePoint(0,0);
m_Graph[4].AddPoint(iGraphX,iGraphY);
}
cDisp.Format(L"%lf",WNew[0][0]);
GetDlgItem(IDC_W0C)->SetWindowTextW(cDisp);
cDisp.Format(L"%lf",WNew[0][1]);
GetDlgItem(IDC_W1C)->SetWindowTextW(cDisp);
cDisp.Format(L"%lf",WNew[0][2]);
GetDlgItem(IDC_W2C)->SetWindowTextW(cDisp);
cDisp.Format(L"%lf",WNew[0][3]);
GetDlgItem(IDC_W3C)->SetWindowTextW(cDisp);
m_sCount.Format(L"%d",0);
// End of Adaptive filter
//close files here if already end of file is encountered
if((f[0].eof()||f[1].eof()||f[2].eof()||f[3].eof()))
{
MessageBox(L"End of File encountered");
ferr=1;
exit(1);
}
//}while(!(f[0].eof())&&!(f[1].eof())&&!(f[2].eof())&&!(f[3].eof()));
}
}
【问题讨论】:
-
我们无所不知,无所不知,所以是的,我们可以告诉您您的代码出了什么问题,而不会看到它的任何 sn-p。
-
...我们可以告诉你,但我们不这样做,因为我们真的是坏人!
-
对不起 Mehrdad,您的意思是我应该在问题中添加我的代码的 sn-p 吗?如果是的话,我可以这样做......
-
有趣的阅读:Avoiding UpdateData。建议的替代方法是访问 控制变量 中的值,而不是使用
UpdateData函数。 -
@sspdd:哈哈,是的,我的意思是你应该在你的代码中添加一个 sn-p,所以我们看看事情是如何相互作用的。 (一般来说,即使看起来很明显,最好放一段代码,这样人们可以更真实地看到正在发生的事情。)感谢您发布它。 :)
标签: c++ windows winapi visual-c++ mfc