wxwidgets, thread....



  • hi leute!
    ich suche ein gutes tutorial zu wxwidgets!!!!
    wie kann man dort einen thread erstellen??

    cu



  • ist ja wohl jetzt ein witz surf 🕶



  • Dieser Thread wurde von Moderator/in Gerard aus dem Forum C++ in das Forum Rund um die Programmierung verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • hab raufgefunde das ich folgendes brauche:

    wxThread::Create
    wxThreadError Run()
    

    nun die klasse dazu:

    class startWinSockConnection : public wxThread
    {
      public:
            void Thread_start();
    
    }
    

    kann jemand das helfen? hab nirgends so ein sample gefunden;-(

    cu



  • coder1 schrieb:

    kann jemand das helfen? hab nirgends so ein sample gefunden;-(

    http://www.dent.med.uni-muenchen.de/~wmglo/wxthread/CompleteExample.html

    und unter den mitgelieferten Examples ist auch ein Beispiel-Projekt...



  • danke;-) genau sowas hab ich gesucht;-)

    warum wird nach dem

    wxThread::Create();
    

    kein

    wxThread::Run
    

    aufgerufen??????

    steht ja da in der doku:
    http://www.freiburg.linux.de/~wxxt/wxHTML/wxwin360.htm

    auszug:

    wxThreadError Create()
    
    Creates a new thread. The thread object is created in the suspended state, you should call Run to start running it.
    
    Return value
    
    One of:
    
    wxTHREAD_NO_ERROR  There was no error.  
    wxTHREAD_NO_RESOURCE  There were insufficient resources to create a new thread.  
    wxTHREAD_RUNNING  The thread is already running.
    

    cu



  • in der Doku die auf der Seite verlinkt ist, ist das noch nicht der Fall:

    http://www.dent.med.uni-muenchen.de/~wmglo/wxthread/wxThread.2.html



  • #include <wx/wx.h>
    #include <wx/file.h>
    #include <wx/thread.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <ctime>
    #include <cassert>
    #include <sstream>
    
    class startWinSockConnection : public wxThread
    {
    public:
    	void Initialize()
    	{
    		  /*
    		  Creates a new thread. The thread object is created in the suspended state, you should call Run to start running it.
    		  Return value
    		  One of:
    		  wxTHREAD_NO_ERROR  There was no error.  
    		  wxTHREAD_NO_RESOURCE  There were insufficient resources to create a new thread.  
    		  wxTHREAD_RUNNING  The thread is already running. 
    		  */
    		  wxThread::Create();
                        Run();
    	}
    private:
    	virtual ExitCode Entry();
    };
    
    /*
    This is the entry point of the thread. This function is pure virtual and must be implemented by 
    any derived class. The thread execution will start here.
    The returned value is the thread exit code which is only useful for the joinable threads and is 
    the value returned by Wait.
    This function is called by wxWindows itself and should never be called directly.
    */
    
    wxThread::ExitCode startWinSockConnection::Entry()
    {
      // implement your thread calculations here
      // da wird Server gestartet usw
    
    	std::cout << "thread gestartet" << std::endl;
    
    	return 0;
    }
    
    const int ID_BUTTON_CHOOSEFILE = 1000; 
    class FileTransferServerDialog : public wxDialog
    {
    public:
    	FileTransferServerDialog(const wxChar* title, int xpos, int ypos, int width, int height)
    		: wxDialog(NULL, -1, title, wxPoint(xpos, ypos), wxSize(width, height))
    	{
    		pStaticTextFileName_ = new wxStaticText(this, -1, "Dateiname:", wxPoint(10, 10), wxSize(200, 20));
    		pStaticTextFileSize_ = new wxStaticText(this, -1, "Dateigröße:", wxPoint(10, 30), wxSize(200, 20));
    
    		pButtonChooseFile_ = new wxButton(this, ID_BUTTON_CHOOSEFILE, "Datei auswählen", wxPoint(210, 30), wxSize(90, 23));
    
    		pGaugeFileTransferProgress = new wxGauge(this, -1, NULL, wxPoint(10, 60), wxSize(300, 20), wxGA_SMOOTH);
    		pGaugeFileTransferProgress->SetRange(100);
    		pGaugeFileTransferProgress->SetValue(50);
    
    		pStaticTextFileTransferSpeed_ = new wxStaticText(this, -1, "Geschwindigkeit: 16 kb/s", wxPoint(10, 85), wxSize(200, 20));
    
    	}
    
    	void FileTransferServerDialog::onButtonChooseFile(wxCommandEvent &event)
    	{
    	wxFileDialog* pFileChooser = new wxFileDialog(this);
    
    	if(pFileChooser->ShowModal() == wxID_OK)
    	{
    			wxFile file;
    			file.Open(pFileChooser->GetPath());
    			std::ostringstream messageStream;
    			messageStream << "Dateigröße: " << file.Length();
    			pStaticTextFileName_->SetLabel(wxString("Dateiname: ") + pFileChooser->GetFilename());
    			pStaticTextFileSize_->SetLabel(messageStream.str().c_str());
    			//fileName = pFileChooser->GetPath();
    
    			// Thread starten
    			startWinSockConnection thread;
    			thread.Initialize();
    	}
    	pFileChooser->Destroy();
    	}
    private:
    	DECLARE_EVENT_TABLE();
    	wxStaticText* pStaticTextFileName_;
    	wxStaticText* pStaticTextFileSize_;
    	wxButton* pButtonChooseFile_;
    	wxGauge* pGaugeFileTransferProgress;
    	wxStaticText* pStaticTextFileTransferSpeed_;
    };
    
    BEGIN_EVENT_TABLE(FileTransferServerDialog, wxDialog)
    EVT_BUTTON(ID_BUTTON_CHOOSEFILE, FileTransferServerDialog::onButtonChooseFile)
    END_EVENT_TABLE();
    
    class FileTransferServer : public wxApp
    {
    	bool OnInit()
    	{
    		FileTransferServerDialog* pFileTransferServerDialog = new FileTransferServerDialog("File Transfer Server", 40, 40, 350, 200);
    		pFileTransferServerDialog->ShowModal();
    		pFileTransferServerDialog->Destroy();
    		return false;
    	}
    };
    
    IMPLEMENT_APP(FileTransferServer);
    

    Unbehandelte Ausnahme bei 0x004ca59a in Fenster.exe: 0xC0000005: Zugriffsverletzung-Leseposition 0xccccccd0.
    dann zeigt der debugger in thread.cpp da her:
    wxThreadState GetState() const { return m_state; }



  • return bei Entry Methode is so

    return (ExitCode) 0;
    

Anmelden zum Antworten