Dialog tutorial: Part 1
This tutorial develops a
simple
Search/Replace dialog and a HTML viewer dialog, based on wxWidgets
Sizer code. Sizers are a means to ensure that the dialog fits
nicely together, and has a sensible size on any platform. You
can read about sizers, how to edit them manually and what all the
parameters mean at http://neume.sourceforge.net/sizerdemo/
The Dialog editor
was introduced
into wxHatch at version 1.3 and is likely to develop further with
future releases. An outline of its structure is in this help file
Starting a New Dialog:
Create an New Dialog project
by using the wxHatch File | New menu and choosing New Dialog This
will create
- a dialog test harness
program
(dlg_test.cpp and dlg_test.h)
- 2 dialog code files
(called
myproject.cpp myproject.h)
and myproject.inc,
a section of code which can be
added to other wxHatch projects which need to invoke the
dialog
- a dialog editing
window, click the
image below for larger size,
The mainsizer is the root of the dialog, and can hold other sizers
or individual controls. The wxVERTICAL style means that these
controls will be arranged vertically. At the start, it
contains a buttonsizer, which will have working OK and Cancel
buttons. Compile and Run the program to see how it looks.
To make a Search Dialog, we need to add some controls:
- Right click the
mainsizer and choose Insert | wxTextCtrl
and name it something like SearchBox
- Right click the
mainsizer and choose Insert | wxStaticText (you
can accept the name it is given automatically); this will be added
above the text ctrl. Click the + to expand m_staticText and use the
mouse to edit the label, eg to Search For ... Note that you need to
enclose characters in wxT(" ") to enable Unicode compilation, when
non-English characters may be used
- If you try to compile
this, you will get errors from
myproject.inc, this file holds the call from external program to
dialog, and we need to pass in any default search word, and recover
the result of the search in the calling program. For example,
Digital Mars gives this kind of output:
dialog.SearchBox_SetValue (
/* const wxString& */ value);
dlgtst02.inc(8) : Error:
undefined
identifier 'value'
--- errorlevel 1
- To work on this, right
click the Dialog editor, and choose Goto
| Include. We have set the label for the Static text already, so
can delete this line. In the line that reads
dialog.SearchBox_SetValue ( /* const wxString&
*/ value);
we need to pass in a value for the search, perhaps wxT("wxWidgets")
would do instead of value.
- When the dialog closes,
we want to recover the input from the
users, and this will be passsed back in sSearchBox. As a first test
we will just show it in a message box, so click just below the line
beginnnig wxString sSearchBox = and use Insert Dialog |
wxMessagebox OK. Rewrite the MessageBox call so it looks like
this:
wxString
s =
dialog.SearchBox_GetValue() ;
(void)wxMessageBox( s,
wxT("Dialog Result is"));
Now it should compile and run
Any problems?
- If you want to find the
Dialog editor pane and its got lost
(perhaps behind another code window), click the OK button in the
toolbar

- If you've added the
static box below the textctrl, right click
the static box and choose Move Ctrl Up
Next
wxHatch
Home 