• Keine Ergebnisse gefunden

Possible Enhancements

Im Dokument PenPomt GO (Seite 130-136)

. You can change the class of the window created in HelloAppInit to be some other kind of window class by changing the class to which Hello World (toolkit) sends msgNewDefaults and msgNew. But different classes take different message arguments when they are created. You need to replace the declaration of a

LABEL_NEW structure with the msgNew arguments of the new class.

Warning Passing the wrong message arguments with a message is one of the more common errors in PenPoint programming. The C compiler will not catch the error.

If the class handling the message expects different arguments, it will blindly read past the end of the structure you passed it, and if it passes back values, it will overwrite random memory. A given class receiving a given messsage has to be given a pointer to the appropriate structure, otherwise unpredictable results will occur:

but it can't enforce this.

There are many classes which inherit from clsLabel, consequently, if you used one of these, you wouldn't even have to change the initialization of the structure. For example, clsField inherits from clsLabel, and FIELD_NEW includes the same NEW_ONLY structures as LABEL_NEW, so it takes the same border and label specifications.

".. Highlights of the Second HelloTK

HELLOTK2.C is much like HELLOTKl;c'·Thebig difference is that it supports more than one window. Most applications have many windows within their frame.

You compile and run it the same way. Just copy HELLOTK2.C to HELLOTK.C and follow the steps outlined above.

". Only One Client Window per Frame

Frames only support a single client window. But usually you'll want several windows in your application. You have two alternatives:

• Subclass clsFrame (which is very difficult)

• Create a client window that is another window, then insert all the windows you want into that client window (which is quite easy).

The toolkit provides two window classes that help you organize the windows within the client window. These are called layout windows. To understand why they're needed, you need to know a little bit about layout.

". Layout

When you're using several windows, something is responsible for positioning them on the screen. You can set a window's position and size to some value with msgWinDelta. However, if the user changes the system font size, or resizes the frame, or changes from portrait to landscape mode, the numbers you pick are unlikely to still be appropriate. It's more convenient to specifY window locations at an abstract level:

• "I want this window below that one, and extending to the edge of that other

"

one.

• "Position these windows in two columns of equal width."

The DI toolkit provides two layout classes which support these styles,

clsCustomLayout and clsTableLayout. Both are packed with features. Both lay out their ~wn child windows according to the constraints (for custom layout) or algorithm (for table layout) which you specifY. The general way of using layout windows is to create one, specifY the layout you want, and insert the windows in it.

7.3

7.3.1

7.3.2

CHAPTER 7 I CREATING OBJECTS (HELLO WORLD: TOOLKIT) 123 Highlights of the Second HelloTK

HELLOTK2.C uses a custom layout window and positions a single label.in its center using CIAlign (clCenter , clSameAs, clCenter).

II Specify how the custom layout window should position the label.

CstmLayoutSpeclnit(&(cs.metrics));

cs.child = In.object.uid;

cs.metrics.x.constraint = C1Align(clCenterEdge, clSameAs, clCenterEdge);

cs.metrics.y.constraint = C1Align(clCenterEdge, clSameAs, clCenterEdge);

cs.metrics.w.constraint = clAsIs;

cs.metrics.h.constraint = clAsIs;

ObjCallJmp(msgCstmLayoutSetChildSpec, cn.object.uid, &cs, s, error2)i

".. Possible Enhancements

You might consider trying to add one of these to HELLOTK2.C:

".,.. Fields

Change the label to be an editable field. There are several ways of handling handwriting in PenPoint. One way is to use a UI component which allows editing, clsField. Since fields have similar behavior to labels (they display a string, have a length, font, and so on), clsField inherits from clsLabei. This makes it easy to update the application: replace the lABEL_NEW structure with FIELD_NEW, and clsLabel with clsField, and recompile. You can now hand-write into the field.

7.3.3

7.3.3.1

".,.. More Components 7.3.3.2

Add some more controls, using different custom layout constraints. You should be able to put together a simple control panel.

".,.. General Model of Controls

You specify the metrics of each control when you create it, then you insert them in your layout window. The controls lay themselves out, repaint themselves, and support user interaction without any intervention on your part. When the user activates a control, the control sends its client (set in the msgNewarguments of clsControl, or by msgControlSetClient) a notification message.

For more information on controls, see Part 4: UJ Toolkit of the PenPoint Architectural Reference.

7.3.3.3

u ;!!

... ..,

o

III

II

Chapter 8 / Creating A New Class·

(Hello World: Custom Window)

This chapter describes how you create a new class. Along the way, the chapter also describes how you display the string "Hello World!" on screen by creating and . drawing in custom windows.

