Klasse wo aufrufen?

snowleopard

Grünschnabel
Hallo!
Ich hab mich vor kurzem mit Visual c++ angefreundet und
bin nun auf mein erstes problem gestoßen:
ich will eine klasse mit

ClientSocket* sockClient = new ClientSocket;

"global" in einem MDI-child aufrufen. Ohne MDI-child konnte ich
dies einfach an einer stelle im quellcode definieren (siehe ROT).:confused:

funktionieren tuts auch alles wenn ich den oben besagten quellcodeschnipsel
direkt an der stelle ganz unten (siehe GRÜN) einfüge, dann jedoch ist die funktion
nur für den button verfügbar und nicht für andere buttons.


nun die sicherlich lächerliche frage (hey ich bin erst ne woche dabei^^)
wie muss ich den quellcodeschnipsel einfügen damit ich auch mit anderen
buttons auf die funktionen der klasse zugreifen kann? =)

würde mich tierisch über hilfe freuen, fettes mauz!


Code:
#pragma once

#include "Socket.h"
#include "WinSock2.h"

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::Threading; // für timer
using namespace System::Runtime::InteropServices;//Für Marshal



namespace snowleopard {

bisher hier definiert

	/// <summary>
	/// Zusammenfassung für P2Pmailer
	///
	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
	///          arbeiten, die diesem Formular zugewiesen sind.
	/// </summary>

