I'm trying to write a program which will generate templates in html..
I try to make a menu in visual c++, rest of code was written in c++ (console).
so I have 2 problems...

1st PROBLEM
I designed nice clean menu with drop-down menu containing 3 options
AVAILABILITY
DEGRADATION
UNAVAILABILITY
Now, I need to clean whole window,close that form and open another form in a place of first - just to start a sub program..It should vork like void command in console c++..you choose option and from menu, and you can write what that option should do.
I need to do that, because each option will have diffrent components at window, and will do diffrent things.

2nd PROBLEM
Is it hard to add normal C++ (non-windows/console) code to my form based program?..My windows/form based menu is used only to gather informations as a variables in a more frendly way...Working on these variables should be done in console (can be invisble)..This i mainly work on strings and files...Program will replace words in html file with the ones provided by user in Form/windows part of the program.
THX!

my code is:

#pragma once

#include "resource.h"

namespace Templater2 {
	
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </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::MenuStrip^  menuStrip1;
	protected: 
	private: System::Windows::Forms::ToolStripMenuItem^  availabilityToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  availabilityToolStripMenuItem1;
	private: System::Windows::Forms::ToolStripMenuItem^  degradationToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  unavailabilityToolStripMenuItem;


	protected: 



	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->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->availabilityToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->availabilityToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->degradationToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->unavailabilityToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->menuStrip1->SuspendLayout();
			this->SuspendLayout();
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->availabilityToolStripMenuItem});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(630, 24);
			this->menuStrip1->TabIndex = 0;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// availabilityToolStripMenuItem
			// 
			this->availabilityToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {this->availabilityToolStripMenuItem1, 
				this->degradationToolStripMenuItem, this->unavailabilityToolStripMenuItem});
			this->availabilityToolStripMenuItem->Name = L"availabilityToolStripMenuItem";
			this->availabilityToolStripMenuItem->Size = System::Drawing::Size(56, 20);
			this->availabilityToolStripMenuItem->Text = L"Impact";
			// 
			// availabilityToolStripMenuItem1
			// 
			this->availabilityToolStripMenuItem1->Name = L"availabilityToolStripMenuItem1";
			this->availabilityToolStripMenuItem1->Size = System::Drawing::Size(152, 22);
			this->availabilityToolStripMenuItem1->Text = L"Availability";
			this->availabilityToolStripMenuItem1->Click += gcnew System::EventHandler(this, &Form1::availabilityToolStripMenuItem1_Click);
			// 
			// degradationToolStripMenuItem
			// 
			this->degradationToolStripMenuItem->Name = L"degradationToolStripMenuItem";
			this->degradationToolStripMenuItem->Size = System::Drawing::Size(152, 22);
			this->degradationToolStripMenuItem->Text = L"Degradation";
			// 
			// unavailabilityToolStripMenuItem
			// 
			this->unavailabilityToolStripMenuItem->Name = L"unavailabilityToolStripMenuItem";
			this->unavailabilityToolStripMenuItem->Size = System::Drawing::Size(152, 22);
			this->unavailabilityToolStripMenuItem->Text = L"Unavailability";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(630, 409);
			this->Controls->Add(this->menuStrip1);
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"Templater 1.0";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {			 }
	private: System::Void availabilityToolStripMenuItem1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
};
}

This is not c++ -- it is CLR/C++ which is another language that was derived from c++. And yes, it is very easy to add the console code to the CLR project -- call the code in the button or menu event handler. The console code won't be able to use cout or cin because there is no console window, but otherwise all other code should work ok.

As for your first question, you have to create another form, say Form2, then display that form in the menu event handler.

private: System::Void availabilityToolStripMenuItem1_Click(System::Object^  sender, System::EventArgs^  e) {			 

     Form2^ f2 = gcnew Form2;   // allocate memory for Form2
     this->Hide();      // hide Form1
     f2->ShowDialog();  // run Form2
     this->Show();      // after Form2 finishes, show Form1 again

}

Edited 5 Years Ago by Ancient Dragon: n/a

This is not c++ -- it is CLR/C++ which is another language that was derived from c++. And yes, it is very easy to add the console code to the CLR project -- call the code in the button or menu event handler. The console code won't be able to use cout or cin because there is no console window, but otherwise all other code should work ok.

As for your first question, you have to create another form, say Form2, then display that form in the menu event handler.

private: System::Void availabilityToolStripMenuItem1_Click(System::Object^  sender, System::EventArgs^  e) {			 

     Form2^ f2 = gcnew Form2;   // allocate memory for Form2
     this->Hide();      // hide Form1
     f2->ShowDialog();  // run Form2
     this->Show();      // after Form2 finishes, show Form1 again

}

Ok...I recive som errors:
I've added #include "form2.h" after #pragma once lin, but it doesnt help
error messages:

Error	3	error C2011: 'Templater2::Form1' : 'class' type redefinition	c:\users\vasquez\documents\visual studio 2010\projects\templater2\templater2\Form1.h	19	1	Templater2
Error	1	error C2039: 'form2' : is not a member of 'Templater2::Form1'	c:\users\vasquez\documents\visual studio 2010\projects\templater2\templater2\Form2.h	132	1	Templater2
Error	2	error C2228: left of '.show' must have class/struct/union	c:\users\vasquez\documents\visual studio 2010\projects\templater2\templater2\Form2.h	132	1	Templater2

Sorry for bothering you, but i couldnt find any help on the inrernet...I have no info how to do it @ my books neither.

Thank you mate!
now it works...
I'm glad you could help me...VC++ isnt so easy as I thought :/...and its hard to find good tutorials on the internet...
Anyway once again, thank you, I owe you big beer :)

This article has been dead for over six months. Start a new discussion instead.