db@tc.fluke.COM (Dan Banay) (07/25/90)
C++ is a general purpose programming language designed to make programming more enjoyable for the serious programmer. - Bjarne Stroustrup Note: Due to the large number of requests I have received, I am posting this review of ZTC++ and CNS C++/Views. Hopefully this review will provide enough information so that an informed choice can be made about the products. I have attempted to present both the good and bad points of the combination. We have all heard (or experienced) the dreaded learning curve for Windows programming. Even experienced Windows programmers have trouble keeping all the details straight. This review describes the use of Zortech C++ (2.06) and CNS C++/Views for Windows programming. Specifically, it describes how the windows learning curve can be significantly reduced. This reviewss Zortech C++ 2.06 because I am still waiting for my upgrade to arrive. :-( I am also forced to use the Windows 2.1 SDK because I am still waiting for the Windows 3.0 upgrade notice to arrive (Microsoft says that they will send them out in a "few weeks"). Wait Wait Wait. First Zortech C++. I've been using ZTC++ for about a year now (Windows programming for about 8 months) and have found it to be a solid and efficient compiler. Before that, I did most of my Windows programming using Microsoft C 5.1. Let's face it, Windows programming is a real pain. I figured that I would use ZTC++ to write some Windows objects and make my life easier. This worked to some extent, but I quickly discovered that in order to produce a really good set of Windows objects, I would have to have a deep understanding of the Windows API. Maybe it's just me, but it's hard to keep all the details straight; IMHO, the Windows API is much *too* complicated. If you saw the SunView API, you'd know what I mean. Recently, I received an upgrade notice from Zortech, which featured the CNS C++/Views package. As the song goes, "Just one look..." The CNS C++/Views package (environment) features a SmallTalk-like browser and a set of objects. The 60 plus objects provide a GUI-independent layer which makes windows programming (IMHO) a snap. C++/Views is distributed on 3 high-density 5.25" floppy disks which includes *full* source code for all the libraries (but not the browser), and plenty of sample code. Accompanying the disks is a handsome 3 ring binder with, for the most part, excellent documentation. The manual is divided into two sections: The user guide (257 pages with index) and the class catalog (224pgs). The user guide provides many examples which will help you grasp the concepts quickly. To use C++/Views, you will need: * Zortech C++ v2.0 (or above) or any C++ 2.0 (or later) compilers/ preprocessors compatible with MS Windows. * DOS 3.0 or later (recommended). You will need a 286 or 386 with at least 2MB of RAM to run the browser efficiently. * Microsoft Windows Software Development Kit, version 2.1 or later. Installation of C++/Views is fairly straightforward if you are using the preconfigured libraries (Zortech C++ 2.1). For ZTC++ 2.06, you will have to rebuild the library (a real hassle - email me if need to do this). In addition to the classes, the package consists of a browser, an archive utility, a documentation generator, and a utility to convert Dialog Editor files to C++ code. When I first saw the browser, I was reminded of the SmallTalk environment. The browser contains three main windows: a window listing all the classes for the current application, a window listing class members for the currently selected class, and a text editor with which you can edit class members and other code. Not only does the browser provide an efficient means of keeping track of objects, it keeps track of dependencies (generates makefiles, .DEF files, etc.) and class documentation. What it does *not* do is run the compiler. To run the compiler, you can run an instance of command.com and type "make" in the project directory. Despite this, the browser is a joy to use -- I don't know how I got along with out it. One of the best parts of this package is that it is *open*. That's no marketing trick, it IS open. If you don't like the way the browser generates makefile or linker directive files, you can edit the corresponding template file. Then, when a new file is created, the corresponding template file will be used (with substitutions). It is also very easy to import other classes, and so forth. For reasons of efficiency, classes and header files can be stored in a pre-parsed format known as ARC files. It is very unfortunate that CNS chose that name, because people will invariably think of the popular ARC program that we all know and love. In order to parse the files, there are some restrictions: * One source file (.c, .cpp, .cxx) and one header file (.h or .hxx) per class. * One and only one class declaration in a header file. * All and only the class member function definitions of that class declaration in the source file. * No explicit pointer to function or pointer to member types are allowed for variables, function arguments or function return types (i.e. int (* f)() is a no-no). You can use typedefs instead. * Friend functions may *not* be declared inline. * C preprocessor include directives must be grouped together without intervening preprocessor directives of C++ declarations. (pg 16 of the user manual) While some of these restrictions may seem severe, keep in mind that the way you work with code will be different. You use menus to add classes, super classes, variables, and methods. To edit an existing entity, you simply click on it with the mouse. This will cause the entity to appear in the text editor. The browser maintains all the dependencies, etc., so that you can concentrate on the task at hand. In reality, each all members of a class will appear in the same file. It is really difficult to describe how the browser "feels," but at least for me, it is very natural. BTW, the browser is probably the best example of an application written using the C++/Views object library. It runs just fine in Windows -- and ANY OTHER environment that the object library supports (they appear to be targeting the MAC, X Windows, and MS Windows). In fact, a lot of the sample code in the manual comes straight out of the browser (e.g. TextEditor objects). The object library consists of 60 classes which provide a GUI independent means of writing graphical applications. In fact, you can use many of these objects to write vanilla DOS applications! The objects implement a Model-View-Controller paradigm (MVC). Briefly, MVC divides the applications into three parts: * The Model: the representation of the functionality -- loosely, the data structure(s) used to represent the process. * The View: How the model is presented (graphics,etc). How it looks to the user. * The Controller: The "boss." User input sends messages to view layer, which in turn sends messages to the Model part in order to obtain information. There was an excellent article by Adele Goldberg in a recent issue of Dr. Dobbs Journal about MVC. See "Smalltalk-80: The Language and its implementation" by Goldberg and Robson for additional details. Here are some of the classes provided: Assoc (association lists), PointArray, Collection, OrdCollection, Stack, Set, Dictionary, Tokens, String, Stream, File, Archiver (object persistance), Serial (port), ToFmStream, TagStream, TokenStream (last two are used to build browser -- you can give the benefits of templates to your own apps), Notifier (more on this later), Clipboard, Display, BitMap, Printer, Window, Control (Buttons, CheckBox, RadioButton, etc), View (AppView, ControlView, PopUpWindow, etc), ScrollBar, TextBox, EditBox, EditLine, TextEditor (which can be attached to a file -- complete with cut and paste), Dialogs (ListSelect, FileSelect, Input, Report, YesNo, About).... pant pant ;-) CNS really did its homework-- the classes are superb. The only glaring omission I could find was the lack of classes for handling fonts. But, since the system is open, it can be added by subclassing AppView. Also, the Port object only provides 8 colors (althought it looks like you can define additional ones -- but is it portable?) Before I get into code, I should point out that C++/Views uses the LARGE memory model for Windows. If you read Petzold's book (or look at it every time you try to remember the name of a message) you know that this is discouraged. What this means is that the data segment must be fixed. It also means that far (32 bit) pointers are always used. In prior versions of Windows, this was a big deal -- but with Windows 3.0 I don't think it really makes that much of a difference. You can, however, specifiy (using -D compiler option) that you want objects allocated on the near heap (or far heap). Also, memory handles are supported, and you can use them if you want. I wanted to point this out, because executables will be a bit larger -- figure on approximately 70K just to hold the classes. Actually, once you get past the initial 70K, the code won't grow as quickly because most of what you will need is provided for you. Ok, I'm sure that at this point, folks want to see code. The following program implements the "countess." Countess is a simple window (resizeable, with system box, and min/max buttons) which responds when given focus (i.e. when clicked upon). To keep things simple, it prints "you have touched me x time(s)." -- don't laugh, I'm trying to keep it small enough to discuss. ;-) First the main program: // // countess.cpp - Zortech C++ and CNS C++/Views // note: This program was written after spending two days reading the manual. // In four days, you'll be doing stuff you never dreamed of doing. // READ THE ENTIRE MANUAL BEFORE YOU TRY WRITING CODE. I'm glad I did. #include "notifier.h" #include "cntsview.h" char *CTWindow = __FILE__; main() { CountessView *v; v = new CountessView(); v->setTitle("Countess"); // change title bar v->show(); // display window notifier.start(); // start MVC process } Keep in mind that when the you add new objects/members to the heirarchy, you will be provided a template to edit. In fact, virtually all C++/Views applications will have a main() function just like this one. In C++/Views there isn't a main window function (like in C) where you have to keep track of messages (which I can never remember without looking in the manuals 10 zillion times). Instead, the notifier sends messages to those objects which are affected. Subclasses of AppView (like CountessView) have methods for each type of message. If you want to handle these messages, you override them in a subclass. This will become clear later. Here is the class definition for CountessView: // generated by browser class CountessView : private AppView { private: boolean clearFocus(); // called when window loses input focus boolean givenFocus(); // called when window received input focus int cnt; // number of times the countess has been touched public: boolean paint(); // handles update of client area boolean free(); // internal CountessView(); // constructor ~CountessView(); // destructor }; Before I continue, I should note that there are two ways to specify object dimensions (for Windows, controls): In device units, or "percents" (sounds like Normalized Device Coordinates to me). The empty constructor opens a large default window (resizable, with min/max buttons). Normally, you don't have to handle each type of message that is sent by the notifier -- defaults are handled by the AppView superclass. For my example, I will need to handle: paint, givenFocus, and clearFocus. As an added twist, I'll make the cursor change shape when it passes over the countess window. Here then, is the implementation: // constructor: reset count to zero CountessView::CountessView() { cnt = 0 ; } CountessView::~CountessView() { ; // do nothing } // handle window update boolean CountessView::paint() { char buf[35]; sprintf(buf,"You have touched me %d times!",cnt); wrtText(buf,5,5); return TRUE; // signal that we handled it // NOTE: you could call notifier to get the exposed rectangle if // you wanted to. } // have focus (clicked on window) boolean CountessView::givenFocus() { notifier.setCursor(Cross); // change to + cnt++; update(); // force paint message return TRUE; } // lose focus (clicked on another window) boolean CountessView::clearFocus() { notifier.restoreCursor(); // restore cursor return TRUE; } The executable is about 70K. Notice how little source code is required to complete the task. For me, the nicest thing is that I can *remember* all this stuff without having to look in the manual. I have found this to be a *lot* easier than using the SDK and C. Also, with the browser, code from one project can be reused *easily* in another project. Some other Window messages: boolean mouseMv(int x, int y); called whenever mouse moves boolean mouseEnter/Exit (int button); called when mouse enters/exits object boolean nextFocus() called when TAB key hit -- typically the next thing to do would be to find the next sibling (represented as an ordered collection). boolean moved(int x, int y); called when the window is moved Other objects make using keyboard accelerators and timers a snap. Another notable class is the Port class. The Port class provides graphics support. With it, you can draw shapes, lines, text, viewing transforms, etc. A subclass of Port, called Printer, provides a device independent way to produce graphics hardcopy. Since Printer is a subclass, any message you can send to Port, you can also send to Printer. C++/Views comes with a number of sample programs which really demonstrate its power: * The Browser: As I mentioned before, it was implemented using the library (no source code provided). * Scribble: Demonstration of mouse tracking. * FHistory: C++ version of the Financial History View MVC tutorial from Goldberg and Robson. Very nice barcharts, etc. * Sketch: Expands on Scribble by providing a full MVC application that demonstrates polymorphism as well as use of the Archiver class to store drawings into a disk file (persistent objects). * Draw: Demonstration of the Port class (BitBlt, colors, clipping). My experience with ZTC++ and C++/Views has been very pleasant. Zortech and CNS have provided a means of developing Windows applications without the hassles associated with the SDK and C. The process is much more enjoyable. I strongly recommend the combination for those folks are tired of struggling with the SDK or want to try a better (IMHO) way. Disclaimer: I am in no way associated with Zortech or CNS -- other than as a *VERY* happy customer. Dan p.s. If you have any additional question about ZTC++ and/or C++/Views for developing windows applications, send email and I'll try to answer them. -- +------------------------------------------------------------------------+ | Dan Banay | | db@tc.fluke.COM {microsoft,sun,uw-beaver}!fluke!db +1 206 356 6285 | +------------------------------------------------------------------------+ | John Fluke Mfg. Co., MS 223B, PO Box 9090, Everett, WA 98206-9090 USA | +------------------------------------------------------------------------+
db@tc.fluke.COM (Dan Banay) (07/25/90)
Sorry, I neglected to mention a few things: * CNS C++/Views costs ~$500 (varies depending where you buy it from). * CNS can be reached at: CNS, Inc. Software Products Dept. 7090 Shady Oak Road Eden Prairie, MN 55344 USA (612) 944-0170, FAX: (612) 944-0923 * You can reach Zortech at: USA Zortech Inc., 4-C Gill Street WOBURN MA 01801 (617) 937-0696 FAX: 617-937-0793 EUROPE Zortech Ltd., 58-60 Beresford Street, LONDON SE18 6BG 081-316-7777 FAX: 081-316-4138 Sorry I didn't include this in the review. Dan -- +------------------------------------------------------------------------+ | Dan Banay | | db@tc.fluke.COM {microsoft,sun,uw-beaver}!fluke!db +1 206 356 6285 | +------------------------------------------------------------------------+ | John Fluke Mfg. Co., MS 223B, PO Box 9090, Everett, WA 98206-9090 USA | +------------------------------------------------------------------------+
maba@doitcr.doit.sub.org (Martin Backschat) (07/31/90)
In article <1990Jul24.174401.2874@tc.fluke.COM> db@tc.fluke.COM (Dan Banay) writes: } } Sorry, I neglected to mention a few things: } } * CNS C++/Views costs ~$500 (varies depending where you buy it from). } } * CNS can be reached at: } } CNS, Inc. } Software Products Dept. } 7090 Shady Oak Road } Eden Prairie, MN 55344 } USA } } (612) 944-0170, FAX: (612) 944-0923 } } } * You can reach Zortech at: } } USA } } Zortech Inc., 4-C Gill Street } WOBURN MA 01801 } (617) 937-0696 B } FAX: 617-937-0793 } } } EUROPE } } Zortech Ltd., 58-60 Beresford } Street, LONDON SE18 6BG } 081-316-7777 } FAX: 081-316-4138 Zortech (England) told me, that they will sell CNS/C++ Views for 200 Pounds to registered ZTC++ users until end of august. Martin "Maba" Backschat