gpt4 book ai didi

c++ - wxwidgets 自定义事件不会传播到父窗口

转载 作者:行者123 更新时间:2023-11-27 23:09:07 24 4
gpt4 key购买 nike

我试图实现我自己的自定义事件。如果我从我连接它的类(一个 wxFrame)发布它,它确实有效,但如果它从一个子 wxFrame 发布,它就不会被捕获。

自定义事件:

**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 ,但这对我没有帮助。

最佳答案

您需要阅读 event propagation overview了解事件在 wxWidgets 中是如何工作的。特别是,它会告诉您只有从 wxCommandEvent 派生的事件默认向上传播,对于其他事件您需要调用 ResumePropagation(N) 使它们传播N 升级(当然可以是 INT_MAX 以使它们无限传播)。

关于c++ - wxwidgets 自定义事件不会传播到父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21283373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com