	public ref class P2Pmailer : public System::Windows::Forms::Form
	{
	public:
		
		P2Pmailer(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		~P2Pmailer()
		{
			if (components)
			{
				delete components;
			}
		}

	private: System::Windows::Forms::Label^  lb_Port2;
	protected: 
	private: System::Windows::Forms::Label^  lp_IP;
	private: System::Windows::Forms::Label^  lb_Port1;
	private: System::Windows::Forms::TextBox^  tb_Port;
	private: System::Windows::Forms::TextBox^  tb_IP;
	private: System::Windows::Forms::Button^  bt_ping;
	private: System::Windows::Forms::Button^  bt_verbindung_trennen;
	private: System::Windows::Forms::Label^  lb_status;
	private: System::Windows::Forms::Label^  lb_EventX;
	private: System::Windows::Forms::TextBox^  tb_Daten;
	private: System::Windows::Forms::Button^  bt_senden;
	private: System::Windows::Forms::TextBox^  tb_Eingabe;
	private: System::Windows::Forms::TextBox^  tb_PortServer;
	private: System::Windows::Forms::Button^  bt_client_start;
	private: System::Windows::Forms::Button^  bt_server_start;

	protected: 

	protected: 

	private:
		/// <summary>
		/// Erforderliche Designervariable.
		/// </summary>
		System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// </summary>
		
		void InitializeComponent(void)
		{
			this->lb_Port2 = (gcnew System::Windows::Forms::Label());
			this->lp_IP = (gcnew System::Windows::Forms::Label());
			this->lb_Port1 = (gcnew System::Windows::Forms::Label());
			this->tb_Port = (gcnew System::Windows::Forms::TextBox());
			this->tb_IP = (gcnew System::Windows::Forms::TextBox());
			this->bt_ping = (gcnew System::Windows::Forms::Button());
			this->bt_verbindung_trennen = (gcnew System::Windows::Forms::Button());
			this->lb_status = (gcnew System::Windows::Forms::Label());
			this->lb_EventX = (gcnew System::Windows::Forms::Label());
			this->tb_Daten = (gcnew System::Windows::Forms::TextBox());
			this->bt_senden = (gcnew System::Windows::Forms::Button());
			this->tb_Eingabe = (gcnew System::Windows::Forms::TextBox());
			this->tb_PortServer = (gcnew System::Windows::Forms::TextBox());
			this->bt_client_start = (gcnew System::Windows::Forms::Button());
			this->bt_server_start = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// lb_Port2
			// 
			this->lb_Port2->AutoSize = true;
			this->lb_Port2->Location = System::Drawing::Point(328, 44);
			this->lb_Port2->Name = L"lb_Port2";
			this->lb_Port2->Size = System::Drawing::Size(29, 13);
			this->lb_Port2->TabIndex = 12;
			this->lb_Port2->Text = L"Port:";
			// 
			// lp_IP
			// 
			this->lp_IP->AutoSize = true;
			this->lp_IP->Location = System::Drawing::Point(337, 18);
			this->lp_IP->Name = L"lp_IP";
			this->lp_IP->Size = System::Drawing::Size(20, 13);
			this->lp_IP->TabIndex = 11;
			this->lp_IP->Text = L"IP:";
			// 
			// lb_Port1
			// 
			this->lb_Port1->AutoSize = true;
			this->lb_Port1->Location = System::Drawing::Point(11, 18);
			this->lb_Port1->Name = L"lb_Port1";
			this->lb_Port1->Size = System::Drawing::Size(29, 13);
			this->lb_Port1->TabIndex = 13;
			this->lb_Port1->Text = L"Port:";
			// 
			// tb_Port
			// 
			this->tb_Port->Location = System::Drawing::Point(366, 45);
			this->tb_Port->Name = L"tb_Port";
			this->tb_Port->Size = System::Drawing::Size(47, 20);
			this->tb_Port->TabIndex = 17;
			this->tb_Port->Text = L"666";
			// 
			// tb_IP
			// 
			this->tb_IP->Location = System::Drawing::Point(366, 19);
			this->tb_IP->Name = L"tb_IP";
			this->tb_IP->Size = System::Drawing::Size(123, 20);
			this->tb_IP->TabIndex = 16;
			this->tb_IP->Text = L"192.168.2.105";
			// 
			// bt_ping
			// 
			this->bt_ping->Location = System::Drawing::Point(174, 61);
			this->bt_ping->Name = L"bt_ping";
			this->bt_ping->Size = System::Drawing::Size(111, 23);
			this->bt_ping->TabIndex = 25;
			this->bt_ping->Text = L"ping feststellen";
			this->bt_ping->UseVisualStyleBackColor = true;
			this->bt_ping->Visible = false;
			// 
			// bt_verbindung_trennen
			// 
			this->bt_verbindung_trennen->Location = System::Drawing::Point(175, 32);
			this->bt_verbindung_trennen->Name = L"bt_verbindung_trennen";
			this->bt_verbindung_trennen->Size = System::Drawing::Size(110, 23);
			this->bt_verbindung_trennen->TabIndex = 24;
			this->bt_verbindung_trennen->Text = L"verbindung trennen";
			this->bt_verbindung_trennen->UseVisualStyleBackColor = true;
			this->bt_verbindung_trennen->Visible = false;
			// 
			// lb_status
			// 
			this->lb_status->AutoSize = true;
			this->lb_status->Location = System::Drawing::Point(172, 16);
			this->lb_status->Name = L"lb_status";
			this->lb_status->Size = System::Drawing::Size(71, 13);
			this->lb_status->TabIndex = 23;
			this->lb_status->Text = L"Status: offline";
			// 
			// lb_EventX
			// 
			this->lb_EventX->AutoSize = true;
			this->lb_EventX->BackColor = System::Drawing::Color::Red;
			this->lb_EventX->Font = (gcnew System::Drawing::Font(L"Arial", 48, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->lb_EventX->Location = System::Drawing::Point(21, 79);
			this->lb_EventX->Name = L"lb_EventX";
			this->lb_EventX->Size = System::Drawing::Size(75, 75);
			this->lb_EventX->TabIndex = 22;
			this->lb_EventX->Text = L"X";
			this->lb_EventX->Visible = false;
			// 
			// tb_Daten
			// 
			this->tb_Daten->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->tb_Daten->Location = System::Drawing::Point(17, 157);
			this->tb_Daten->MaxLength = 100;
			this->tb_Daten->Multiline = true;
			this->tb_Daten->Name = L"tb_Daten";
			this->tb_Daten->ReadOnly = true;
			this->tb_Daten->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->tb_Daten->Size = System::Drawing::Size(452, 140);
			this->tb_Daten->TabIndex = 20;
			// 
			// bt_senden
			// 
			this->bt_senden->Location = System::Drawing::Point(419, 303);
			this->bt_senden->Name = L"bt_senden";
			this->bt_senden->Size = System::Drawing::Size(50, 23);
			this->bt_senden->TabIndex = 19;
			this->bt_senden->Text = L"senden";
			this->bt_senden->UseVisualStyleBackColor = true;
			this->bt_senden->Visible = false;
			// 
			// tb_Eingabe
			// 
			this->tb_Eingabe->Location = System::Drawing::Point(17, 303);
			this->tb_Eingabe->Name = L"tb_Eingabe";
			this->tb_Eingabe->Size = System::Drawing::Size(396, 20);
			this->tb_Eingabe->TabIndex = 18;
			this->tb_Eingabe->Visible = false;
			// 
			// tb_PortServer
			// 
			this->tb_PortServer->Location = System::Drawing::Point(49, 19);
			this->tb_PortServer->Name = L"tb_PortServer";
			this->tb_PortServer->Size = System::Drawing::Size(73, 20);
			this->tb_PortServer->TabIndex = 21;
			this->tb_PortServer->Text = L"666";
			// 
			// bt_client_start
			// 
			this->bt_client_start->Location = System::Drawing::Point(419, 42);
			this->bt_client_start->Name = L"bt_client_start";
			this->bt_client_start->Size = System::Drawing::Size(70, 23);
			this->bt_client_start->TabIndex = 26;
			this->bt_client_start->Text = L"client start";
			this->bt_client_start->UseVisualStyleBackColor = true;
			// 
			// bt_server_start
			// 
			this->bt_server_start->Location = System::Drawing::Point(43, 42);
			this->bt_server_start->Name = L"bt_server_start";
			this->bt_server_start->Size = System::Drawing::Size(79, 23);
			this->bt_server_start->TabIndex = 27;
			this->bt_server_start->Text = L"server start";
			this->bt_server_start->UseVisualStyleBackColor = true;
			this->bt_server_start->Click += gcnew System::EventHandler(this, &P2Pmailer::bt_server_start_Click);
			// 
			// P2Pmailer
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(506, 343);
			this->Controls->Add(this->bt_client_start);
			this->Controls->Add(this->bt_server_start);
			this->Controls->Add(this->tb_Port);
			this->Controls->Add(this->tb_IP);
			this->Controls->Add(this->bt_ping);
			this->Controls->Add(this->bt_verbindung_trennen);
			this->Controls->Add(this->lb_status);
			this->Controls->Add(this->lb_EventX);
			this->Controls->Add(this->tb_Daten);
			this->Controls->Add(this->bt_senden);
			this->Controls->Add(this->tb_Eingabe);
			this->Controls->Add(this->tb_PortServer);
			this->Controls->Add(this->lb_Port2);
			this->Controls->Add(this->lp_IP);
			this->Controls->Add(this->lb_Port1);
			this->MaximizeBox = false;
			this->MinimumSize = System::Drawing::Size(200, 360);
			this->Name = L"P2Pmailer";
			this->Text = L"P2Pmailer";
			this->ResumeLayout(false);
			this->PerformLayout();

			
		}
#pragma endregion

	private: System::Void bt_server_start_Click(System::Object^  sender, System::EventArgs^  e) 
			 {
HIER GEHTS, ABER HALT NUR FÜR DEN BUTTON!
				tb_Daten->AppendText("SYSTEM >> Hosting... \r\n");

				int port=Convert::ToInt32(tb_PortServer->Text);
				sockClient->StartHosting(port);
				
				//unbenutzbar machen:
				tb_IP->ReadOnly="True";
				tb_Port->ReadOnly="True";
				tb_PortServer->ReadOnly="True";
				//benutzbar machen:
				bt_senden->Visible="True";
				bt_verbindung_trennen->Visible="True";
				tb_Eingabe->Visible="True";
				lb_EventX->Visible="True";
				bt_ping->Visible="True";
				lb_status->Text="Status: online";

				tb_Daten->AppendText("SYSTEM >> Verbindung hergestellt\r\n"); //leitet zudem backgroundworker ein
			 }
};
}
 
Zurück