Custom events revisited
Posted: Thu Mar 12, 2009 1:00 am
I see that there is another question on custom events, but mine is even more basic, perhaps.
Incidentally, I also have a kind of communication event I'd like to define. I defined everything according to "cookbook" (and it looks like it matches the code in other post too). However, my custom event is not being delivered to the main frame. If I replace it with standard wxCommandEvent, everything works just fine of course.
Here is the definition in include file:
Here is the definition in CPP file:
Here is the event handler attached to the main frame:
And finally here is how it is being sent:
So, I must be missing something - but what?
Incidentally, I also have a kind of communication event I'd like to define. I defined everything according to "cookbook" (and it looks like it matches the code in other post too). However, my custom event is not being delivered to the main frame. If I replace it with standard wxCommandEvent, everything works just fine of course.
Here is the definition in include file:
Code: Select all
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMM_EVENT, -1);
END_DECLARE_EVENT_TYPES()
class commEvent;
typedef void (wxEvtHandler::*CommEventFunction)(commEvent&);
#define EVT_COMM(id, fn)\
DECLARE_EVENT_TABLE_ENTRY(wxEVT_COMM_EVENT, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (CommEventFunction) & fn, (wxObject *) NULL ),
enum {
COMM_Test
};
class commEvent : public wxEvent
{
public:
commEvent(int id);
commEvent *Clone() const { return new commEvent(*this); }
};
Code: Select all
DEFINE_EVENT_TYPE(wxEVT_COMM_EVENT);
commEvent::commEvent(int id) : wxEvent(wxEVT_COMM_EVENT, id)
{
printf("Event type %d\n", wxEVT_COMM_EVENT);
}
BEGIN_EVENT_TABLE(commEventFrame, wxFrame)
EVT_COMM(COMM_Test, commEventFrame::OnTest)
END_EVENT_TABLE()
Code: Select all
void commEventFrame::OnTest(commEvent &event)
{
printf("Received test event: %d\n", event.GetId());
}
Code: Select all
commEvent evt(COMM_Test);
wxPostEvent(mainFrame, evt);