Menu Bar with Quit for a wxDialog or wxFrame-based app on OSX

I have some apps that I’ve tried porting to OSX off an on over the years, but some of them have never been quite right.

They’re written with wxWidgets, which is a multiplatform application development toolkit. However, documentation and fine details for macOS specifics is generally lacking.

For instance, I had an ongoing problem with making the “Quit” function in a menu work in a single-dialog application based on the wxDialog class. I originally asked the question on the forums back in 2011:

I have a wxDialog-based application on OSX that shows a single modal dialog window.

My understanding is that a dialog-based app cannot have a menu bar. However, I do get the default system menu bar on the app.

The Cmd-Q option (Quit) shows up on the default system menu bar, but it is grayed out. How can I modify my app to bind to that Cmd-Q option so I can treat it the same as clicking the red button at the top right of my dialog (which exits the app)?

The original post is here.

The answer from Tierra about switching to a wxFrame instead of a wxDialog was a part of the puzzle (thank you!), but the quit item still didn’t work. Once I had a wxFrame I could then attach the default menu items (in the constructor where all the dialog controls are being created):

wxMenu* helpMenu = new wxMenu();
wxMenuBar* menuBar = new wxMenuBar();
menuBar->Append( helpMenu, "&Help" );

I also had to connect those buttons to my functions in the event table (my dialog class is called wxKeyboard):

EVT_MENU( wxID_EXIT, wxKeyboard::OnExit )
EVT_MENU( wxID_ABOUT, wxKeyboard::OnInfo )
EVT_MENU( wxID_HELP, wxKeyboard::OnHelp )

Once that was done, I had an about menu item, a help menu item, and the quit item magically appeared and worked as intended. In addition, the “About” menu entry appeared under the application menu and not the help menu, but I had to add it to a menu in order for it to show up.