I'm pretty new to wxWidgets, and I have a simple problem with events.
How can I add event and function to button from other than main classs. In code below i marked the problem button
My project looks like that :
Code: Select all
//----------------------------------------BEGIN stdwx.h----------------------------------------
#ifndef STDWX_H
#define STDWX_H
#include <wx/wxprec.h>
//#include "..\_wx_intellisense.h"
#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/button.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/filedlg.h>
#endif
//----------------------------------------END stdwx.h----------------------------------------
//----------------------------------------BEGIN guipageki.h----------------------------------------
#ifndef GUIPAGEKI_H
#define GUIPAGEKI_H
class pageKI : public wxNotebookPage
{
private:
wxStaticText *KIstatictextFname;
wxTextCtrl *KItextctrlFname;
wxStaticText *KIstatictextStream;
wxTextCtrl *KItextctrlStream;
//_************************************* P R O B L E M BU T T O N**************************************
wxButton *ex_Button; //_HOW ADD EVENT
//void On_ex_Button(wxCommandEvent& event); //and IT's FUNCTION ETC. FOR THAT BUTTON
//_**********************************************************************************************
public:
pageKI(wxWindow * parent, wxString fname = "", wxString stream = "");
};
enum
{
ex__Button2=11054,
ex__Button3
};
#endif
//----------------------------------------END guipageki.h----------------------------------------
//----------------------------------------BEGIN guipageki.cpp----------------------------------------
#include "stdwx.h"
#include "guipageki.h"
pageKI::pageKI(wxWindow * parent, wxString fname, wxString stream):wxNotebookPage(parent, wxID_ANY)
{
KIstatictextFname = new wxStaticText(this, wxID_ANY,_T("nazwa pliku"),wxPoint(10,10));
KItextctrlFname = new wxTextCtrl(this,wxID_ANY,fname,wxPoint(10,30),wxSize(730,20));
KIstatictextStream = new wxStaticText(this, wxID_ANY,_T("konfiguracja"),wxPoint(10,50));
KItextctrlStream = new wxTextCtrl(this,wxID_ANY,stream,wxPoint(10,70),wxSize(730,20));
//_**********************************************************************************************
//_HOW ADD EVENT and IT's FUNCTION ETC. FOR THAT BUTTON
ex_Button = new wxButton(this, ex__Button2, "cuss", wxPoint(100,0));
//_**********************************************************************************************
}
//----------------------------------------END guipageki.cpp----------------------------------------
//----------------------------------------BEGIN guimain.h----------------------------------------
#ifndef GUIMAIN_H
#define GUIMAIN_H
class MyApp : public wxApp
{
public: virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, int xpos, int ypos, int width, int height);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnMybutton(wxCommandEvent& event);
private:
wxNotebook *scaNotebook;
wxButton *KIbuttonLoad;//for that button everything is clear
wxNotebookPage *KIpage;
wxNotebook *KInotebook;
DECLARE_EVENT_TABLE()
};
enum
{
Minimal_Quit = wxID_EXIT,
sca_notebook,
KI_page,
KI_buttonLoad,
KI_notebook,
Minimal_About = wxID_ABOUT,
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
EVT_BUTTON(KI_buttonLoad, MyFrame::OnMybutton)
END_EVENT_TABLE()
#endif
// ---------------------------------------- END guimain.h ----------------------------------------
// ----------------------------------------BEGIN guimain.cpp ----------------------------------------
#include "stdwx.h"
#if !defined(__WXMSW__) && !defined(__WXPM__)
#include "../sample.xpm"
#endif
#include "guipageki.h"
#include "guimain.h"
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("SCA gui"), 5,50,800,600 );
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title, int xpos, int ypos, int width, int height)
: wxFrame(NULL, wxID_ANY, title, wxPoint(xpos, ypos), wxSize(width,height))
{
SetIcon(wxICON(sample));
#if wxUSE_MENUS
wxMenu *fileMenu = new wxMenu; wxMenu *helpMenu = new wxMenu; helpMenu->Append(Minimal_About, _T("&O programie...\tF1"), _T("Wyświetla informacje o programie")); fileMenu->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Wyjście z programu")); wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(fileMenu, _T("&Plik")); menuBar->Append(helpMenu, _T("&Pomoc")); SetMenuBar(menuBar);
#endif // wxUSE_MENUS
#if wxUSE_STATUSBAR
CreateStatusBar(2); SetStatusText(_T("Zapraszam!"));
#endif // wxUSE_STATUSBAR
scaNotebook = new wxNotebook(this,sca_notebook, wxPoint(10,10), wxSize(200,100));
KIpage = new wxNotebookPage( scaNotebook, KI_page);
KIbuttonLoad = new wxButton(KIpage, KI_buttonLoad, _T("ładuj"), wxPoint( 10, 10), wxSize(100,20));
KInotebook = new wxNotebook(KIpage, KI_notebook, wxPoint(10,50), wxSize(760,130));
scaNotebook->AddPage(KIpage,_T("ki"));
}
void MyFrame::OnMybutton(wxCommandEvent& WXUNUSED(event))
{
wxString filename = wxFileSelector("Wybierz konfiguracje inicjującą");
if(!filename.empty())
{
pageKI * npki = new pageKI(KInotebook);
KInotebook->AddPage(npki,"0");
}
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)){ Close(true); }
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxString msg;
msg.Printf( _T("Autorem programu jest Andrzej Wawrzyniak\n")
_T("\n\tPowered by %s"), wxVERSION_STRING);
wxMessageBox(msg, _T("O programie SCA"), wxOK | wxICON_INFORMATION, this);
}
// ----------------------------------------END guimain.cpp ----------------------------------------