我正在为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函数中放置一个断点,但它没有达到它。
答案 0 :(得分:1)
您使用的是错误的控件ID。在为ID 0
创建事件接收器时,您创建ID为TopRightPanel_Ctrl
的TreeCtrl:
: wxTreeCtrl(parent, TopRightPanel_Ctrl, ...
// ^
// | they need to match
// v
EVT_TREE_SEL_CHANGED(TopRightPanel_Ctrl, ...