
Step 6: Painting the window and adding menus
There are a few flaws with the application from Step 5. The biggest problem
is that the drawing window doesn’t know how paint itself. T see this foro
yourself, try drawing a line in the window minimizing the application,,
then restoring it. The line you drew is gone.
Y u can find theo
Another problem is that the only way the user can access the application is
source for Step 6 in
the files
with the mouse. The user can either press the left button to draw a line or
STEP06.CPP and
the right button to change the pen size.
STEP06.RC in the
directory
In Step 6, you’ll make it possible for the application to remember the
EXAMPLES\OWL\
contexts of the window and redraw it. Y u’ll also add some menus too
TUTORIAL.
increase the number of ways the user can access the application.
There are two problems that must be dealt with when you’re trying to paint
Repainting the
the window:
window
■ There must be a way to remember what was displayed in the window.
■ There must be a way to redraw the window.
In the earlier steps of the tutorial application, the line in the window was
Storing the drawing
drawn as the user moved the mouse while holding the left mouse button.
This approach is fine for drawing the line, but doesn’t store the points in
the line for later use.
Because the line is composed of a number of points in the window you can,
store each point in the ObjectWindows TP int class. And because each lineo
is composed of multiple points, you need an array of TP int objects to storeo
a line. Instead of attempting to allocate, manage, and update an array of
TP int objects from scratch, the tutorial application uses the Borlando
container class T rray to define a data type called TP ints. It also uses theA o
Borland container class T rrayIterator to define an iterator calledA
TP intsIterator. The definitions of these two types look like this:o
typedef TArray<TPoint> TPoints;
typedef TArrayIterator<TPoint> TPointsIterator;
The TMyWindow class adds a TP ints object in which it can store the pointso
in the line. It actually uses a TP ints *, a protected member called Line,o
which is set to point to a TP ints array created in the constructor Theo .
constructor now looks something like this:
Chapter 2, Learning ObjectWindows
45