当前位置: 动力学知识库 > 问答 > 编程问答 >

wxwidgets - How to response MENU_SELECTED event in an Inherited wxMenuBar?

问题描述:

I had tried DECLARE_EVENT_TABLE() && Connect(),but it dosen't work.My code just like this.How to make it work?

 //.h

class MainFrameMenuBar :public wxMenuBar

//...

private:

DECLARE_EVENT_TABLE();

};

/...

//.cpp

BEGIN_EVENT_TABLE(MainFrameMenuBar, wxMenuBar)

EVT_MENU(XRCID("ID_MENU_FIGURE"), MainFrameMenuBar::onMenuItemFigure)

END_EVENT_TABLE()

MainFrameMenuBar::MainFrameMenuBar(wxWindow* parent)

{

wxXmlResource::Get()->LoadMenuBar(parent,wxT("ID_MAIN_MENUBAR"));

//int id = XRCID("ID_MENU_FIGURE");

//Connect(id, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrameMenuBar::onMenuItemFigure), NULL, this);

}

void MainFrameMenuBar::onMenuItemFigure(wxCommandEvent& event)

{

printf("abc");

}

网友答案:

This used to be broken in older wxWidgets versions and you had to handle menu events only in the wxFrame containing the menu bar and not the menu bar itself, but it should have been fixed quite some time ago, so perhaps you need to upgrade?

If you do use a version affected by that bug and can't upgrade, handling the events in the frame is the simplest workaround.

分享给朋友:
您可能感兴趣的文章:
随机阅读: