From: John L. <jla...@gm...> - 2006-05-31 03:08:38
|
On 5/30/06, Steve Kieu <ha...@ya...> wrote: > Thanks for your reply. > Just abit of adamant, why the following code in c++ works as expected? > > #include "wx/wx.h" #include "wx/frame.h" class test: public wxFrame { > DECLARE_CLASS( test ) DECLARE_EVENT_TABLE() public: test( wxWindow* parent, > wxWindowID id = -1, const wxString& caption = _("Test")); void > OnLeaveWindow( wxMouseEvent& event ); }; IMPLEMENT_CLASS( test, wxFrame ) // > Is the following equivalent to frame:ConnectEvent(wx.wxEVT_LEAVE_WINDOW, > OnLeaveWindow) ? BEGIN_EVENT_TABLE( test, wxFrame ) EVT_LEAVE_WINDOW( > test::OnLeaveWindow ) END_EVENT_TABLE() test::test( wxWindow* parent, > wxWindowID id, const wxString& caption ): wxFrame( parent, id, caption){} > void test::OnLeaveWindow( wxMouseEvent& event ){ wxMessageBox(_("Leave > window in c++; works")); } class ClGUIApp: public wxApp { DECLARE_CLASS( > ClGUIApp ) DECLARE_EVENT_TABLE() public: ClGUIApp(); virtual bool OnInit(); > virtual int OnExit(); }; DECLARE_APP(ClGUIApp) IMPLEMENT_APP( ClGUIApp ) > IMPLEMENT_CLASS( ClGUIApp, wxApp ) BEGIN_EVENT_TABLE( ClGUIApp, wxApp ) > END_EVENT_TABLE() ClGUIApp::ClGUIApp(){} bool > ClGUIApp::OnInit() { test* mainWindow = new test( NULL, -1 ); > mainWindow->SetSize(400,300); mainWindow->Show(true); return true; } int > ClGUIApp::OnExit(){ return wxApp::OnExit(); } > Cheers, > This is kinda' hard to read. :/ Take the choices.wx.lua sample, add the line to the leave window. frame:SetStatusText("wxEvents from contols will be displayed here", 0) frame:Connect(wx.wxEVT_LEAVE_WINDOW, function(event) print("Hi") end) It works for me. Remember that the frame is mostly hidden by the notebook so you have to find a spot where it's exposed. Try it out for the listbox as well. Yes the EVT_LEAVE_WINDOW( test::OnLeaveWindow ) is similar to wxEvtHandler::Connect. There are some differences however. The Connect function uses a dynamic event table that is processed before (IIRC) the static event table generated with the macro so you have to use event:Skip() to get the default processing to work in some cases. Regards, John Labenski |