How to response MENU_SELECTED event in an Inherited wxMenuBar?

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
winzjqwin
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Aug 03, 2016 6:25 am

How to response MENU_SELECTED event in an Inherited wxMenuBar?

Post by winzjqwin »

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

Code: Select all

	//.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");
        }
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to response MENU_SELECTED event in an Inherited wxMenuBar?

Post by doublemax »

I'm not 100% sure, but i have a faint memory that this can't work, because the menu events are directly sent to the owning wxFrame, not to the wxMenuBar
Use the source, Luke!
winzjqwin
In need of some credit
In need of some credit
Posts: 3
Joined: Wed Aug 03, 2016 6:25 am

Re: How to response MENU_SELECTED event in an Inherited wxMenuBar?

Post by winzjqwin »

doublemax wrote:I'm not 100% sure, but i have a faint memory that this can't work, because the menu events are directly sent to the owning wxFrame, not to the wxMenuBar
thanks!
Post Reply