Below are a number of convenience functions for getting input from the user or displaying messages. Note that in these functions the last three parameters are optional. However, it is recommended to pass a parent frame parameter, or (in MS Windows or Motif) the wrong window frame may be brought to the front when the dialog box is popped up.
::wxFileSelector
::wxGetTextFromUser
::wxGetMultipleChoice
::wxGetSingleChoice
::wxGetSingleChoiceIndex
::wxGetSingleChoiceData
::wxMessageBox
wxString wxFileSelector(const wxString& message, const wxString& default_path = NULL,
const wxString& default_filename = NULL, const wxString& default_extension = NULL,
const wxString& wildcard = "*.*'', int flags = 0, wxWindow *parent = NULL,
int x = -1, int y = -1)
Pops up a file selector box. In Windows, this is the common file selector dialog. In X, this is a file selector box with somewhat less functionality. The path and filename are distinct elements of a full file pathname. If path is NULL, the current directory will be used. If filename is NULL, no default filename will be supplied. The wildcard determines what files are displayed in the file selector, and file extension supplies a type extension for the required filename. Flags may be a combination of wxOPEN, wxSAVE, wxOVERWRITE_PROMPT, wxHIDE_READONLY, or 0. They are only significant at present in Windows.
Both the X and Windows versions implement a wildcard filter. Typing a filename containing wildcards (*, ?) in the filename text item, and clicking on Ok, will result in only those files matching the pattern being displayed. In the X version, supplying no default name will result in the wildcard filter being inserted in the filename text item; the filter is ignored if a default name is supplied.
Under Windows (only), the wildcard may be a specification for multiple types of file with a description for each, such as:
"BMP files (*.bmp) | *.bmp | GIF files (*.gif) | *.gif"The application must check for a NULL return value (the user pressed Cancel). For example:
const wxString\& s = wxFileSelector("Choose a file to open"); if (s) { ... }Include files
<wx/filedlg.h>
wxString wxGetTextFromUser(const wxString& message, const wxString& caption = "Input text",
const wxString& default_value = "", wxWindow *parent = NULL,
int x = -1, int y = -1, bool centre = TRUE)
Pop up a dialog box with title set to caption, message message, and a default_value. The user may type in text and press OK to return this text, or press Cancel to return the empty string.
If centre is TRUE, the message text (which may include new line characters) is centred; if FALSE, the message is left-justified.
Include files
<wx/textdlg.h>
int wxGetMultipleChoice(const wxString& message, const wxString& caption, int n, const wxString& choices[],
int nsel, int *selection,
wxWindow *parent = NULL, int x = -1, int y = -1,
bool centre = TRUE, int width=150, int height=200)
Pops up a dialog box containing a message, OK/Cancel buttons and a multiple-selection listbox. The user may choose one or more item(s) and press OK or Cancel.
The number of initially selected choices, and array of the selected indices, are passed in; this array will contain the user selections on exit, with the function returning the number of selections. selection must be as big as the number of choices, in case all are selected.
If Cancel is pressed, -1 is returned.
choices is an array of n strings for the listbox.
If centre is TRUE, the message text (which may include new line characters) is centred; if FALSE, the message is left-justified.
Include files
<wx/choicdlg.h>
wxString wxGetSingleChoice(const wxString& message, const wxString& caption, int n, const wxString& choices[],
wxWindow *parent = NULL, int x = -1, int y = -1,
bool centre = TRUE, int width=150, int height=200)
Pops up a dialog box containing a message, OK/Cancel buttons and a single-selection listbox. The user may choose an item and press OK to return a string or Cancel to return the empty string.
choices is an array of n strings for the listbox.
If centre is TRUE, the message text (which may include new line characters) is centred; if FALSE, the message is left-justified.
Include files
<wx/choicdlg.h>
int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption, int n, const wxString& choices[],
wxWindow *parent = NULL, int x = -1, int y = -1,
bool centre = TRUE, int width=150, int height=200)
As wxGetSingleChoice but returns the index representing the selected string. If the user pressed cancel, -1 is returned.
Include files
<wx/choicdlg.h>
wxString wxGetSingleChoiceData(const wxString& message, const wxString& caption, int n, const wxString& choices[],
const wxString& client_data[], wxWindow *parent = NULL, int x = -1,
int y = -1, bool centre = TRUE, int width=150, int height=200)
As wxGetSingleChoice but takes an array of client data pointers corresponding to the strings, and returns one of these pointers.
Include files
<wx/choicdlg.h>
int wxMessageBox(const wxString& message, const wxString& caption = "Message", int style = wxOK | wxCENTRE,
wxWindow *parent = NULL, int x = -1, int y = -1)
General purpose message dialog. style may be a bit list of the following identifiers:
wxYES_NO | Puts Yes and No buttons on the message box. May be combined with wxCANCEL. |
wxCANCEL | Puts a Cancel button on the message box. May be combined with wxYES_NO or wxOK. |
wxOK | Puts an Ok button on the message box. May be combined with wxCANCEL. |
wxCENTRE | Centres the text. |
wxICON_EXCLAMATION | Under Windows, displays an exclamation mark symbol. |
wxICON_HAND | Under Windows, displays a hand symbol. |
wxICON_QUESTION | Under Windows, displays a question mark symbol. |
wxICON_INFORMATION | Under Windows, displays an information symbol. |
The return value is one of: wxYES, wxNO, wxCANCEL, wxOK.
For example:
... int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO | wxCANCEL, main_frame); if (answer == wxYES) delete main_frame; ...message may contain newline characters, in which case the message will be split into separate lines, to cater for large messages.
Under Windows, the native MessageBox function is used unless wxCENTRE is specified in the style, in which case a generic function is used. This is because the native MessageBox function cannot centre text. The symbols are not shown when the generic function is used.
Include files
<wx/msgdlg.h>