程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> c語言-MessageBox和DialogResult程序報錯

c語言-MessageBox和DialogResult程序報錯

編輯:編程解疑
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

最佳回答:


 這代碼是C#的,不是C++的。

C++的寫法是
if (MessageBox(NULL. "You did not enter a server name. Cancel this operation?", "No Server Name Specified", MB_YESNO) == IDYES)
//接下去的代碼
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved