Page 1 of 1

enable menu

Posted: Sat Jun 02, 2012 8:49 am
by rafae11
how do i enable a menu with a click of a button.

i open a new program and save menu is disabled by default. I want to enable it when i open a file.
i used wxformbuilder to generate the save code.

wxMenuItem* Save;
Save = new wxMenuItem( m_menu1, wxID_ANY, wxString( wxT("Save") ) , wxEmptyString, wxITEM_NORMAL );
m_menu1->Append( Save );
Save->Enable( false );

void wxfbIntegrationFrame::OpenOnMenuSelection(wxCommandEvent& event)


Re: enable menu

Posted: Sat Jun 02, 2012 2:42 pm
by xaviou

You can use a wxWidgets defined Id for your "save" menu (wxID_SAVE) or a user defined one.

Then, you can retreive the menu by calling FindItem on the wxMenuBar of you frame, for example like this :

Code: Select all

void wxfbIntegrationFrame::OpenOnMenuSelection(wxCommandEvent& event)
    wxMenuItem* item = GetMenuBar()->FindItem(wxID_SAVE);
    if (item!=NULL) item->Enable(true);
P.S: Do not forget the "CODE" tag when you have to post a piece of code on this forum : it is much more readable.


Re: enable menu

Posted: Sat Jun 02, 2012 3:26 pm
by rafae11
Thanks for the help. that fixed it.

Re: enable menu

Posted: Sat Jun 02, 2012 4:00 pm
by tuli
also see

is there any advantage to use wxID_SAVE over some random custom ID?