File: wx267.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (261 lines) | stat: -rw-r--r-- 9,968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<HTML>
<head><title>Dialog functions</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="dialogfunctions"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx264.htm#functions"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx266.htm#topic1060"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx268.htm#gdifunctions"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>Dialog functions</H2>
<P>
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.<P>
<A HREF="#wxfileselector">::wxFileSelector</A><BR>
<A HREF="#wxgettextfromuser">::wxGetTextFromUser</A><BR>
<A HREF="#wxgetmultiplechoice">::wxGetMultipleChoice</A><BR>
<A HREF="#wxgetsinglechoice">::wxGetSingleChoice</A><BR>
<A HREF="#wxgetsinglechoiceindex">::wxGetSingleChoiceIndex</A><BR>
<A HREF="#wxgetsinglechoicedata">::wxGetSingleChoiceData</A><BR>
<A HREF="#wxmessagebox">::wxMessageBox</A><BR>
<P>

<HR>
<A NAME="wxfileselector"></A>
<H3>::wxFileSelector</H3>
<P>
<B>wxString</B> <B>wxFileSelector</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>default_path = NULL</I>,<BR>

  <B>const wxString&amp; </B><I>default_filename = NULL</I>, <B>const wxString&amp; </B><I>default_extension = NULL</I>,<BR>

  <B>const wxString&amp; </B><I>wildcard = "*.*''</I>, <B>int </B><I>flags = 0</I>, <B>wxWindow *</B><I>parent = NULL</I>,<BR>

  <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>)<P>
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.<P>
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.<P>
Under Windows (only), the wildcard may be a specification for multiple
types of file with a description for each, such as:<P>
<PRE>
 "BMP files (*.bmp) | *.bmp | GIF files (*.gif) | *.gif"
</PRE>
The application must check for a NULL return value (the user pressed
Cancel). For example:<P>
<PRE>
const wxString\& s = wxFileSelector("Choose a file to open");
if (s)
{
  ...
}
</PRE>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/filedlg.h&gt;<P>

<HR>
<A NAME="wxgettextfromuser"></A>
<H3>::wxGetTextFromUser</H3>
<P>
<B>wxString</B> <B>wxGetTextFromUser</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption = "Input text"</I>,<BR>

  <B>const wxString&amp; </B><I>default_value = ""</I>, <B>wxWindow *</B><I>parent = NULL</I>,<BR>

  <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>, <B>bool</B><I> centre = TRUE</I>)<P>
Pop up a dialog box with title set to <I>caption</I>, message <I>message</I>, and a
<I>default_value</I>.  The user may type in text and press OK to return this text,
or press Cancel to return the empty string.<P>
If <I>centre</I> is TRUE, the message text (which may include new line characters)
is centred; if FALSE, the message is left-justified.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/textdlg.h&gt;<P>

<HR>
<A NAME="wxgetmultiplechoice"></A>
<H3>::wxGetMultipleChoice</H3>
<P>
<B>int</B> <B>wxGetMultipleChoice</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption</I>, <B>int</B><I> n</I>, <B>const wxString&amp; </B><I>choices[]</I>,<BR>

  <B>int </B><I>nsel</I>, <B>int *</B><I>selection</I>,
  <B>wxWindow *</B><I>parent = NULL</I>, <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>,<BR>

  <B>bool</B><I> centre = TRUE</I>, <B>int </B><I>width=150</I>, <B>int </B><I>height=200</I>)<P>
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.<P>
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. <I>selection</I> must be
as big as the number of choices, in case all are selected.<P>
If Cancel is pressed, -1 is returned.<P>
<I>choices</I> is an array of <I>n</I> strings for the listbox.<P>
If <I>centre</I> is TRUE, the message text (which may include new line characters)
is centred; if FALSE, the message is left-justified.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/choicdlg.h&gt;<P>

<HR>
<A NAME="wxgetsinglechoice"></A>
<H3>::wxGetSingleChoice</H3>
<P>
<B>wxString</B> <B>wxGetSingleChoice</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption</I>, <B>int</B><I> n</I>, <B>const wxString&amp; </B><I>choices[]</I>,<BR>

  <B>wxWindow *</B><I>parent = NULL</I>, <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>,<BR>

  <B>bool</B><I> centre = TRUE</I>, <B>int </B><I>width=150</I>, <B>int </B><I>height=200</I>)<P>
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.<P>
<I>choices</I> is an array of <I>n</I> strings for the listbox.<P>
If <I>centre</I> is TRUE, the message text (which may include new line characters)
is centred; if FALSE, the message is left-justified.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/choicdlg.h&gt;<P>

