风色幻想V 2016-04-26 07:44 采纳率: 100%
浏览 1578
已采纳

MessageBox和DialogResult程序报错

VC++6.0网上找的点击“是”进入下一步的代码,然后我用main函数执行下面的代码
string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;

    //显示MessageBox.
    result = MessageBox.Show(this, message, caption, buttons);

    //如果点击的是"YES"按钮,将form关闭.
    if(result == DialogResult.Yes)
    {
        // Closes the parent form.
        this.Close();
    }

然后报了错,请问是什么问题,最好能给一份完整的代码,本人新手
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'DialogResult' : undeclared identifier
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Yes' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Show' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxButtons' : undeclared identifier
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.YesNo' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxIcon' : undeclared identifier
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Information' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxDefaultButton' : undeclared identifier
C:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Button1' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(15) : error C2228: left of '.Show' must have class/struct/union type
C:\Desktop\ceshi1\ceshi1.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed

  • 写回答

3条回答

  • threenewbee 2016-04-26 14:21
    关注
     这代码是C#的,不是C++的。
    
    C++的写法是
    if (MessageBox(NULL. "You did not enter a server name. Cancel this operation?", "No Server Name Specified", MB_YESNO) == IDYES)
    //接下去的代码
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题