Windows 11, VS Studio 19 wx version 3.1.5
I used wx Form Builder to generate the code, and then the inheritance classes (once), however whenever I click on the menu item (m_Mod) it does not call the derived classes function (should create a message box with the text "CALLED", but nothing appears), which from what I can see that is how it is intended to work.
I have tried adding override, setting the events to Connect and Table, as well as impl_virtual, decl and pure virtual, and without anything of major help after an hour searching.
(If I put the code in the cMainFrame function declaration it does run, just not when its in the cMain derived class function)
Full code at: https://github.com/Miitto/Arma-Mod-Assistant
cGUI.h (wxFormBuilder generated, removed some of the clutter)
class cMainFrame : public wxFrame
{
protected:
wxMenuBar* m_menuBar;
wxMenu* m_file;
wxMenu* m_New;
virtual void newMod( wxCommandEvent &event) {event.Skip();}
cMainFrame( wxWindow* parent, wxWindowID id = id_mainFrame, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 1920,1080 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
wxAuiManager m_mgr;
~cMainFrame();
};
cGUI.cpp
cMainFrame::cMainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
m_mgr.SetManagedWindow(this);
m_mgr.SetFlags(wxAUI_MGR_DEFAULT);
m_menuBar = new wxMenuBar( 0 );
m_file = new wxMenu();
m_New = new wxMenu();
wxMenuItem* m_NewItem = new wxMenuItem( m_file, wxID_ANY, wxT("New"), wxEmptyString, wxITEM_NORMAL, m_New );
wxMenuItem* m_Mod;
m_Mod = new wxMenuItem( m_New, id_newModMenu, wxString( wxT("Mod") ) , wxEmptyString, wxITEM_NORMAL );
m_New->Append( m_Mod );
m_mgr.Update();
this->Centre( wxBOTH );
// Connect Events
m_New->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( cMainFrame::newMod ), this, m_Mod->GetId());
}
cMain.h (Inheritence Class Generated by wxFormsBuilder)
#ifndef __cMain__
#define __cMain__
#include "cGUI.h"
class cMain : public cMainFrame
{
protected:
// Handlers for cMainFrame events.
void newMod( wxCommandEvent& event );
public:
cMain( wxWindow* parent);
}
#endif
cMain.cpp
#include "cMain.h"
#include <wx/msgdlg.h>
cMain::cMain( wxWindow* parent )
:
cMainFrame( parent )
{
}
void cMain::newMod( wxCommandEvent& event )
{
wxMessageBox(wxT("CALLED"));
event.Skip();
}
This code should definitely work, provided you actually append the menu item to the menu bar, so you can click it (as already mentioned by @New Pagodi). And as mentioned by @macroland, you don't need
wxCommandEventHandlerwithBind(), using it can just hide potential mistakes (even though this is not the case here). The recommended and simpler way is to just write this line as:But, again, the code as shown does work, so you really need to show the actual code you use because it seems you've somehow fixed your problem while simplifying it. Of course, now that you did fix it, you should also be easily able to find the problem yourself just by comparing the version you posted here with the one you have.