我試圖實現我自己的自定義事件。它可以工作,如果我從我連接它的類(一個wxFrame)發佈它,但是如果它從一個子wxFrame發佈它不會被捕獲。wxwidgets自定義事件不會傳播到父窗口
自定義事件:
**cFrameFocus.h**
#pragma once
#include <wx\event.h>
class cFrameFocusEvent;
const wxEventTypeTag<cFrameFocusEvent> evtFRAME_FOCUS(wxNewEventType());
//eventhandler macro
#if _MSC_VER <= 1600
typedef void (wxEvtHandler::*MyFrameFocusEventFunction)(cFrameFocusEvent&);
#define FrameFocusEventHandler(func) wxEVENT_HANDLER_CAST(MyFrameFocusEventFunction,func)
#else
#define FrameFocusEventHandler(func) (&func)
#endif
class cFrameFocusEvent :
public wxEvent
{
wxWindow* m_frame;
public:
cFrameFocusEvent(wxEventType pEventType,int pWinId = wxID_ANY,const wxWindow* pWin = 0);
~cFrameFocusEvent(void);
//impement base class pure virtual
virtual wxEvent* Clone(void)const;
//accessor
wxWindow* GetWindow(void)const;
};
**cFrameFocus.cpp**
#include "cFrameFocus.h"
cFrameFocusEvent::cFrameFocusEvent(wxEventType pEventType,int pWinId,const wxWindow* pWin):
wxEvent(pWinId,pEventType)
{
m_frame = const_cast<wxWindow*>(pWin);
}
cFrameFocusEvent::~cFrameFocusEvent(void)
{
}
wxEvent* cFrameFocusEvent::Clone(void)const{
return new cFrameFocusEvent(*this);
}
wxWindow* cFrameFocusEvent::GetWindow(void)const{
return m_frame;
}
子框架試圖甚至派:
cFrameFocusEvent* pevent = new cFrameFocusEvent(evtFRAME_FOCUS,GetId(),this);
wxQueueEvent(GetParent(),pevent);
注:我已經偶然發現了這個問題wxWidgets 2.9 custom events,但它並沒有幫助我。
我想你需要從'wxCommandEvent'派生出來。 – Simple