wxWidgets Invoke?
-
Guten Morgen,
ich habe ein wxWidgets App mit 2 Threads geschrieben. Der eine Thread macht einen Frame mit einem StaticText auf und der andere Thread soll diesen Text verändern. Leider zeigt mir das Programm nach dem zweiten ThreadStart nur noch "Keine Rückmeldung" an. Brauche ich eventuell wie auch in C# soetwas wie Invoke? Wenn ja gibt es verschiedene Möglichkeiten?
Hier mein Quellcode:
App.h:
#ifndef __App_ #define __App_ #include "StaticTextFrame.h" class App : public wxApp { public: StaticTextFrame* StaticTextFrameX; public: virtual bool OnInit(); }; DECLARE_APP(App); #endif
App.cpp:
#include <wx/wx.h> #include "App.h" #include "MainFrame.h" IMPLEMENT_APP(App); bool App::OnInit() { MainFrame* MainFrameX = new MainFrame(0L); MainFrameX->SetIcon(wxICON(MainIcon)); MainFrameX->Show(); return true; }
EditStaticTextThread.h:
#include <wx/wx.h> #include "App.h" #include "StaticTextFrame.h" class EditStaticTextThread : public wxThread { public: EditStaticTextThread() : wxThread(wxTHREAD_JOINABLE) { } void* Entry() { StaticTextFrame* StaticTextFrameX = wxGetApp().StaticTextFrameX; StaticTextFrameX->SetLabel("Hello World!"); return NULL; } };
MainFrame.h:
/////////////////////////////////////////////////////////////////////////// // C++ code generated with wxFormBuilder (version Sep 8 2010) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #ifndef __MainFrame__ #define __MainFrame__ #include <wx/wx.h> #include "App.h" #include "StaticTextFrame.h" #include "EditStaticTextThread.h" /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /// Class MainFrame /////////////////////////////////////////////////////////////////////////////// class MainFrame : public wxFrame { private: protected: wxPanel* Panel1; wxButton* Button1; wxButton* Button2; // Virtual event handlers, overide them in your derived class virtual void OnButton1Click(wxCommandEvent& event) { StaticTextFrame* StaticTextFrameX = wxGetApp().StaticTextFrameX; StaticTextFrameX = new StaticTextFrame(NULL); StaticTextFrameX->Show(); } virtual void OnButton2Click(wxCommandEvent& event) { EditStaticTextThread* EditStaticTextThreadX = new EditStaticTextThread(); EditStaticTextThreadX->Create(); EditStaticTextThreadX->Run(); EditStaticTextThreadX->Wait(); delete EditStaticTextThreadX; } public: MainFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("MainFrame"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500,300), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL); ~MainFrame(); }; #endif //__MainFrame__
MainFrame.cpp:
/////////////////////////////////////////////////////////////////////////// // C++ code generated with wxFormBuilder (version Sep 8 2010) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "MainFrame.h" /////////////////////////////////////////////////////////////////////////// MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); wxBoxSizer* BoxSizer1; BoxSizer1 = new wxBoxSizer( wxVERTICAL ); Panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* BoxSizer2; BoxSizer2 = new wxBoxSizer( wxVERTICAL ); Button1 = new wxButton( Panel1, wxID_ANY, wxT("Create StaticTextFrame"), wxDefaultPosition, wxDefaultSize, 0 ); BoxSizer2->Add( Button1, 1, wxALL|wxEXPAND, 5 ); Button2 = new wxButton( Panel1, wxID_ANY, wxT("Edit StaticText with second thread"), wxDefaultPosition, wxDefaultSize, 0 ); BoxSizer2->Add( Button2, 1, wxALL|wxEXPAND, 5 ); Panel1->SetSizer( BoxSizer2 ); Panel1->Layout(); BoxSizer2->Fit( Panel1 ); BoxSizer1->Add( Panel1, 1, wxEXPAND | wxALL, 5 ); this->SetSizer( BoxSizer1 ); this->Layout(); this->Centre( wxBOTH ); // Connect Events Button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton1Click ), NULL, this ); Button2->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton2Click ), NULL, this ); } MainFrame::~MainFrame() { // Disconnect Events Button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton1Click ), NULL, this ); Button2->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton2Click ), NULL, this ); }
StaticTextFrame.h:
/////////////////////////////////////////////////////////////////////////// // C++ code generated with wxFormBuilder (version Sep 8 2010) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #ifndef __StaticTextFrame__ #define __StaticTextFrame__ #include <wx/wx.h> /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /// Class StaticTextFrame /////////////////////////////////////////////////////////////////////////////// class StaticTextFrame : public wxFrame { private: protected: wxPanel* Panel1; wxStaticText* StaticText1; public: StaticTextFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("StaticTextFrame"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 743,402 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); ~StaticTextFrame(); }; #endif //__StaticTextFrame__
StaticTextFrame.cpp
/////////////////////////////////////////////////////////////////////////// // C++ code generated with wxFormBuilder (version Sep 8 2010) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "StaticTextFrame.h" /////////////////////////////////////////////////////////////////////////// StaticTextFrame::StaticTextFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); wxBoxSizer* BoxSizer1; BoxSizer1 = new wxBoxSizer( wxVERTICAL ); Panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* BoxSizer2; BoxSizer2 = new wxBoxSizer( wxVERTICAL ); StaticText1 = new wxStaticText( Panel1, wxID_ANY, wxT("MyLabel"), wxDefaultPosition, wxDefaultSize, 0 ); StaticText1->Wrap( -1 ); BoxSizer2->Add( StaticText1, 0, wxALL, 5 ); Panel1->SetSizer( BoxSizer2 ); Panel1->Layout(); BoxSizer2->Fit( Panel1 ); BoxSizer1->Add( Panel1, 1, wxEXPAND, 5 ); this->SetSizer( BoxSizer1 ); this->Layout(); this->Centre( wxBOTH ); } StaticTextFrame::~StaticTextFrame() { }
Mfg,
BluePhaz
-
Wieso stürzt das Programm ab?
-
*push*