,.. Hello World (Custom Window)

Hello World (custom Window) creates an instance of a custom window and uses the custom window to display some text.

It's still not a very- realistic application because it doesn't me any data, but it does use an additional class, a descendant of c1sWin, to do its drawing. Your application may be able to use only standard DI components from the DI Toolkit and other PenPoint subsystems; but if not, you will be creating your own window class to draw stuff.

So far our example applications have been quite simple and have not needed to define their own classes (apart from creating a subclass of clsApp). One of the big advantages in object oriented programming is that when you do define a class, other applications can create instances of the class (rather than defining new classes on their own).

So that other applications can use the new class, developers often define each class in a single C file and then compile and link one or more C mes into a DLL. The C me that contains the application class (and has main) is compiled into an executable file.

To show this coding style, Hello World {custom Window) is implemented as an application and a separate DLL. There are two parts to Hello World (custom Window), c1sHelloWorld (the application class), ana c1sHelloWin (the window class). HELLO.C implements c1sHelloWorld and HELLOWIN.C defines

c1sHelloWin. HELTBL.TBL contains the method table for clsHelloWorld;

HEL WTBL.TBL contains the method table for clsHello Win.

". Compiling the Code

Compiling and linking the Hello World (custom Window) executable is somewhat similar to compiling Empty Application. However, Hello World (custom Window) is compiled and linked in two parts: an EXE me that contains the application, and a DLL file that contains the window class (c1sHelloWin).

You can build Hello World (custom Window) by changing directory to

\PENPOINT\SDK\SAMPLE\HELLO and typing wmake.

8.1

8.1.1

Note that because the application class, clsHelloWorld, and its window class are in different files, compiling is more efficient if they have separate method table files (HELTBL.TBL and HELWTBL.TBL).

linking DLLs

When you link DLLs (dynamic link libraries), the information you provide the linker is slightly different from the information you provide when linking an executable image. If you use the makefile to build Hello World (custom window), the file builds the command file for you. If you created the command file by hand, it would contain:

SYSTEM PenPoint DLL

NAME \386\PENPOINT\app\hello\hello.dll DEBUG ALL

FILE helwtbl.obj FILE dllinit.obj FILE hellowin.obj EXPORT=dll

LIBRARY penpoint LIBRARY win

SEGMENT CLASS 'CODE' Share, CLASS 'DATA' Share, CLASS 'BSS' Share OPTION Modname='GO-HELLO_DLL-Vl(O)'

OPTION Map=hello.mpd OPTION Quiet,NOD,Verbose

For contrast, here is the command file for the Hello World (custom window) executable file:

SYSTEM PenPoint

NAME \386\PENPOINT\app\hello\hello.exe DEBUG ALL

FILE heUbl.obj FILE hello. obj LIBRARY penpoint LIBRARY app

OPTION Quiet, Map=hello.mpe, NOD, Verbose, Stack=15000, MODNAME='GO-HELLO_EXE-Vl(O)' In addition to this command file, the WATCOM linker also requires a DLL.LBC

file. This file lists all the exported functions defined in the DLL being linked.

Usually, PenPoint DLLs only have the single entry point DLLMain. The lines in the DLL.LBC file have the form:

++entry-point.go-lname

The case doesn't matter in the DLL.LBC file.

The go-lname is used by the PenPoint installer to identifY code modules. An Iname is composed of a company ID, a project name, and a revision number in the forin Vmajor (minor) . Where major is the major revision number and minor is the minor revision number.

Thus, for Hello World (custom window), the DLL.LBC file contains the single line:

++DLLMAIN.'GO-HELLO_DLL-Vl(O)'

CHAPTER 8 I CREATING A NEW CLASS (HELLO WORLD: CUSTOM WINDOW) 127 Hello World (Custom Window)

~,. DLe Fiies

Because Hello World (custom window) requires that HELLO.OLL be loaded before HELLO.EXE can run, you need to have a HELLO.DLC file in the Hello World , (custom window) application directory that expresses the relationship:

GO-HELLO_DLL-Vl(O) hello.dll GO-HELLO_EXE-Vl(O) hello.exe

The PenPoint installer uses this information when installing the Hello World (custom window) application. The first line indicates that the Hello World (custom window) application depends on the DLL file HELLO.OLL, version 1(0).

Should this DLL already be loaded, PenPoint will not attempt to load it. The second line tells PenPoint to install the executable file HELLO.EXE.

Because the PenPoint name of the application directory is "Hello World," the makefile must STAMP the .OLC file with the name "Hello World" so that the Installer will find it.

Im Dokument PenPomt GO (Seite 130-136)