Windows programming from scratch. (Microsoft's C/C++ 7.0 program development software)(includes related articles) (Software Review) (Evaluation)
by Tom Campbell, Clifton Karnes
Sometimes, a deal comes along that's so sweet you're foolish not to take advantage of it. Microsoft's C/C++ 7.0 is one of those deals. If you're serious about programming in Windows and haven't yet decided on a development environment, get it.
Microsoft used to sell its professional C development system for $450. It's added a C++ compiler and tossed in the SDK (the latter without printed documentation) and dropped the price to an obscenely low $139. You get 5000 pages of fabulously written and superbly printed documentation on C, C++, the runtime libraries, and the highly esteemed Microsoft Foundation Classes (MFC). You also get a somewhat staid but incredibly flexible programming environment, a topnotch debugger, the debug version of Windows, and a substantial amount of online documentation for less used features, which doesn't appear anywhere in the printed manuals.
Unless you already have a comprehensive library of third-party books on the SDK, go the extra $150 for the printed manuals (see "Should You Fight or Switch?" if you're still not convinced). This article assumes you're willing to trade six months of intense study of the Windows API and C++ in exchange for guru-level Windows programming skills, and that you may, but probably dont, have a favorite development system (other than Microsoft's) already. If so, it will help you decide whether Microsoft gives you the best tools for the job.
Don't make the mistake of thinking that all of these tools and manuals will make programming Windows applications easy. They won't. What they will do, however, is to provide the strongest foundation any programming environment has ever had for any operating system--and all in a single environment. Nor are all of these tools the very best. Here, though, the whole vastly exceeds the sum of its parts.
Installing C/C++ 7.0 and the SDK took about an hour on my 33-MHz 386, and consumed a terrifying 50MB of disk space. You need not apply if you don't have at least a 386, by the way.
C/C++ 7.0 is so memory hungry that Microsoft throws in a $150 memory manager called 386-to-the-Max that you have to run if you fire up the compiler on DOS (you don't need the memory manager to run C/C++ 7.0 from a DOS box in Windows, however).
As I mentioned above, my installation took 50MB. Expect to surrender about 40 megs for a minimal system. The installation programs to a great job of letting you choose what to install, so you can easily shave 10 megs from that number (by eliminating online help options and sample code), or you can add 10 megs to it (by adding a couple of memory models and including the full complement of online help).
In a vivid metaphor for the greatest weakness of C/C++, the C/C++ installation program forced by machine into running Windows. Then, not only did the SDK installation refuse to run under Windows, but it wouldn't even run in a DOS box. You must exit Windows to install the SDK--the modules used to create Windows applications! And in fact, there's no Windows environment in which to program Windows application: you must compile under DOS and then switch to Windows to run the program. This is the product's Achilles heel, and it's made acceptable only by the correspondingly high quality and selection of the other tools and documentation.
A Windows program is usually made up of several C or C++ source files, a resource script (which instructs a set of auxiliary tools to construct dialog boxes and other parts of the user interface), a command file just to run the linker, and a text file describing this process for a utility called Nmake, which oversees the entire process and helps you avoid wasting time during this necessarily slow and laborious process.
The C compiler takes care of the C or C++ source files, natch. Another utility or three will process the resource scripts, and the linker literally puts them all together. If this sounds like a much slower turnaround time than with, say, Visual Basic or ToolBook, you're right. If you suspect that you can probably do a ton of things with the SDK that would be totally impossible in Visual Basic or ToolBook, you're right again. (What language do you think they were written in, anyway?)
Hammering Out the Code
The C 7.0 compiler is no speed demon, but it turns in respectable times. Slower than Borland but faster than Watcom, it produces solid code with some good optimizations. There are many, many command line switches and extensions to the C language to let you fine-tune the generated code. The C++ support seems to be good, but the C++ classes I've written are only a few thousand lines long. Note that while the product is called C/C++ 7.0, the 7.0 only applies to the C compiler itself. C++ support is at version 1.0, but I've heard of very few bugs in the C++ compiler. That's an unexpected but very welcome development.
The linker is also much slower than Borland's, but on projects of over 50,000 lines or so, they start to reach parity; Microsoft seems to have a pronounced lead in resolving thousands of references at a time. The dialog, font, and bitmap editors are all good, and I'd say they were excellent if I hadn't seen Borland's Resource Workshop. But they more than do the trick. In neither product can you edit TrueType fonts. One unique tool is the Hotspot Editor, most helpful for editing the clickable images in online help.
Windows programmers never have enough debugging tools, but Microsoft goes a long way toward redressing that problem with this release. The MFC has a full complement of integrated debugging and memory-tracing macros. A replacement Windows kernel that runs dogslow but which catches many heretofore invisible programming errors gives you one of the ultimate tools there is--an operating system that helps you debug. (It's also fun to see how other programs fare under the debugging kernel, because you don't need source code to find out what's going on with a Windows executable.)
Utilities are included to monitor Windows messages and view Windows memory usage graphically. HeapWalker, for example, shows you icons and cursors in memory while Windows is running. Stress lets you fake heavy system usage to see how your program survives in the low-memory conditions that seem to be a way of life in multitasking environments, and the serviceable Source Profiler lets you see what routines eat up the most time.
I can't say CodeView is my favorite debugger, but it does the trick. It can finally work with Windows applications in graphics mode, unlike Borland's Turbo Debugger, and it fully understands C++. If you have a second monitor, such as a Hercules, you can use it to show code while the program runs unmolested under Windows.
Microsoft Makes Good
Microsoft deserves to be a billion-dollar company, and one of the main reasons is that it learns from its mistakes. The documentation for its C 5.1 was so good that I actually sent a fan letter, but that documentation consisted of three loose-leaf volumes. It costs a lot to print and ship that many manuals, and many users claimed to be sick of so many books.
Consequently, version 6 came with just a few introductory paperback texts and the rest of the documentation online. I was so disgusted that I didn't even ask for a review copy. Meanwhile, I switched to Borland but used Microsoft's great version 5 documentation because I couldn't find its equal anywhere.
Evidently, a lot of users felt the same as I did, because Microsoft has finally bounced back with the best documentation of any development system around. It would take an article at least this long just to outline all the manuals, but here are the highlights.
A slim but complete Getting Started guide takes you through not just installation but where to go depending on whether you want to code in C or C++, DOS, or Windows. To learn how to program Windows in C++ using MFC, take the time to read the 400-page C++ Class Libraries User's Guide. Although Getting Started implies you can learn to program Windows from scratch with this book, you probably can't. You'll probably need to learn C and plow through Charles Petzold's excellent Programming Windows, even though you'll have some unlearning to do when you use MFC.
C++ Class Libraries User's Guide is a great way to see real live C++ classes in action and to learn MFC itself. There is also a much-needed tutorial on the iostream class of C++, which is infinitely more powerful than the C standard I/O library but harder to learn. It goes deep into the heart of the iostream, even showing you how to create your own manipulators, which format output more flexibly than vprintf( ). The tutorial develops a Windows phone book application of several thousand lines, so you get a realistic view of MFC in action.
Programmer's Reference, Volume 1: Overview is the kind of book that should be with every major programming environment but never is. Certainly, Borland has nothing like it, and ridiculously few third-party books even approach it in scope. This is truly an overview, directed at the capable Windows programmer but covering issues that only an expert could explain properly. There's a section on the new common dialogs with code fragments; an extensive, if still too short, section on OLE; a section on GDI; and a short description of network programming issues. These are all well and good, but there are some tremendous bonuses. The data decompression API is covered, a whole section on writing screen savers comes with the code for a screen saver, a stress testing section shows you how to shake out memory leaks, and some useful tips for international applications round out the group.
C and C++ language reference guides explain Microsoft's implementation and compare it to the international C and C++ standards. Anyone interested in portable software (not to mention compiler design) is well advised to scrutinize the section comparing ANSI C to the Microsoft flavor, which is a superset of ANSI.
The trendier among you will appreciate manuals on multimedia and pen support; these aren't as well documented as some of the more mature parts of Windows, but they're still exceptionally well covered. Along with the working example code, this is enough to get you going for 90 percent of your pen and multimedia programming needs; for the other 10 percent, you'll need to visit Compuserve.
Although this article is mostly concerned with the C programmer, it would be a crime not to mention that the DOS runtime library reference has examples for every routine and can hold its own with any book on the shelf at B. Dalton. The reference is in alphabetical order but preceded by summary chapters that attack the subject from all possible angles. Every routine and variable has example code, and a see-also note is provided whenever it makes sense. Not only is the manual itself a masterwork, but the DOS runtime and graphics libraries have both grown to be major achievements. Read the first chapters carefully before you create your next DOS app, because there's a good chance a lot of the code you expected to write will already be there, ripe for the picking.
Is It Worthwhile?
I'd like some refinements to the devastatingly powerful one-two punch of the C/C++ and SDK bundle. Obviously, the compiler and editor should be Windows based and run faster. I'd like more on learning to program Windows in C. I still don't like CodeView as much as Turbo Debugger.
But these shortcomings pale when set against what can only be described as a magnificent product. There is simply no other way to get so many high-quality tools and so much insanely good documentation at such a low price. If you're serious about programming Windows applications from scratch, you can't go wrong with Microsoft C/C++ 7.0.
IBM PC or compatible (80386 or faster), 4MB RAM, hard drive with 20-to 50MB free, 1.2- or 1.44MB floppy drive, Windows 3.0 or higher--$495 list, $139 on special; printed SDK documents--$150 extra
Should You Fight or Switch?
Questions and answers about the development deal of the decade:
Q. Isn't $150 a lot for just 5000 pages of documentation?
A. You're getting greedy. That's like buying ten books of 500 pages each at the bookstore. Assuming you pay the bargain price of $25 per book, you're still saving a hundred bucks. Spring for it. Especially if you haven't invested in a lot of third-party books, this is a nobrainer.
Q. Does that 5000 pages of documentation include any filler?
A. No, there's not a page of fluff. In fact, it's so good, I wish there were more. And there is--online. Even the 33 pounds of freight this $289 deal drops on your doorstep mentions important material that is available only online,
Q. Does all this make programming C++ or Windows easier?
A. No, no, no! At least, not as easy as, say, ToolBook or Visual Basic (which still have a learning curve that's a few weeks long). But you will find a mother lode of information, tools, code examples, and cross references you can't get anywhere else. And you'll have everything you need to program anything that can be programmed in Windows--a claim that couldn't be made for Visual Basic or any other Windows programming kit on the market. If you don't know how to program in C, you'll need an introductory text on that subject. But the C++ tutorial is fabulous, rivaling even the best of the third-party books.
Q. Should I switch from Borland C++ if I'm happy with it?
A. No, not if you're happy--but here are a few kickers. Borland's OWL sheath over Windows depends on nonstandard C++ coding, so it's not portable. However, Microsoft's Foundation Classes have been ported to Zortech, Watcom, and Borland C++. I know a number of programmers who bought the Microsoft special just for MFC, the documentation, and the abundance of development tools. As a longtime fan of Borland's, I must reluctantly suggest that a good alternative would be to buy Borland C++ without the Application Frameworks option, get the Microsoft special, and log on to Compuserve to find out how to port MFC to Borland C++.
Q. Is it worth the full $495 if I miss the special?
A. If you don't own another Windows development system, it's worth every cent--and more. If you're happy with the C you have, stick with it. Vicious competition in the development market means your product will be forced to improve its tools and documentation immensely or die a quick but humiliating death.
Q. There must be a downside. What don't I get if I go all the way and pay $139 for C/C++ with the SDK and $150 for the manuals?
A. Tech support. Learning how to program Windows is just plain hard, and at that price, Microsoft isn't going to hold your hand. Expect to read Charles Petzold's classic Programming Windows, to do a lot of studying of the supplied manuals, and to spend a good $50 every month on Compuserve. Believe me, it's worth the investment.
Windows Programming Made Easier
It's true that programming Windows with C isn't for the fainthearted, but there are tools that can make working with C easier and faster, These tools fall into two groups: code generators and custom controls.
Code generators are programs that let you create a Windows interface inter-actively. If you've used ToolBook, or almost any Windows dialog editor, you have an idea of what this means. Instead of writing code to create the fundamental aspects of your window, you work wit a simulation of the Window and interactivity modify it to suit your
After you're satisfied with the window design, you tell the code generator to generate the source code for your interface. You then take the source code and add your own routines to handle the main tasks your window is supposed to accomplish. Finally, you compile the code, and you're done.
Code generators are expensive, but they take the most tedious aspect of Windows programming and make it quick and fun. And since it's so much easier to create an interface with these programs, you'll probably be willing to spend more time on interface design and wind up with a better, easier-to-use program. It's also easy to experiment with a code generator, which makes one a great learning tool.
The Windows code generator market is shared by three excellent programs: WindowsMAKER Pro 4.0 (Blue Sky Software, 800-677-4946, $995), Case:W 4.0 (Caseworks, 404-399-6236, $995), and ProtoView (ProtoView, 908-329-8588, $395). All three offer the essentials outlined above: You work in a simulation of your window, and when you're finished, the generator produces the code to create the simulation.
All three of these programs can generate code for every major compiler, including Microsoft C/C++ 7.0 and Borland C++ 3.1, and versions are coming out that support these two companies' C++ class libraries: the Microsoft Foundation Classes and Borland's OWL.
Case:W offers some extra features for generating CUA-compliant code, and it's the only tool that has an OS/2 Presentation Manager version. ProtoView is the bang-for-the-buck winner and has recently been selected by Borland to bundle with its C++, which is quite an endorsement.
WindowsMAKER Pro is the easiest to use of the group, and it offers some outstanding features. First, it sports a tool-bar that not only generates source code with the press of a button but lets you build your application and run it, too. You can also quickly find and edit your source code using any text editor you specify. With these features, WindowsMAKER Pro can easily become the interface for your development environment. In addition, WindowsMAKER Pro has a powerful dialog editor that supports custom controls and is very easy to use. You just can't go wrong with this program.
Programming in C can also be simplified with custom controls, In Windows, most of the objects that populate dialog boxes and other windows are called controls. The most common of these are buttons (including push buttons, radio buttons, and check-box buttons), text boxes (both for displaying text and editing it), and list boxes.
You've probably noticed that in some programs these controls appear in simple black, white, and gray, but in others they have a sculpted 3-D look. The sculpted controls are examples of custom controls. You can create these from scratch yourself, or you can buy a library. Obviously, the easier way to go is to let an expert do the work and buy a prepackaged set. There are three excellent groups worth considering: Borland's Resource Workshop (Borland International, 408-438-8400, $49.95), Blaise Computing's Control Palette for Windows (Blaise Computing, 510-540-5441, $169), and Farpoint's Drover's Toolbox for Windows (Farpoint, 614-765-4333, $345).
Borland offers only a few controls with the Resource Workshop, but they aren't the package's main attraction. The Resource Workshop is an amazing resource editor that's an unrivaled tool for creating dialog boxes and decompiling resources from exe and dll files. You'll probably want to get it whether or not you wind up using the controls that come with it.
The Farpoint and Blaise controls are both superb. They are easy to work with and produce stunning results. I've found the Blaise controls to be a little more flexible, but the Drover package comes with a huge number of functions to enhance the Windows API, which balances things out. Both are excellent values.