为什么视频里能通过编译,而我这里却不能编译呢?用的都是VC6.0
,而且也是按视频的来操作的,不明白为什么!错误信息:
Compiling...
CALCULATORDlg.cpp
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(189) : error C2059: syntax error : 'constant'
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(190) : error C2228: left of '.pSubmenu' must have class/struct/union type
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(190) : error C2227: left of '->InsertMenuA' must point to class/struct/union
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(190) : error C2059: syntax error : 'constant'
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(191) : error C2228: left of '.bAllow' must have class/struct/union type
G:\MFC程序\MFC工程\CALCULATOR\CALCULATORDlg.cpp(192) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
执行 cl.exe 时出错.CALCULATORDlg.obj - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    void CCALCULATORDlg::OnAllow() 
    {
    if (!bAllow)
    {
    CMenu *pmenu = GetMenu(),  // 获取菜单的指针
      *pSubmenu = pmenu->GetSubMenu( 0); //获取子菜单的指针
    错误提示:GetSubMenu()参数不仅一个 pSubmenu->InsertMenu(0, MF_BYPOSITION.IDM_SUM, "求和");
    pSubmenu->InsertMenu(1, MF_BYPOSITION.IDM_AVERAGE, "求平均");
    错误提示:left of '->InsertMenuA' must point to class/struct/union
    bAllow = TRUE;
    m_Allow.SetWindowText("禁止计算");
    }
    else
    {
    CMenu *pmenu = GetMenu(),
      *pSubmenu = pmenu->GetSubMenu(0); pSubmenu->DeleteMenu(IDM_SUM, MF_BYCOMMAND);
    pSubmenu->DeleteMenu(IDM_AVERAGE, MF_BYCOMMAND);
    bAllow = FALSE;
    m_Allow.SetWindowText("允许计算");
    }

    }void CCALCULATORDlg::OnClose() 
    {
    OnOK();

    }void CCALCULATORDlg::OnSum()
    {
    double sum = 0;
    char strOfNum[10]; m_Edit1.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit2.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit3.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit4.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    sprintf(strOfNum, "%.3f", sum);
    m_Edit5.SetWindowText(strOfNum);}void CCALCULATORDlg::OnAverage()
    {
    double sum = 0,
       average = 0;
    char strOfNum[10]; m_Edit1.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit2.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit3.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum);
    m_Edit4.GetWindowText(strOfNum, 10);
    sum += atof(strOfNum); average = sum / 4;
    sprintf(strOfNum, "%.3f", average);
    m_Edit6.SetWindowText(strOfNum);
    }