#ifndef __CUSTOM_EVENT_H__ #define __CUSTOM_EVENT_H__ #include //*************** // wxCustomEvent //*************** class wxCustomEvent : public wxCommandEvent { public: wxCustomEvent( wxEventType type = wxEVT_NULL, int id = 0 ); wxCustomEvent( const wxCustomEvent& event ); virtual wxEvent* Clone() const; private: DECLARE_DYNAMIC_CLASS( wxCustomEvent ); }; typedef void (wxEvtHandler::*CustomEventFunction)( wxCustomEvent& ); static const wxEventType wxCUSTOM_EVENT_TYPE = 24000; static const int wxCUSTOM_TEST = 24001; #define EVT_CUSTOM_TEST(id, fn) \ DECLARE_EVENT_TABLE_ENTRY( \ wxCUSTOM_EVENT_TYPE, id, -1, \ (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)\ wxStaticCastEvent( CustomEventFunction, &fn ), \ (wxObject *) NULL ), //********* // TestApp //********* class TestApp : public wxApp { public: bool OnInit(); }; DECLARE_APP( TestApp) //*********** // TestFrame //*********** class TestFrame : public wxFrame { public: TestFrame( wxWindow* parent, int id, wxString title ); private: void OnCustomEvent( wxCustomEvent& ce ); DECLARE_EVENT_TABLE() }; #endif //*** //****** // END CUSTOMEVENT.H // BEGIN CUSTOMEVENT.CPP //****** //*** //#include "CustomEvent.h" //*************** // wxCustomEvent //*************** IMPLEMENT_DYNAMIC_CLASS( wxCustomEvent, wxCommandEvent ) wxCustomEvent::wxCustomEvent( wxEventType type, int id ) : wxCommandEvent( type, id ) {} wxCustomEvent::wxCustomEvent( const wxCustomEvent& event ) : wxCommandEvent( event ) { printf( "Reached wxCustomEvent copy ctor\n" ); } wxEvent* wxCustomEvent::Clone() const { printf( "Reached wxCustomEvent Clone()\n" ); return new wxCustomEvent( *this ); } //********* // TestApp //********* IMPLEMENT_APP( TestApp ) bool TestApp::OnInit() { TestFrame* tf = new TestFrame( NULL, -1, "Custom Event Test" ); tf->SetSize( 400,300 ); tf->Show( true ); //wxCommandEvent ce( wxCUSTOM_EVENT_TYPE, wxCUSTOM_TEST ); wxCustomEvent ce( wxCUSTOM_EVENT_TYPE, wxCUSTOM_TEST ); tf->AddPendingEvent( ce ); return true; } //*********** // TestFrame //*********** BEGIN_EVENT_TABLE( TestFrame, wxFrame ) EVT_CUSTOM_TEST( wxCUSTOM_TEST, TestFrame::OnCustomEvent ) END_EVENT_TABLE() TestFrame::TestFrame( wxWindow* parent, int id, wxString title ) : wxFrame( parent, id, title ) {} void TestFrame::OnCustomEvent( wxCustomEvent& ce ) { printf( "TestFrame received the custom event!\n" ); }