2 u013069562 u013069562 于 2016.04.26 15:44 提问

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个回答

caozhy
caozhy   Ds   Rxr 2016.04.26 22:21
已采纳
 这代码是C#的,不是C++的。

C++的写法是
if (MessageBox(NULL. "You did not enter a server name. Cancel this operation?", "No Server Name Specified", MB_YESNO) == IDYES)
//接下去的代码
caozhy
caozhy   Ds   Rxr 2016.04.26 22:21
 if (MessageBox(NULL, "You did not enter a server name. Cancel this operation?", "No Server Name Specified", MB_YESNO) == IDYES)
qq_20246395
qq_20246395   2016.04.27 02:20

c#才有这东西DialogResult.Yes。。。。怎么越看越像c#
DialogResult MessageBoxButton这些东西错误中说未定义
加上网上找到,应该是没有依赖某个库,这些东西都是别人定义的东西,而且我看好像是c++.net的东西。
嘛,只想实现功能的话楼上已经有答案了

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!