ChildFrame events..
Rory Walsh
rorywalsh at ear.ie
Wed Oct 18 06:40:38 PDT 2006
I am trying to get a childframe to call my main frames OnClose event
handler when I close it but I can't seem to get it to work. Here is the
code, perhaps someone can spot what must be a silly mistake? loopStation
in the code below is a vector of MDIChildFrame's. I would like to
dynamically attach event to the childframes, is this possible? Cheers,
Rory.
#include "wxLooperApp.h"
#include "wxLooperFrame.h"
//
----------------------------------------------------------------------------
// constants
//
----------------------------------------------------------------------------
enum
{
M_EXIT = 1,
M_OK = 100,
M_NEWLOOP = 200,
ID_MENU_QUIT = 300
};
IMPLEMENT_CLASS(wxLooperFrame, wxMDIParentFrame)
BEGIN_EVENT_TABLE (wxLooperFrame, wxMDIParentFrame)
EVT_MENU (ID_MENU_QUIT, wxLooperFrame::OnQuit)
EVT_MENU ( M_EXIT, wxLooperFrame::OnQuit)
EVT_MENU ( M_NEWLOOP, wxLooperFrame::newLoopWindow)
EVT_CLOSE ( wxLooperFrame::OnClose)
// EVT_BUTTON ( M_OK, wxLooperFrame::OnOk)
END_EVENT_TABLE()
//
----------------------------------------------------------------------------
// main frame
//
----------------------------------------------------------------------------
wxLooperFrame::wxLooperFrame(const wxString& title, const wxPoint& pos,
const wxSize& size)
: wxMDIParentFrame((wxMDIParentFrame *)NULL, -1, title, pos, size)
{
//create basic frame....
loopCnt = 0;
//create menu
FileMenu = new wxMenu;
FileMenu->Append(M_NEWLOOP, "New Loop");
FileMenu->Append(M_EXIT, "Exit");
menuBar = new wxMenuBar;
menuBar->Append(FileMenu, "&File");
SetMenuBar(menuBar);
}
//
----------------------------------------------------------------------------
wxLooperFrame::~wxLooperFrame()
{
}
//
----------------------------------------------------------------------------
void wxLooperFrame::OnClose(wxCloseEvent &event)
{
wxMessageBox("test");
}
//
----------------------------------------------------------------------------
void wxLooperFrame::OnQuit(wxCommandEvent& event)
{
Close(TRUE);
}
//
----------------------------------------------------------------------------
void wxLooperFrame::newLoopWindow(wxCommandEvent& event)
{
wxString str;
str.sprintf("Loop Station %d", loopCnt+1);
loopStation.resize(loopCnt+1);
loopStation[loopCnt] = new wxMDIChildFrame(this, -1, str,
wxDefaultPosition, wxSize(215, 255), wxDEFAULT_FRAME_STYLE);
loopStation[loopCnt]->Connect(ID_MENU_QUIT,
wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&wxLooperFrame::OnQuit);;
loopCnt++;
}
//-----------------------------------------------------------------------------
More information about the wx-users
mailing list