无法删除内存,请帮忙看看为什么
#define WXUSINGDLL
#include <wx/wx.h>
#include <iostream>
using namespace std;
/*********定义自己的事件处理类******************/
class MyEventHandler : public wxEvtHandler
{
public:
MyEventHandler(){};
~MyEventHandler(){};
void OnAbout(wxCommandEvent& event);
};
void MyEventHandler::OnAbout(wxCommandEvent& event)
{
cout << "It is my Eventhandler::OnAbout!" << endl;
}
/**********************************************/
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
virtual ~MyFrame(){};
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
private :
MyEventHandler *m_eventHandler;
DECLARE_EVENT_TABLE()
};
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App"));
frame->Show(true);
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
END_EVENT_TABLE()
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxString msg;
msg.Printf(wxT("Hello and welcome to %s"),
wxVERSION_STRING);
wxMessageBox(msg,wxT("About Minimal"),
wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close();
/*******无法删除**************/
PopEventHandler(TRUE);
delete m_eventHandler;
m_eventHandler = NULL;
/******************************/
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxPoint(0,0),wxSize(800,600))
{
m_eventHandler = NULL;
wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
wxT("Show about dialog"));
fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt.X"),
wxT("Quit this program"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(helpMenu, wxT("&Help"));
SetMenuBar(menuBar);
wxButton* button = new wxButton(this,wxID_OK,wxT("OK"),wxPoint(200,200));
CreateStatusBar(3);
SetStatusText(wxT("Welcome to wxWidgets!"));
m_eventHandler = new MyEventHandler();
m_eventHandler->Connect(wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(MyEventHandler::OnAbout));
PushEventHandler(m_eventHandler); //加载事件处理函数
}