void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
{
- wxFontData data;
- data.SetInitialFont(wxGetApp().m_canvasFont);
- data.SetColour(wxGetApp().m_canvasTextColour);
+ wxFontData data;
+ data.SetInitialFont(wxGetApp().m_canvasFont);
+ data.SetColour(wxGetApp().m_canvasTextColour);
- wxFontDialog *dialog = new wxFontDialog(this, &data);
- if (dialog->ShowModal() == wxID_OK)
- {
- wxFontData retData = dialog->GetFontData();
+ // you might also do this:
+ //
+ // wxFontDialog dialog;
+ // if ( !dialog.Create(this, data) { ... error ... }
+ //
+ wxFontDialog dialog(this, data);
+
+ if (dialog.ShowModal() == wxID_OK)
+ {
+ wxFontData retData = dialog.GetFontData();
wxGetApp().m_canvasFont = retData.GetChosenFont();
wxGetApp().m_canvasTextColour = retData.GetColour();
myCanvas->Refresh();
- }
- dialog->Destroy();
+ }
+ //else: cancelled by the user, don't change the font
}
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
{
wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly",
- "Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
+ "Message box text", wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
+
+ switch ( dialog.ShowModal() )
+ {
+ case wxID_YES:
+ wxLogStatus(wxT("You pressed \"Yes\""));
+ break;
+
+ case wxID_NO:
+ wxLogStatus(wxT("You pressed \"No\""));
+ break;
- dialog.ShowModal();
+ case wxID_CANCEL:
+ wxLogStatus(wxT("You pressed \"Cancel\""));
+ break;
+
+ default:
+ wxLogError(wxT("Unexpected wxMessageDialog return code!"));
+ }
}
void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )