Event handling

Liam Whalen lwhalen at cabletv.on.ca
Tue Oct 2 17:19:09 PDT 2007


I have a few questions about event handling.  What I would like to do is 
have different classes handle different events depending on which event was 
called.  So if there is a SOCKET event then my Connection class would hadle 
that.  If ther is a GUI event then my MainWindow would handle that.
So I've tried to setup my event table like this:

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
        EVT_MENU(CLIENT_QUIT,         MyFrame::OnQuit)
        EVT_SOCKET(SOCKET_ID,       Connection::OnSocketEvent)
END_EVENT_TABLE()

Which gives me this error:
*******************************************************
c:\documents and settings\liam\my documents\visual studio 
2005\projects\ootm-wxwidgets\ootm-wxwidgets\ootmmainwindow.cpp(6) : error 
C2440: 'static_cast' : cannot convert from 'void (__thiscall 
OOTMConnection::* )(wxSocketEvent &)' to 'wxSocketEventFunction'

Types pointed to are unrelated; conversion requires reinterpret_cast, 
C-style cast or function-style cast
*******************************************************

Which is beyond my meger programming skill to interpret.
So what I'm considering is seting my event table like this:

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
        EVT_MENU(CLIENT_QUIT,     MyFrame::OnQuit)
        EVT_SOCKET(SOCKET_ID,    MyFrame::DelegateSocketEvent)
END_EVENT_TABLE()

And then MyFrame would have a private data member pointing to my Connection 
class.  Which MyFrame would then pass the event to in the 
DelegateSocketEvent function.  Is this a feasable way of handling events? 
Having one window delegate events to the classes which process them?  Or am 
I missing some way of initializing the event table that would allow 
wxWidgets to pass the events to their corresponding classes?

Liam 





More information about the wx-users mailing list