CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    448

    [RESOLVED] How to check on menu item in a dialog?

    Hi guys,

    I would like you to help me. I have figure out that I will get the errors of 'Form2' : undeclared identifier as if I included the "#include Form1.h" on the top of the Form2 class while I have the "#include Form2.h" on the top of the Form1 header.

    This is how I found the problem to get it solve, if I remove the "#include Form2.h" on the top of the Form1 header, the problem would solve but I cannot open the form2 dialog.

    What I am trying to do is to open the form2 dialog and check on the Form1 menu items that if any of the menu items checked is set to true or false then do something.

    Please can you help me to get this solution as I find it very difficult to deals with?

    Thanks,
    Mark
    Last edited by mark103; April 9th, 2011 at 11:17 AM.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to check on menu item in a dialog?

    If you really have a line reading

    Code:
    #include Form2.h
    in your code the error message is no surprise. Of course that would need to be:

    Code:
    #include "Form2.h"
    But maybe this was a transcription error while writing the post.

    If it's not that, it most likely is the "circular inclusion" problem. It's quite common and has been discussed around here in a lot of threads. You can find them using a forum search for "circular inclusion" or "mutual inclusion".

    Aside from that, your post suspiciously looks as if you're using C++/CLI which is discussed in a different section. In particular, there are some specifics about the circular inclusion problem in C++/CLI (related to how the IDE sets up the projects) so the (fewer) threads about that in the C++/CLI section may be particularly helpful.

    Checking menu items on another form seems to be a secondary issue as of now and I suggest to postpone this until you got the above sorted out.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Aug 2007
    Posts
    448

    Re: How to check on menu item in a dialog?

    Hello Eri523,

    Sorry for the delaying in my response as I was on vacation. However, yes I have included the #include "Form2.h" in my form1 header and #include "Form1.h" in the form2 header. I can't find a way to get solution, as I took my research and I doesn't find any answers.


    If you would need to see my form1 and my form2 code, so here it is:


    Form1:

    Code:
    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    #include "Form2.h"
    
    
    namespace Test {
    
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		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::Button^  button1;
    	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)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(73, 84);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(133, 62);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
                                 Form2^ form2 = gcnew Form2();
                                 form2->showdialog(this);
    			 }
    	};
    }

    Form2:

    Code:
    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    
    #include "Form1.h"
    
    
    namespace Test {
    
    	/// <summary>
    	/// Summary for Form2
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form2 : public System::Windows::Forms::Form
    	{
    	public:
    		Form2(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form2()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	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)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(73, 84);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(133, 62);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// Form2
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form2";
    			this->Text = L"Form2";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                               Form1^ form1 = gcnew Form1();
                               if (form1->menuitems->checked == true)
                               {
                                 'do something
                                }
    			 }
    	};
    }

    Hope you can help me with this.

    Thanks,
    Mark

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How to check on menu item in a dialog?

    You may want to try a .net forum. This is for Visual C++ and MFC without .net

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to check on menu item in a dialog?

    The button click handler in Form2 is the only place in that form where you reference Form1. So, as a minimum solution, move the button click handler's implementation into the Form2.cpp file. I suppose the IDE has created one for you, at least VC++ 2010 does that. If not, simply create it yourself. You then can move the #include "Form1.h" directive to the .cpp file as well.

    If you have any more questions about C++/CLI, whether about doing the above or otherwise, please post them in the C++/CLI section.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How to check on menu item in a dialog?

    [ Moved thread ]
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  7. #7
    Join Date
    Aug 2007
    Posts
    448

    Re: How to check on menu item in a dialog?

    Quote Originally Posted by Eri523 View Post
    The button click handler in Form2 is the only place in that form where you reference Form1. So, as a minimum solution, move the button click handler's implementation into the Form2.cpp file. I suppose the IDE has created one for you, at least VC++ 2010 does that. If not, simply create it yourself. You then can move the #include "Form1.h" directive to the .cpp file as well.

    If you have any more questions about C++/CLI, whether about doing the above or otherwise, please post them in the C++/CLI section.
    That doesn't really much helping, because I have tried it but still get the same error so no difference. I would appreciate if you could post the code so hopefully my problem would solve there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured