wxMenuBar ausführen
-
hi
kann mir jemand helfen bei wxformbuilder .ich verstehe nicht, wie und Wo führe ich code um ausführen von MenuItem
z.b 1) Exit
2) Dialog offnenhier ist Code
Main.cpp #include <wx/wx.h> #include "main.h" /////////////////////////////////////////////////////////////////////////// Main::Main( 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 ); this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) ); wxBoxSizer* bSizer1; bSizer1 = new wxBoxSizer( wxVERTICAL ); this->SetSizer( bSizer1 ); this->Layout(); H_menubar = new wxMenuBar( 0 ); H_menubar->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_MENU ) ); file = new wxMenu(); exit = new wxMenuItem( file, wxID_ANY, wxString( wxT("Beenden") ) + wxT('\t') + wxT("Ctrl+Q"), wxEmptyString, wxITEM_NORMAL ); #ifdef __WXMSW__ exit->SetBitmaps( wxBitmap( wxT("icon/system-log-out.bmp"), wxBITMAP_TYPE_ANY ) ); #elif (defined( __WXGTK__ ) || defined( __WXOSX__ )) exit->SetBitmap( wxBitmap( wxT("icon/system-log-out.bmp"), wxBITMAP_TYPE_ANY ) ); #endif file->Append( exit ); H_menubar->Append( file, wxT("Datei") ); Datensatz = new wxMenu(); datensatz = new wxMenuItem( Datensatz, wxID_ANY, wxString( wxT("Neue Datensatz") ) + wxT('\t') + wxT("Ctrl+Q"), wxEmptyString, wxITEM_NORMAL ); #ifdef __WXMSW__ datensatz->SetBitmaps( wxBitmap( wxT("icon/edit-select-all.bmp"), wxBITMAP_TYPE_ANY ) ); #elif (defined( __WXGTK__ ) || defined( __WXOSX__ )) datensatz->SetBitmap( wxBitmap( wxT("icon/edit-select-all.bmp"), wxBITMAP_TYPE_ANY ) ); #endif Datensatz->Append( datensatz ); H_menubar->Append( Datensatz, wxT("Datensatz") ); this->SetMenuBar( H_menubar ); this->Centre( wxBOTH ); // Connect Events file->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Main::exitOnMenuSelection ), this, exit->GetId()); Datensatz->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( Main::datensatzOnMenuSelection ), this, datensatz->GetId()); } Main::~Main() { // Disconnect Events } Newdata::Newdata( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->Centre( wxBOTH ); } Newdata::~Newdata() { } class wxMyApp : public wxApp { public: virtual bool OnInit(); }; IMPLEMENT_APP(wxMyApp) bool wxMyApp::OnInit() { Main* frame=new Main(NULL); frame->Show(true); return true; }
main.h class Main : public wxFrame { private: protected: wxMenuBar* H_menubar; wxMenu* file; wxMenu* Datensatz; // Virtual event handlers, overide them in your derived class virtual void exitOnMenuSelection( wxCommandEvent& event ) { event.Skip(); } virtual void datensatzOnMenuSelection( wxCommandEvent& event ) { event.Skip(); } public: wxMenuItem* exit; wxMenuItem* datensatz; Main( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Hauptfenster"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxMAXIMIZE|wxTAB_TRAVERSAL ); ~Main(); }; /////////////////////////////////////////////////////////////////////////////// /// Class Newdata /////////////////////////////////////////////////////////////////////////////// class Newdata : public wxDialog { private: protected: public: Newdata( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Neue Datensatz"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 464,393 ), long style = wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX ); ~Newdata(); };
Danke voraus
-
Das wird doch über die "Connect Events" definiert, also in den entsprechenden "...OnMenuSelection"-Funktionen.
Wobei ich dir raten würde, die Definition in die "Main.cpp" zu verschieben (und aus der Headerdatei den Funktionsblock{ event.Skip(); }
zu löschen).
-
-
Kannst du überhaupt C++?
-
naja ich probiere mein beste zu geben