The "child frame" you're creating should be a modal dialog.
Here's some sample code for a dialog for entering one string:
Code: Select all
class DataEntryDialog : public wxDialog
{
public:
DataEntryDialog(wxWindow *parent, const wxString &title) : wxDialog(parent, wxID_ANY, title)
{
wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
m_textctrl = new wxTextCtrl(this, wxID_ANY, "");
m_textctrl->SetHint( "Enter text here");
mainSizer->Add(m_textctrl, 0, wxEXPAND|wxALL, 4);
wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->AddStretchSpacer(1); // make buttons right-aligned by adding flexible space to the left
wxButton *cancelButton = new wxButton(this, wxID_CANCEL, "Cancel");
buttonSizer->Add( cancelButton, 0, wxEXPAND|wxALL, 4 );
wxButton *okButton = new wxButton(this, wxID_OK, "OK");
okButton->SetDefault();
buttonSizer->Add( okButton, 0, wxEXPAND|wxALL, 4 );
mainSizer->Add(buttonSizer, 0, wxEXPAND|wxALL, 4);
SetSizerAndFit(mainSizer);
Bind(wxEVT_BUTTON, &DataEntryDialog::OnCommand, this);
Bind(wxEVT_CLOSE_WINDOW, &DataEntryDialog::OnClose, this);
};
wxString GetValue() const { return m_textctrl->GetValue(); }
protected:
void OnCommand( wxCommandEvent &event)
{
/*
the switch is not really necessary in this sample,
we could just call EndModal( event.GetId() ) here
added just for clarity and demonstration purposes
*/
switch(event.GetId())
{
case wxID_OK:
EndModal(wxID_OK);
break;
case wxID_CANCEL:
EndModal(wxID_CANCEL);
break;
default:
EndModal(wxID_CANCEL);
break;
}
};
void OnClose( wxCloseEvent &event)
{
EndModal(wxID_CANCEL);
};
wxTextCtrl *m_textctrl;
};
And here is how you would use it:
Code: Select all
DataEntryDialog dlg(this, "enter some text");
int ret = dlg.ShowModal();
if( ret == wxID_OK )
{
wxLogMessage("text entered: %s", dlg.GetValue() );
} else {
wxLogMessage("dialog cancelled");
}