Probleme mit Benutzeroberfläche (formprojekt)



  • Vor einiger Zeit habe ich ein Konsolen-Programm geschrieben, welches die Primzahlen von 2 bis [selbstbestimmbar] ausrechnet. (siehe http://www.mediafire.com/?zxzyoxz0ayz)

    .Net Framework 3.5 muss installiert sein!

    bei Rapidshare:
    dotnetfx35.part1.rar
    http://rapidshare.com/files/115886232/dotnetfx35.part1.rar.html

    dotnetfx35.part2.rar
    http://rapidshare.com/files/115892208/dotnetfx35.part2.rar.html

    dotnetfx35.part3.rar
    http://rapidshare.com/files/115892725/dotnetfx35.part3.rar.html

    Das Programm nutzt 4 Threads (durch SDL-funktionen -> SDL.lib und SDLmain.lib müssen gelinkt sein) zum Berechnen der Primzahlen. Und gibt diese in die Dateien output1.txt, output2.txt, output3.txt und output4.txt aus und legt eine Datei namens: alle_primzahlen_geordnet.txt an. In der alle berechneten Primzahlen in der richtigen Reihenfolge und die benötigte Zeit eingetragen sind.

    Nun zu meinem Problem:

    Ich will das Programm um die Benutzeroberfläche erweitern.
    -> also habe ich mit VS2008 ein Formsprojekt erstellt und dort die Benutzeroberfläche entworfen, welche auch ausführbar ist.

    Bild:
    http://www.abload.de/img/1wxqm5.png

    SDL threads sehen wie folgt aus:

    #include stdlib.h  
    #include SDL.h  
    #include SDL_thread.h  
    
    int thread1 (void *p){ 
    while (1){ 
    //do something 
    } 
    return 0; 
    } 
    
    int thread2 (void *p){ 
    while (1){ 
    //do something 
    } 
    return 0; 
    } 
    
    int main (void){ 
    SDL_Thread *t1, *t2; 
    t1 = SDL_CreateThread (thread1, NULL); 
    t2 = SDL_CreateThread (thread2, NULL); 
    SDL_Delay (2000); 
    SDL_KillThread (t1); 
    SDL_KillThread (t2); 
    SDL_Quit (); 
    return 0; 
    }
    

    alle nötige header sind includiert und die nötigen .lib dateien gelinkt.
    ich bekomme in der 4. Zeile einen fehler

    int thread1 (void *p); 
    public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
    SDL_Thread *t1, *t2, *t3, *t4; 
    t1 = SDL_CreateThread (thread1, NULL); 
    
    ...
    

    Error 1 error C3867: 'prim3_2_mit_benutzeroberflaeche::Form1::thread1': function call missing argument list; use '&prim3_2_mit_benutzeroberflaeche::Form1::thread1' to create a pointer to member g:\studium relevant\informatik\projekte\prim3_2_mit_benutzeroberflaeche\prim3_2_mit_benutzeroberflaeche\Form1.h 349 prim3_2_mit_benutzeroberflaeche

    wenn ich das mache:
    t1 = SDL_CreateThread (&thread1, NULL);

    kommt:
    Error 1 error C2276: '&' : illegal operation on bound member function expression g:\studium relevant\informatik\projekte\prim3_2_mit_benutzeroberflaeche\prim3_2_mit_benutzeroberflaeche\Form1.h 349 prim3_2_mit_benutzeroberflaeche

    PS: eingabe und ausgabe funktioniert schon _

    a = Convert::ToInt32(this->textBox1->Text); 
    this->listBox1->Items->Add(Convert::ToString(y));
    


  • ich hab nun die thread funktionen global definiert aber da bringt er mir:

    Error 1 error C2673: 'thread1' : global functions do not have 'this' pointers g:\studium relevant\informatik\projekte\prim3_2_mit_benutzeroberflaeche\prim3_2_mit_benutzeroberflaeche\stdafx.h

    weil die funktionen was in ner listbox ausgeben sollen

    this->listBox1->Items->Add(Convert::ToString(y));
    

    gibt es noch eine andere möglichkeit was in die listbox schreiben ??



  • Wie wäre es wenn du dir mal die Verwendung von System::Threading::Thread anschaust 😉

    SDL_Thread ist nicht grad wirklich die passende Lösung wenn du mit .NET arbeitest 🙂

    BR
    Vinzenz



  • danke !!

    hab ne testanwendung mit 2 listboxen + 1 button geschrieben
    diese hat auch problemlos funktioniert

    als ich das in meinem richtigen projekt implementiert hatte

    kam folgende fehlermeldung:

    Error 1 error C2248: 'System::Windows::Forms::Control::y' : cannot access private member declared in class 'System::Windows::Forms::Control'

    aber die methoden sind doch unter public:

    ich denke es liegt daran, das die variablen in der testanwendung im schleifenkopf initialisiert werden, während sie in meinem Projekt global definiert sind

    testanwendung mit den methoden zahlen1 und zahlen2
    im projekt steht dort

    void thread1()
    	{
    	while (y<=a)
    		{...
    

    testanwendung
    Form1.h:

    #pragma once
    
    namespace threadklasse {
    
    	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;
    
    	/// <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
    			//
    		}
    
    		void zahlen1()
    				{
    					for ( int a = 0; a < 10; a++ )
    					{
    					listBox1->Items->Add(Convert::ToString(a));
    
    					}
    				}
    
    		void zahlen2()
    				{
    					for ( int b = 10; b < 20; b++ )
    					{
    					listBox2->Items->Add(Convert::ToString(b));
    
    					}
    				}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	public: System::Windows::Forms::ListBox^  listBox1;
    	protected: 
    	private: System::Windows::Forms::Button^  button1;
    	public: System::Windows::Forms::ListBox^  listBox2;
    
    	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->listBox1 = (gcnew System::Windows::Forms::ListBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->listBox2 = (gcnew System::Windows::Forms::ListBox());
    			this->SuspendLayout();
    			// 
    			// listBox1
    			// 
    			this->listBox1->FormattingEnabled = true;
    			this->listBox1->Location = System::Drawing::Point(35, 24);
    			this->listBox1->Name = L"listBox1";
    			this->listBox1->Size = System::Drawing::Size(71, 108);
    			this->listBox1->TabIndex = 0;
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(87, 188);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(89, 30);
    			this->button1->TabIndex = 1;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// listBox2
    			// 
    			this->listBox2->FormattingEnabled = true;
    			this->listBox2->Location = System::Drawing::Point(159, 24);
    			this->listBox2->Name = L"listBox2";
    			this->listBox2->Size = System::Drawing::Size(71, 108);
    			this->listBox2->TabIndex = 2;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(284, 264);
    			this->Controls->Add(this->listBox2);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->listBox1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    
    				 Thread^ aThread = gcnew Thread( gcnew ThreadStart( this,&Form1::zahlen1 ) );
    				 Thread^ bThread = gcnew Thread( gcnew ThreadStart( this,&Form1::zahlen2 ) );
    
    				 aThread->Start();
    				 bThread->Start();
    
    			 }
    	};
    
    }
    


  • so ich hab mal meine testanwendung modifiziert und die schleifen abhängig von einer globalen eingabevariablen gemacht.

    wenn die globalen variablen mit static declariert werden funktioniert die anwendung

    -> d.h. in meinem projekt sind aus irgend einem grund die variablen für irgendeine klasse private declariert und somit für mich nicht nutzbar

    declariert habe ich die variablen in stdafx.h

    static unsigned int a,y =0;
    


  • habs hingekriegt 🙂


Anmelden zum Antworten