2013-05-25 3 views
-3

Я делаю видео-игру с использованием Microsoft Visual C++, я кодирую все это на языке CLR, но я эту странную проблему ....Форма 2 не открывается?

Почему-то всякий раз, когда я пытаюсь открыть форму 2 с помощью формы 1, Я получаю эти ошибки ...

*1>------ Build started: Project: Retaliation, Configuration: Debug Win32 ------ 
    1> Form2.cpp 
    1>c:\users\devon\documents\visual studio  2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'Form2' : undeclared  identifier 
    1>c:\users\devon\documents\visual studio  2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'f2' : undeclared  identifier 
    1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2061: syntax error : identifier 'Form2' 
    1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(432): error C2065: 'f2' : undeclared identifier 
    1>c:\users\devon\documents\visual studio  2010\projects\retaliation\retaliation\Form1.h(432): error C2227: left of '->Show' must  point to class/struct/union/generic type 
    1>   type is ''unknown-type'' 
    1> Retaliation.cpp 
    1> Generating Code... 
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========* 

Вот мой код для формы 1 ...

#pragma once 
    #include "stdAfx.h" 
    #include "Form2.h" 
    #include "Form1.h" 

    namespace Retaliation { 

using namespace System; 
using namespace System::ComponentModel; 
using namespace System::Collections; 
using namespace System::Windows::Forms; 
using namespace System::Data; 
using namespace System::Drawing; 
using namespace System::IO; 
using namespace std; 
/// <summary> 
/// Summary for Form1 
/// </summary> 
public ref class Form1 : public System::Windows::Forms::Form 
{ 
public: 
    String^ CharName; 
    String^ Race; 
    String^ Gender; 
    String^ Specialty; 
    String^ Friend; 
    int YesorNo; 
    int ExitChoice; 
    int TimerValue; 
int MonsterN; 
int EnemyHp; 
int Dm; 
int Energy; 
int Action; 
int Rage; 
int MaxMana; 
int MaxRage; 
int MaxEnergy; 
int Save; 
// 1 = Earth pony 2 = Pegasus 3 = unicorn 
int Lv; 
int XpR; 
    int Xp; 
int A; 
int D; 
int Hp; 
int MaxHp; 
int Magic; 
int Mana; 
int Agility; 
int Gold; 
String ^Enpowerment; 
// 1 = Friendship is Magic, 2 = Music is Magic, 3 = Darkness is Magic, 4 = Light is  Magic, 5 = Chaos is Magic 
// End of leveling thread 
int Checkpoint; 
int FriendNameN; 
int SavePoint; 
int MenuChoice; 
int RightMenuChoice; 
int RestartFile; 
int Answer; 
int EnemyA; 
int EnemyD; 
int EnemyLv; 
int EnemyMana; 
int EnemyMagic; 
int EnemyAgility; 
int Random; 
String^EName; 
int Damage; 
int Survivors; 
int SavedSurvivors; 
private: System::Windows::Forms::TextBox^ textBox1; 
private: System::Windows::Forms::Timer^ timer1; 
public: 
    int MainActions; 


    Form1(void) 
    { 
     InitializeComponent(); 
     // 
     //TODO: Add the constructor code here 
     // 

    } 

protected: 
    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    ~Form1() 
    { 
     if (components) 
     { 
      delete components; 
     } 
    } 
private: System::Windows::Forms::PictureBox^ pictureBox1; 
protected: 
private: System::Windows::Forms::Button^ button1; 
private: System::Windows::Forms::Button^ button2; 
private: System::Windows::Forms::Button^ button3; 
private: System::Windows::Forms::PictureBox^ pictureBox2; 
private: System::Windows::Forms::Label^ label1; 



private: System::Windows::Forms::Label^ label2; 


private: System::Windows::Forms::Button^ button4; 
private: System::Windows::Forms::Button^ button5; 
private: System::Windows::Forms::PictureBox^ pictureBox3; 
private: System::ComponentModel::IContainer^ components; 

private: 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 


     #pragma region Windows Form Designer generated code 
    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    void InitializeComponent(void) 
    { 
     this->components = (gcnew System::ComponentModel::Container()); 
     System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); 
     this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); 
     this->button1 = (gcnew System::Windows::Forms::Button()); 
     this->button2 = (gcnew System::Windows::Forms::Button()); 
     this->button3 = (gcnew System::Windows::Forms::Button()); 
     this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox()); 
     this->label1 = (gcnew System::Windows::Forms::Label()); 
     this->label2 = (gcnew System::Windows::Forms::Label()); 
     this->button4 = (gcnew System::Windows::Forms::Button()); 
     this->button5 = (gcnew System::Windows::Forms::Button()); 
     this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox()); 
     this->textBox1 = (gcnew System::Windows::Forms::TextBox()); 
     this->timer1 = (gcnew System::Windows::Forms::Timer(this- >components)); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox1))->BeginInit(); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox2))->BeginInit(); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit(); 
     this->SuspendLayout(); 
     // 
     // pictureBox1 
     // 
     this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image"))); 
     this->pictureBox1->Location = System::Drawing::Point(0, -3); 
     this->pictureBox1->Name = L"pictureBox1"; 
     this->pictureBox1->Size = System::Drawing::Size(600, 295); 
     this->pictureBox1->TabIndex = 0; 
     this->pictureBox1->TabStop = false; 
     // 
     // button1 
     // 
     this->button1->Location = System::Drawing::Point(13, 230); 
     this->button1->Name = L"button1"; 
     this->button1->Size = System::Drawing::Size(127, 43); 
     this->button1->TabIndex = 1; 
     this->button1->Text = L"Start Game"; 
     this->button1->UseVisualStyleBackColor = true; 
     this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); 
     // 
     // button2 
     // 
     this->button2->Location = System::Drawing::Point(313, 212); 
     this->button2->Name = L"button2"; 
     this->button2->Size = System::Drawing::Size(120, 42); 
     this->button2->TabIndex = 2; 
     this->button2->Text = L"New Game"; 
     this->button2->UseVisualStyleBackColor = true; 
     this->button2->Visible = false; 
     this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); 
     // 
     // button3 
     // 
     this->button3->Location = System::Drawing::Point(143, 212); 
     this->button3->Name = L"button3"; 
     this->button3->Size = System::Drawing::Size(120, 42); 
     this->button3->TabIndex = 3; 
     this->button3->Text = L"Load Game"; 
     this->button3->UseVisualStyleBackColor = true; 
     this->button3->Visible = false; 
     this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); 
     // 
     // pictureBox2 
     // 
     this->pictureBox2->BackColor = System::Drawing::Color::Transparent; 
     this->pictureBox2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources- >GetObject(L"pictureBox2.BackgroundImage"))); 
     this->pictureBox2->Location = System::Drawing::Point(0, -3); 
     this->pictureBox2->Name = L"pictureBox2"; 
     this->pictureBox2->Size = System::Drawing::Size(86, 81); 
     this->pictureBox2->TabIndex = 4; 
     this->pictureBox2->TabStop = false; 
     this->pictureBox2->Visible = false; 
     // 
     // label1 
     // 
     this->label1->AutoSize = true; 
     this->label1->BackColor = System::Drawing::Color::Transparent; 
     this->label1->Location = System::Drawing::Point(92, -3); 
     this->label1->Name = L"label1"; 
     this->label1->Size = System::Drawing::Size(22, 13); 
     this->label1->TabIndex = 5; 
     this->label1->Text = L"  "; 
     this->label1->Visible = false; 
     // 
     // label2 
     // 
     this->label2->BackColor = System::Drawing::Color::Transparent; 
     this->label2->Location = System::Drawing::Point(358, 87); 
     this->label2->Name = L"label2"; 
     this->label2->Size = System::Drawing::Size(199, 98); 
     this->label2->TabIndex = 9; 
     this->label2->Text = L"None"; 
     this->label2->Visible = false; 
     // 
     // button4 
     // 
     this->button4->Location = System::Drawing::Point(463, 13); 
     this->button4->Name = L"button4"; 
     this->button4->Size = System::Drawing::Size(75, 23); 
     this->button4->TabIndex = 12; 
     this->button4->Text = L"Yes"; 
     this->button4->UseVisualStyleBackColor = true; 
     this->button4->Visible = false; 
     this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); 
     // 
     // button5 
     // 
     this->button5->Location = System::Drawing::Point(463, 43); 
     this->button5->Name = L"button5"; 
     this->button5->Size = System::Drawing::Size(75, 23); 
     this->button5->TabIndex = 13; 
     this->button5->Text = L"No"; 
     this->button5->UseVisualStyleBackColor = true; 
     this->button5->Visible = false; 
     this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click); 
     // 
     // pictureBox3 
     // 
     this->pictureBox3->BackColor = System::Drawing::Color::Transparent; 
     this->pictureBox3->Location = System::Drawing::Point(13, 84); 
     this->pictureBox3->Name = L"pictureBox3"; 
     this->pictureBox3->Size = System::Drawing::Size(165, 208); 
     this->pictureBox3->TabIndex = 14; 
     this->pictureBox3->TabStop = false; 
     this->pictureBox3->Visible = false; 
     // 
     // textBox1 
     // 
     this->textBox1->Location = System::Drawing::Point(463, 212); 
     this->textBox1->Name = L"textBox1"; 
     this->textBox1->Size = System::Drawing::Size(100, 20); 
     this->textBox1->TabIndex = 15; 
     this->textBox1->Visible = false; 
     this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged_1); 
     // 
     // timer1 
     // 
     this->timer1->Interval = 1000; 
     this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick); 
     // 
     // Form1 
     // 
     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
     this->ClientSize = System::Drawing::Size(598, 285); 
     this->Controls->Add(this->textBox1); 
     this->Controls->Add(this->pictureBox3); 
     this->Controls->Add(this->button5); 
     this->Controls->Add(this->button4); 
     this->Controls->Add(this->label2); 
     this->Controls->Add(this->label1); 
     this->Controls->Add(this->pictureBox2); 
     this->Controls->Add(this->button3); 
     this->Controls->Add(this->button2); 
     this->Controls->Add(this->button1); 
     this->Controls->Add(this->pictureBox1); 
     this->Name = L"Form1"; 
     this->Text = L"Retaliation"; 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit(); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit(); 
     this->ResumeLayout(false); 
     this->PerformLayout(); 

    } 
    #pragma endregion 
    public:int MoviePlay; 
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
      // 
      this -> button2 -> Visible = true; 
      this -> button3 -> Visible = true; 
      this -> button1 -> Visible = false; 
      this -> pictureBox1 -> Load("Derpy.jpg"); 
      // 
     } 
     private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { 
     if (YesorNo == 0){ 
      this -> button4 -> Visible = true; 
     this -> button2 -> Visible = false; 
     this -> button5 -> Visible = true; 
     this -> button3 -> Visible = false; 
     this -> label2 -> Visible = true; 
     this -> label2 -> Text = "Are you Sure?"; 
     this -> YesorNo = 1; 
     } 
     else if (YesorNo == 5) 
     { 
      Gender = "Female"; 
      this -> label2 -> Text = "What is your Race??"; 
      this -> button4 -> Text = "Earth Pony"; 
      this -> button5 -> Text = "Unicorn"; 
      this -> button2 -> Visible = true; 
      this -> button2 -> Text = "Pegasus"; 
      YesorNo = 6; 
     } 
     else if (YesorNo == 6) 
     { 
      Race = "Pegasus"; 
      this -> button2 -> Visible = false; 
      this -> button4 -> Visible = false; 
      this -> button5 -> Visible = false; 
      label2 -> Text = "Thank You For Playing!!"; 
      YesorNo = 7; 
      this -> timer1 -> Start(); 
     } 
    } 
      private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { 

    } 
     private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { 
     if (YesorNo == 1) 
     { 
      this -> label2 -> Text = "To Make your Pony Character, See PonyMakin.txt in your Retaliation Folder, Your pony should have a invisible background... If not check your background color For your pony!"; 
      button4 -> Text = "Show Pony"; 
      YesorNo = 2; 
     } 
     else if (YesorNo == 2) 
     {    
      this -> pictureBox3 -> Visible = true; 
      this -> pictureBox3 -> Load("Outline Body Model.jpg"); 
      this -> pictureBox2 -> Visible = true; 
      this -> pictureBox2 -> Load("OutlineModel.jpg"); 
      YesorNo = 3; 
      this -> textBox1 -> Visible = true; 
      this -> textBox1 -> Text = "Name?"; 
      this -> button5 -> Visible = false; 
      this -> button4 -> Visible = false; 
      this -> label2 -> Visible = false; 

     } 
     else if (YesorNo == 5) 
     { 
      Gender = "Male"; 
      this -> label2 -> Text = "What is your Race??"; 
      this -> button4 -> Text = "Earth Pony"; 
      this -> button5 -> Text = "Unicorn"; 
      this -> button2 -> Visible = true; 
      this -> button2 -> Text = "Pegasus"; 
      YesorNo = 6; 
     } 
     else if (YesorNo == 6) 
     { 
      Race = "Earth_Pony"; 
      this -> button2 -> Visible = false; 
      this -> button4 -> Visible = false; 
      this -> button5 -> Visible = false; 
      label2 -> Text = "Thank You For Playing!!"; 
      YesorNo = 7; 
      this -> timer1 -> Start(); 
     } 
    } 

     private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) { 
     if (YesorNo == 1 || YesorNo == 2) 
     { 
      Application::Exit(); 
     } 
     else if (YesorNo == 4) 
     { 
      this -> textBox1 -> Visible = false; 
      this -> label2 -> Visible = true; 
      this -> label2 -> Text = "What Is Your Gender?"; 
      this -> button4 -> Text = "Male"; 
      this -> button5 -> Text = "Female"; 
      this -> button4 -> Visible = true; 
      this -> button5 -> Visible = true; 
      YesorNo = 5; 
     } 
     else if (YesorNo == 5) 
     { 
      Gender = "Female"; 
      this -> label2 -> Text = "What is your Race??"; 
      this -> button4 -> Text = "Earth Pony"; 
      this -> button5 -> Text = "Unicorn"; 
      this -> button2 -> Visible = true; 
      this -> button2 -> Text = "Pegasus"; 
      YesorNo = 6; 
     } 
     else if (YesorNo == 6) 
     { 
      Race = "Unicorn"; 
      this -> button2 -> Visible = false; 
      this -> button4 -> Visible = false; 
      this -> button5 -> Visible = false; 
      label2 -> Text = "Thank You For Playing!!"; 
      YesorNo = 7; 
      this -> timer1 -> Start(); 
     } 
    } 
     private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { 
      this -> button3 -> Text = "None yet"; 
    } 
      private: System::Void textBox1_TextChanged_1(System::Object^ sender, System::EventArgs^ e) { 
     this -> label1 -> Visible = true; 
     CharName = textBox1 -> Text; 
     label1 -> Text = CharName; 
     this -> button5 -> Visible = true; 
     this -> button5 -> Text = "Done?"; 
     YesorNo = 4; 
    } 
     private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { 
     TimerValue+= 1000; 
     if (TimerValue == 5000) 
     { 
      Form2^f2 = gcnew Form2; 
      f2->Show(); 
      this->Hide(); 
      MoviePlay = 1; 
      StreamWriter^ outFile = gcnew StreamWriter("Movie.txt"); 
      String^ Movie = MoviePlay.ToString(); 
      outFile->Write(Movie); 
      outFile->Close(); 
      this -> timer1 -> Stop(); 

     } 
    } 
    }; 
    } 

