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)
//接下去的代碼