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 Windows 3) the wrong window frame may be brought to the front when the dialog box is popped up.
::wxGetTextFromUser
char *wxGetTextFromUserchar *message, char *caption = "Input text",
char *default_value = "", wxFrame *parent = NULL, int x = -1, int y = -1
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 NULL.
::wxGetSingleChoice
char *wxGetSingleChoicechar *message, char *caption, int n, char *choices[],
wxFrame *parent = NULL, int x = -1, int y = -1
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 NULL.
choices is an array of n strings for the listbox.
::wxGetSingleChoiceIndex
intwxGetSingleChoiceIndexchar *message, char *caption, int n, char *choices[],
wxFrame *parent = NULL, int x = -1, int y = -1
As wxGetSingleChoice but returns the index representing the selected string.
::wxGetSingleChoiceData
char *wxGetSingleChoiceDatachar *message, char *caption, int n, char *choices[],
char *client_data[], wxFrame *parent = NULL, int x = -1, int y = -1
As wxGetSingleChoice but takes an array of client data pointers corresponding to the strings, and returns one of these pointers.
::wxMessageBox
intwxMessageBoxchar *message, char *caption = "Message", int type = wxOK,
wxFrame *parent = NULL, int x = -1, int y = -1
General purpose message dialog. type may be one or more of the following identifiers or'ed together: wxYES_NO, wxCANCEL, wxOK.
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 and centred in the dialog box, to cater for large messages.
::wxFileSelector
char *wxFileSelectorchar *message, char *default_path = NULL,
char *default_filename = NULL, char *default_extension = NULL,
char *wildcard = ``*.*'', int flags = 0, wxFrame *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.
The application must check for a NULL return value (the user pressed Cancel). For example:
char *s = wxFileSelector("Choose a file to open"); if (s) { ... }