Почему я не могу открыть форму по 2? 2010 \ projects \ retaliation \ retaliation \ Form1.h (431): ошибка C2065: 'Form2': необъявленный идентификатор Относится к ...
Form2^f2 = gcnew Form2; в нижнем

Только в случае, если он имеет дело с проблемой в Form2 ...

#pragma once 
    #include "stdAfx.h" 
    #include "Form1.h" 
    #include "Form2.h" 
    namespace Retaliation { 

using namespace System; 
using namespace System::ComponentModel; 
using namespace System::Collections; 
using namespace System::Windows::Forms; 
using namespace System::Data; 
using namespace System::Drawing; 
using namespace std; 


/// <summary> 
/// Summary for Form2 
/// </summary> 
public ref class Form2 : public System::Windows::Forms::Form 
{ 
public: 
    int MoviePlay; 

    Form2(void) 
    { 
     InitializeComponent(); 
     // 
     //TODO: Add the constructor code here 
     // 
    } 

protected: 
    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    ~Form2() 
    { 
     if (components) 
     { 
      delete components; 
     } 
    } 
private: AxWMPLib::AxWindowsMediaPlayer^ MoviePlayer1; 
protected: 

protected: 

private: 
    /// <summary> 
    /// Required designer variable. 
    /// </summary> 
    System::ComponentModel::Container ^components; 

    #pragma region Windows Form Designer generated code 
    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    void InitializeComponent(void) 
    { 
     System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form2::typeid)); 
     this->MoviePlayer1 = (gcnew AxWMPLib::AxWindowsMediaPlayer()); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->BeginInit(); 
     this->SuspendLayout(); 
     // 
     // MoviePlayer1 
     // 
     this->MoviePlayer1->Enabled = true; 
     this->MoviePlayer1->Location = System::Drawing::Point(0, 0); 
     this->MoviePlayer1->Name = L"MoviePlayer1"; 
     this->MoviePlayer1->OcxState = (cli::safe_cast<System::Windows::Forms::AxHost::State^ >(resources- >GetObject(L"MoviePlayer1.OcxState"))); 
     this->MoviePlayer1->Size = System::Drawing::Size(860, 497); 
     this->MoviePlayer1->TabIndex = 0; 
     this->MoviePlayer1->Enter += gcnew System::EventHandler(this, &Form2::axWindowsMediaPlayer1_Enter); 
     // 
     // Form2 
     // 
     this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); 
     this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 
     this->ClientSize = System::Drawing::Size(859, 495); 
     this->Controls->Add(this->MoviePlayer1); 
     this->Name = L"Form2"; 
     this->Text = L"Form2"; 
     this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load); 
     (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->EndInit(); 
     this->ResumeLayout(false); 

    } 
    #pragma endregion 
