void formula(CString strtxt)
  {
    used=0; pr=0;
  for ( int i=0; i<strtxt.GetLength(); i++)
  {
char ch=strtxt.GetAt(i);
  
  if(ch=='0'||ch=='1')
  { 
/*  if(i>=1)
  {char ch1=strtxt.GetAt(i-1);
  if(ch1=='0'||ch1=='1')
  {
// MessageBox(" 表达式输入错误,请重新输入!");
  return;
  }
  }
  */
  argt=ch-'0';
  num.push(argt);
  continue;
  } else if(ch=='+'||ch=='*')
  {
/* if(i>=1)
  {char ch1=strtxt.GetAt(i-1);
  if(ch1=='+'||ch1=='*')
  { 
//MessageBox(" 表达式输入错误,请重新输入!");
  return;}
  
  }
*/ if(oper.empty()||oper.top()=='(')
  oper.push(ch);
 else
 {
 while (!Prr(ch,oper.top()))
  {
  Cal(num, oper);
  if(oper.empty()||oper.top=='(')
  break;
  }
  oper.push(ch);
  continue;
 }
  }
else if(ch=='(')
{
pr++; oper.push(ch); 
continue;
}
 else if (ch==')')
{
pr--;
while (!oper.empty())
{
if(oper.top()=='(')
break;
Cal(num, oper);
}
oper.pop();
continue;
}
 else 
 {
// ::MessageBox(" 表达式输入错误,请重新输入!");

 return;}
 

  }
  }void CTest06182Dlg::OnButton1() 
{
CString strtxt1;
GetDlgItem(IDC_EDIT1)->GetWindowText(strtxt1);
formula(strtxt1);
 
  if (!pr)
   //MessageBox("括号数目不匹配,请检查并重新输入!");
 
  { 
  while (!oper.empty())   Cal(num,oper); 
  CString str;
  str.Format("%5d",num.top());
  GetDlgItem(IDC_EDIT2)->SetWindowText(str);
  }
 else 
  MessageBox("括号数目不匹配,请检查并重新输入!");
}
上面是我程序的一部分,当我在自己定义的
void formula(CString strtxt)函数中用MessageBox()函数时,总是提示错误,该怎么解决啊,谢谢各位指点!

解决方案 »

  1.   

    你的 formula 是全局函数, 需要使用 int MessageBox(
        HWND hWnd,
        LPCTSTR lpText,
        LPCTSTR lpCaption,
        UINT uType
    );你用的是 CWnd::MessageBox(
        LPCTSTR lpszText,
       LPCTSTR lpszCaption = NULL,
       UINT nType = MB_OK 
    );改成 MessageBox(NULL, "括号数目不匹配,请检查并重新输入!"); 就OK
      

  2.   

    按楼上的改了,可是还是有:
    error C2660: 'MessageBoxA' : function does not take 2 parameters
    这种错?
    不好意思,我刚接触VC不久
      

  3.   

    按楼上的改了,可是还是有: 
    error C2660: 'MessageBoxA' : function does not take 2 parameters 
    这种错? 
    不好意思,我刚接触VC不久
      

  4.   

    MessageBox(NULL, "括号数目不匹配,请检查并重新输入!", NULL, MB_OK); 
      

  5.   

    在有些地方用它会有问题的,改用:
    AfxMessageBox("括号数目不匹配,请检查并重新输入!", ");
      

  6.   

    void formula(CString strtxt) 
    {...
    if(i>=1) 
      {char ch1=strtxt.GetAt(i-1); 
      if(ch1=='+'||ch1=='*') 
      { 
    AfxMessageBox("表达式输入错误,请重新输入!", MB_OK,0);
      return;} 
    ...
    }

    我改成:AfxMessageBox("表达式输入错误,请重新输入!", MB_OK,0)后,好像还是崩溃,点击确定后,出现一个窗,说.exe文件遇到问题,需要关闭.
    为什么啊?
    搞得我都快崩溃了
      

  7.   

    MessageBox和AfxMessageBox一样的,出错是其他地方的问题if (!pr) 
      //MessageBox("括号数目不匹配,请检查并重新输入!"); -->
    if (!pr) 
    {
      //MessageBox("括号数目不匹配,请检查并重新输入!"); 
      return;
    }
      

  8.   

    呵呵~学习学习,一般只是提示的就用afxmessagebox()吧,这个事全局函数简单些吧
    messagebox一般用于返回个值
    是这样吧?
      

  9.   

    pr==NULL的时候你如果没做返回操作,如果你在别的地方用了这个pr访问内存的时候,就会有错误产生,因为他不指向任何内存区域.
      

  10.   

    我设了一个标志位,在主函里里调用 AfxMessageBox9();就没事了,谢谢上面的各位指点!