Is it possible to dynamic set menu items in a wxMenu?

时间:2015-07-28 22:45:59

标签: wxwidgets

Hi: I have in a wxFrame a menubar with this wxMenus: File|Edit|Personal. During the frame creation the wxMenu Personal has two wxMenuItems (Information and Need Help), which tells the user that must fill the form and help abou how to fill it. After the user fills the form with personal information, the menu is populated with new items: send, clear, check and remove, deleting/removing the previous ones... At this point I manage to trap the event, like this:

Bind (wxEVT_MENU_OPEN, &MyFrame::processMenuPersonal, this);
// the method
void MyFrame::processMenuPersonal (wxMenuEvent& event) {
    wxMenu *menu = event.GetMenu ();
    wxMenuItem *item = menu->FindItem (IDM_PERSONAL_EMPTY);
    if (item) {
        // here I want to dynamic add items and remove the current ones
    }
}

Any ideas about how to do this?

1 个答案:

答案 0 :(得分:1)

是。只需附加为子菜单,并将其视为任何条件语句。这是一个样本

void MyFrame::processMenuPersonal (wxMenuEvent& event) {
    wxMenu *menu = event.GetMenu ();
    wxMenu *item = menu->GetMenu(YOUR_MENU_INDEX);
    menu->AppendSubMenu(item, wxT("User Items"));
    if (YouConditionHere) {
        item->Append(wxID_ANY, "Item 1")
        item->Append(wxID_ANY, "Item 2")
        item->Append(wxID_ANY, "Item 3")
    }
}

请注意,项目1,2,3是您在处理数据后要添加的信息(在您删除旧条目的情况下)