Search code examples
c++menuwxwidgetswindows-7-x64statusbar

Incorrect displaying of menu items text in status bar - wxWidgets 3.0


I am writing simple GUI software using wxWidgets 3.0 in CodeBlocks 13.12, on Win 7 x64 machine.

I would like to create a menu for the frame, and each item in the frame should make a different text appear in the status bar when highlighted. Below is what I have done so far ( only the menu part of code ). Menu and status bar appear as planned. The problem is that every item ( in File and Data sub menus ) when highlighted displays "Save project" in the status bar - which is the very first item in the first sub menu. How to change this so that proper menu item names are displayed ?

CODE :

    wxMenuBar* mbar = new wxMenuBar();

    wxMenu* fileMenu = new wxMenu(_T(""));
    //fileMenu->Append(, _("&"), _("")));
    fileMenu->Append(SaveProject, _("&Save project"), _("Save project"));
    fileMenu->Append(SaveProjectAs, _("&Save project as"), _("Save project as"));
    fileMenu->Append(OpenNewProject, _("&Open new project"), _("Open new project"));
    fileMenu->Append(OpenExistingProject, _("&Open existing project"), _("Open existing project"));
    fileMenu->AppendSeparator();
    fileMenu->Append(Quit, _("&Quit"), _("Quit"));

    mbar->Append(fileMenu, _("&File"));

    wxMenu* dataMenu = new wxMenu(_T(""));
    //fileMenu->Append(, _("&"), _("")));
    dataMenu->Append(ImportData, _("&Import data"), _("Import data"));
    dataMenu->Append(ExportData, _("&Export data"), _("Export data"));
    dataMenu->Append(SavaDataAs, _("&Save data as"), _("Save data as"));

    mbar->Append(dataMenu, _("&Data"));

    mainFrame->SetMenuBar(mbar);

Solution

  • I suspect the problem is due to your use of duplicate menu IDs (e.g. SaveProject is used twice). While it's not clear why should this result in the observed behaviour, it is pretty clear that you cannot reuse the menu IDs as you will have no way of distinguishing between the events generated by the two items with the same ID. So don't do this.