MyMainFrame *main_frame = (MyMainFrame*) NULL;
MyMiniFrame *mini_frame = (MyMiniFrame*) NULL;
+bool mini_frame_exists = FALSE;
wxButton *button = (wxButton*) NULL;
// The `main program' equivalent, creating the windows and returning the
// Create the mini frame window
mini_frame = new MyMiniFrame((wxFrame *) NULL, -1, "wxMiniFrame sample",
wxPoint(100, 100), wxSize(205, 100));
+ mini_frame_exists = TRUE;
mini_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR);
InitToolbar(mini_frame->GetToolBar());
void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
+ // make it known that the miniframe is no more
+ mini_frame_exists = FALSE;
Destroy();
}
void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event))
{
- button->Reparent( mini_frame );
+ // practical jokers might find satisfaction in reparenting the button
+ // after closing the mini_frame. We'll have the last laugh.
+ if (! mini_frame_exists)
+ wxMessageBox("The miniframe no longer exists.\n"
+ "You don't want to make this button an orphan, do you?",
+ "You got to be kidding");
+ else
+ button->Reparent( mini_frame );
}