3 Replies - 2670 Views - Last Post: 14 October 2008 - 06:21 AM

#1 Sarcalogos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 08

Making my Form open another program

Post icon  Posted 12 October 2008 - 11:18 PM

I am new to Dream in Code and C++, and I am trying to start out with something easy.
I am a gamer, I play World of Warcraft, so I wanted to make a Windows Form Application first instead of making a Win32 Application because the forms seemed easier to me. What I am trying to do is make my form have 2 buttons. 1 that opens World of Warcraft, and 1 that closes the form.

Here is my code...
#pragma once


namespace WoW {

	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
	///
	/// 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: System::Windows::Forms::Button^  button2;


	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(Form1::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Font = (gcnew System::Drawing::Font(L"Footlight MT Light", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button1->Location = System::Drawing::Point(179, 107);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(81, 30);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Play WoW";
			this->button1->UseVisualStyleBackColor = true;
			// 
			// button2
			// 
			this->button2->Font = (gcnew System::Drawing::Font(L"Footlight MT Light", 11.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button2->Location = System::Drawing::Point(266, 107);
			this->button2->Name = L"button2";
			this->button2->Size = System::Drawing::Size(81, 30);
			this->button2->TabIndex = 1;
			this->button2->Text = L"Get a Life";
			this->button2->UseVisualStyleBackColor = true;
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->ClientSize = System::Drawing::Size(359, 140);
			this->Controls->Add(this->button2);
			this->Controls->Add(this->button1);
			this->MaximizeBox = false;
			this->MaximumSize = System::Drawing::Size(375, 176);
			this->MinimumSize = System::Drawing::Size(375, 176);
			this->Name = L"Form1";
			this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->ResumeLayout(false);

		}
#pragma endregion
	};
}




The cool thing about Microsoft Visual C++, is that it will give you a list of possible functions when editing the code.

All I can get is
this->button1->onclick =



Then I am not really sure what to put next.
Can anyone help?
Thanks in advanced! :)

This post has been edited by Sarcalogos: 12 October 2008 - 11:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Making my Form open another program

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Making my Form open another program

Posted 13 October 2008 - 04:35 AM

The easiest way to do this is through the UI. If you go to the form and double-click on the button, it will add the necessary onclick delegate and put you in a generated event handler method where you can add your code:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
    // Your code here
}

Was This Post Helpful? 0
  • +
  • -

#3 Sarcalogos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 12-October 08

Re: Making my Form open another program

Posted 13 October 2008 - 10:51 PM

Alright... I sort of understand. Again, I am still new to C++.
So, where it says

{
	// Your Code here
}



Is that where I put the code to make it open the program?
But now what do I put there to make it locate and access the program

This post has been edited by Sarcalogos: 13 October 2008 - 11:13 PM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Making my Form open another program

Posted 14 October 2008 - 06:21 AM

Yes, that's correct.

Look in MSDN at the System.Diagnostics.Process class.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1