<HR>
<A NAME="wxgetsinglechoiceindex"></A>
<H3>::wxGetSingleChoiceIndex</H3>
<P>
<B>int</B> <B>wxGetSingleChoiceIndex</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption</I>, <B>int</B><I> n</I>, <B>const wxString&amp; </B><I>choices[]</I>,<BR>

  <B>wxWindow *</B><I>parent = NULL</I>, <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>,<BR>

  <B>bool</B><I> centre = TRUE</I>, <B>int </B><I>width=150</I>, <B>int </B><I>height=200</I>)<P>
As <B>wxGetSingleChoice</B> but returns the index representing the selected string.
If the user pressed cancel, -1 is returned.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/choicdlg.h&gt;<P>

<HR>
<A NAME="wxgetsinglechoicedata"></A>
<H3>::wxGetSingleChoiceData</H3>
<P>
<B>wxString</B> <B>wxGetSingleChoiceData</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption</I>, <B>int</B><I> n</I>, <B>const wxString&amp; </B><I>choices[]</I>,<BR>

  <B>const wxString&amp; </B><I>client_data[]</I>, <B>wxWindow *</B><I>parent = NULL</I>, <B>int</B><I> x = -1</I>,<BR>

  <B>int</B><I> y = -1</I>, <B>bool</B><I> centre = TRUE</I>, <B>int </B><I>width=150</I>, <B>int </B><I>height=200</I>)<P>
As <B>wxGetSingleChoice</B> but takes an array of client data pointers
corresponding to the strings, and returns one of these pointers.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/choicdlg.h&gt;<P>

<HR>
<A NAME="wxmessagebox"></A>
<H3>::wxMessageBox</H3>
<P>
<B>int</B> <B>wxMessageBox</B>(<B>const wxString&amp; </B><I>message</I>, <B>const wxString&amp; </B><I>caption = "Message"</I>, <B>int</B><I> style = wxOK |  wxCENTRE</I>,<BR>

  <B>wxWindow *</B><I>parent = NULL</I>, <B>int</B><I> x = -1</I>, <B>int</B><I> y = -1</I>)<P>
General purpose message dialog.  <I>style</I> may be a bit list of the
following identifiers:<P>

<TABLE>


<TR><TD VALIGN=TOP>
wxYES_NO
</TD>

<TD VALIGN=TOP>
Puts Yes and No buttons on the message box. May be combined with
wxCANCEL.
</TD></TR>


<TR><TD VALIGN=TOP>
wxCANCEL
</TD>

<TD VALIGN=TOP>
Puts a Cancel button on the message box. May be combined with
wxYES_NO or wxOK.
</TD></TR>


<TR><TD VALIGN=TOP>
wxOK
</TD>

<TD VALIGN=TOP>
Puts an Ok button on the message box. May be combined with wxCANCEL.
</TD></TR>


<TR><TD VALIGN=TOP>
wxCENTRE
</TD>

<TD VALIGN=TOP>
Centres the text.
</TD></TR>


<TR><TD VALIGN=TOP>
wxICON_EXCLAMATION
</TD>

<TD VALIGN=TOP>
Under Windows, displays an exclamation mark symbol.
</TD></TR>


<TR><TD VALIGN=TOP>
wxICON_HAND
</TD>

<TD VALIGN=TOP>
Under Windows, displays a hand symbol.
</TD></TR>


<TR><TD VALIGN=TOP>
wxICON_QUESTION
</TD>

<TD VALIGN=TOP>
Under Windows, displays a question mark symbol.
</TD></TR>


<TR><TD VALIGN=TOP>
wxICON_INFORMATION
</TD>

<TD VALIGN=TOP>
Under Windows, displays an information symbol.
</TD></TR>


</TABLE>
<P>
The return value is one of: wxYES, wxNO, wxCANCEL, wxOK.<P>
For example:<P>
<PRE>
  ...
  int answer = wxMessageBox("Quit program?", "Confirm",
                            wxYES_NO | wxCANCEL, main_frame);
  if (answer == wxYES)
    delete main_frame;
  ...
</PRE>
<I>message</I> may contain newline characters, in which case the
message will be split into separate lines, to cater for large messages.<P>
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.<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/msgdlg.h&gt;<P>

</BODY></HTML>