enable menu Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rafae11
Experienced Solver
Experienced Solver
Posts: 85
Joined: Sat Jun 02, 2012 8:41 am

enable menu

Post 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)
{
Save->Enable(true);
}

thanks
User avatar
xaviou
Super wx Problem Solver
Super wx Problem Solver
Posts: 437
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

Re: enable menu

Post by xaviou »

Hi

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.

Regards.
Xav'
My wxWidgets stuff web page : X@v's wxStuff
rafae11
Experienced Solver
Experienced Solver
Posts: 85
Joined: Sat Jun 02, 2012 8:41 am

Re: enable menu

Post by rafae11 »

Thanks for the help. that fixed it.
tuli
Knows some wx things
Knows some wx things
Posts: 42
Joined: Sat Dec 03, 2011 3:56 pm

Re: enable menu

Post by tuli »

also see

http://wyoguide.sourceforge.net/guidelines/menus.html

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