+ The typical usage for the open file dialog is:
+ @code
+ void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
+ {
+ if (...current content has not been saved...)
+ {
+ if (wxMessageBox(_("Current content has not been saved! Proceed?"), _("Please confirm"),
+ wxICON_QUESTION | wxYES_NO, this) == wxNO )
+ return;
+ //else: proceed asking to the user the new file to open
+ }
+
+ wxFileDialog
+ openFileDialog(this, _("Open XYZ file"), "", "",
+ "XYZ files (*.xyz)|*.xyz", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
+
+ if (openFileDialog.ShowModal() == wxID_CANCEL)
+ return; // the user changed idea...
+
+ // proceed loading the file chosen by the user;
+ // this can be done with e.g. wxWidgets input streams:
+ wxFileInputStream input_stream(openFileDialog.GetPath());
+ if (!input_stream.IsOk())
+ {
+ wxLogError("Cannot open file '%s'.", openFileDialog.GetPath());
+ return;
+ }
+
+ ...
+ }
+ @endcode
+
+ The typical usage for the save file dialog is instead somewhat simpler:
+ @code
+ void MyFrame::OnSaveAs(wxCommandEvent& WXUNUSED(event))
+ {
+ wxFileDialog
+ saveFileDialog(this, _("Save XYZ file"), "", "",
+ "XYZ files (*.xyz)|*.xyz", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
+
+ if (saveFileDialog.ShowModal() == wxID_CANCEL)
+ return; // the user changed idea...
+
+ // save the current contents in the file;
+ // this can be done with e.g. wxWidgets output streams:
+ wxFileOutputStream output_stream(saveFileDialog.GetPath());
+ if (!output_stream.IsOk())
+ {
+ wxLogError("Cannot save current contents in file '%s'.", saveFileDialog.GetPath());
+ return;
+ }
+
+ ...
+ }
+ @endcode
+