private: System::Void axWindowsMediaPlayer1_Enter(System::Object^ sender,     System::EventArgs^ e) { 
     } 
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) { 
      if (MoviePlay == 1) 
      { 
       MoviePlayer1->URL = "\\Scv183\\Scene1.mpeg"; 
      MoviePlayer1 -> Ctlcontrols -> play(); 
      } 
     } 
}; 
    } 
+0

Не могли бы вы сократить свой код на то, что это читаемым? – nvoigt

+0

Ошибки довольно явны: 'Form1.h (431): ошибка C2065: 'Form2': необъявленный идентификатор'. Можете ли вы показать нам файл вокруг строки 431 формы Form1.h? –

+0

Как я заметил таймер в вашем коде, возможно, вы хотите взять второй и прочитать [this] (http: // stackoverflow.com/questions/16605726/how-to-make-timer-keep-runing-while-loop-wait-for-another-time-result/16606866 # 16606866) – nvoigt

ответ

0

Вы получаете сообщение об ошибке, потому что у вас есть циклическая зависимость в файлах заголовки. Ваш компилятор пытается скомпилировать Form2.cpp, где вы включаете Form1.h, в Form1.h вы включаете Form2.h, а в Form2.h вы включаете Form1.h. Вам нужно использовать форвардную декларацию или изменить свой дизайн, чтобы ваш класс был менее связан.

Кроме того, не включают в себя headerfile в себе ..

В целом, вы не должны выполнять свои функции определения в заголовочных файлах, но и использовать свои .cpp файлы для этого. Я также не думаю, что вам нужно использовать предварительно скомпилированные заголовки (stdAfx.h), вы должны отключить этот флажок при создании проекта Visual Studio.

+0

Итак, что вы рекомендуете делать, чтобы решить эту проблему? удалить Form2.cpp? – Darksly

+0

Как изменить исходный код? исходный исходный код называется Retaliation.cpp, но ищет form2.cpp – Darksly

+0

Я не понимаю ваш вопрос. –

0

Создайте новый проект. Form1 создается по умолчанию.

Создание кнопки на Form1, дважды щелкните по нему и вставьте код ниже:

Form2^ testDialog = gcnew Form2; 
testDialog->ShowDialog (this); 
delete testDialog; 

Перейти к решению исследователя, щелкните правой кнопкой мыши проект и добавить новую форму и сохранить ее как Form2.

Двойной щелчок Form1.cpp, и вы увидите, что она начинается следующими строками:

#include "stdafx.h" 
#include "Form1.h" 

Редактировать это следующим образом:

#include "stdafx.h" 
#include "Form2.h" 
#include "Form1.h" 

Примечание: Последовательность #include не должна быть изменилось.

Вперед, запустите свой проект и наслаждайтесь !!!!

  • Prasanth