gpt4 book ai didi

c++ - wxTreeCtrl 自定义事件

转载 作者:行者123 更新时间:2023-11-28 07:50:03 25 4
gpt4 key购买 nike

我正在努力处理 wxTreeCtrl 的事件,无法触发它们。我想要触发更改选择事件并尝试查看 treeCtrl 代码示例。到目前为止,我有:

.cpp

TopRightPanel::TopRightPanel(wxWindow *parent, wxSizer* sizer)
: wxTreeCtrl(parent, 0, wxPoint(513, 0), wxSize(512, 384)) //wxPanel(parent, 513, 0, 512, 384)
{
CreateControls(this);;
}



void TopRightPanel::CreateControls(wxTreeCtrl* parent)
{
rootId = wxTreeItemId();
rootId = AddRoot("Particle Systems");
wxTreeItemId root2Id = parent->AppendItem(rootId, "dlisjdslj");



parent->AppendItem(rootId, "Child 1");
}

void TopRightPanel::OnSelChanged(wxTreeEvent& event)
{

}

#if USE_GENERIC_TREECTRL
BEGIN_EVENT_TABLE(TopRightPanel, wxGenericTreeCtrl)
#else
BEGIN_EVENT_TABLE(TopRightPanel, wxTreeCtrl)
#endif

EVT_TREE_SEL_CHANGED(TopRightPanel_Ctrl, TopRightPanel::OnSelChanged)

END_EVENT_TABLE()

#define TREE_EVENT_HANDLER(name) \
void TopRightPanel::name(wxTreeEvent& event) \
{ \
LogEvent(wxT(#name), event); \
SetLastItem(wxTreeItemId()); \
event.Skip(); \
}

/*TREE_EVENT_HANDLER(OnBeginRDrag)
TREE_EVENT_HANDLER(OnDeleteItem)
TREE_EVENT_HANDLER(OnGetInfo)
TREE_EVENT_HANDLER(OnSetInfo)
TREE_EVENT_HANDLER(OnItemExpanded)
TREE_EVENT_HANDLER(OnItemExpanding)
TREE_EVENT_HANDLER(OnItemCollapsed)*/
//TREE_EVENT_HANDLER(OnSelChanged)
//TREE_EVENT_HANDLER(OnSelChanging)

#undef TREE_EVENT_HANDLER

.h

class TopRightPanel : public wxTreeCtrl
{
public:
TopRightPanel(wxWindow *parent, wxSizer *sizer);
void CreateControls(wxTreeCtrl *parent);
void CreateNewParent(wxTreeCtrl *parent);
void CreateNewChild(wxTreeCtrl *parent, wxTreeItemId *root);
void OnSelChanged(wxTreeEvent& event);
void LogEvent(const wxChar *name, const wxTreeEvent& event);
//void OnSelChanging(wxTreeEvent& event);

private:
wxTreeItemId rootId;
//DECLARE_DYNAMIC_CLASS(TopRightPanel);
DECLARE_EVENT_TABLE()
/*void OnSetText(wxCommandEvent & event);
wxStaticText *m_text;*/

};
enum
{
TopRightPanel_Select = 6000,
TopRightPanel_Unselect,
TopRightPanel_Ctrl = 1000
};

如果您能看到任何建议,我将不胜感激。到目前为止,我只是通过尝试在 OnSelChanged 函数中放置一个断点来进行测试,但它没有命中它。

最佳答案

您使用了错误的控件 ID。您创建 ID 为 0 的 TreeCtrl,同时为 ID TopRightPanel_Ctrl 创建事件接收器:

: wxTreeCtrl(parent, TopRightPanel_Ctrl, ...
// ^
// | they need to match
// v
EVT_TREE_SEL_CHANGED(TopRightPanel_Ctrl, ...

关于c++ - wxTreeCtrl 自定义事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14013402/

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