Preface

When I began writing the first edition of PROGRAMMING WINDOWS in the early spring of 1987, Microsoft Windows 1.0 had been released for about a year and a half, a beta-test version of Windows 2.0 was just becoming available, and Windows 3.0 could only be regarded as a far-fetched dream. At that time, the eventual success of Windows in the personal computer marketplace was more a matter of faith than a certain-to-come reality.

With the release of Windows 3, more people than ever are interested in this operating environment. Windows 3 runs Windows programs in Intel 80286–compatible protected mode, giving Windows and Windows programs access to 16 megabytes of memory. This exciting enhancement to Windows--coupled with the many Windows applications released over the past few years--has made Windows 3 an important piece of systems software released for IBM-compatible personal computers. Windows is the graphical interface that many computer users will first encounter.

Since the publication of the first edition of PROGRAMMING WINDOWS in early 1988, many programmers have told me that the book has been useful in helping them learn how to write applications for Windows. Nothing could make me happier.

It was my intention with the first edition of PROGRAMMING WINDOWS to show the basics of writing programs for Windows using the C programming language. A book like this cannot delve into the complexities of a full-fledged application program, of course, but it can show how to handle all the various components of a Windows program. It is up to the application programmer to merge these components into a coherent whole.

In this second edition of PROGRAMMING WINDOWS, I have updated the text where necessary, updated the code listings for a more modern style of C programming, tightened the early chapters (where I felt I had been more theoretical than practical), and added two new chapters--None on Dynamic Data Exchange (DDE) and one on the Multiple Document Interface (MDI). Interestingly enough, the Windows application program interface has been fairly stable over the years and very few changes had to be made to the sample programs.

Windows has a reputation for being easy for users but tough for programmers. Often, aspiring Windows programmers face a steep learning curve, and they want to see lots of programming examples. To satisfy that desire, this book contains more than 50 complete programs. Many of them are short and stripped down to clearly illustrate various Windows programming techniques. Others are a bit longer to show how everything fits together. Several of the programs are useful utilities. Others are tools for exploring Windows.

What I don't do in this book is teach you how to use Windows. If you have no experience using the environment, now is the time to install it and play with it for awhile. Windows is very easy to learn.

PROGRAMMING WINDOWS

Nor will I teach you how to program in C. Before you even think about programming for Windows, you should have a good working knowledge of programming in C for a more conventional environment such as MS-DOS. If your C is a little rusty, you may want to spend some time becoming better acquainted with the topics of structures and pointers.

A good familiarity with the segmented architecture of the Intel 8086 family of microprocessors will also help. If you know how 80286 addressing works (in both real mode and protected mode) and the difference between near and far pointers and functions, you're in good shape. If you don't, I've included some explanations along the way.

To compile the programs in this book and to write your own programs for Windows, you need the following software packages:

Microsoft Windows 3

Microsoft Windows Software Development Kit 3

Microsoft C Professional Development System (aka Microsoft C 6)

If you haven't yet installed Microsoft C 6, you should know that the programs in the book require only the small-model MS-DOS libraries using the math emulator. You may be able to use a C compiler other than Microsoft's if the compiler is suitable for compiling Windows programs. Most other C compilers can't be used for this purpose.

To run Windows and the Windows Software Development Kit, you need the following hardware:

An IBM personal computer (or compatible) based on the Intel 80286 or 80386 microprocessor with a hard disk and 640 KB of memory running MS-DOS 3.1 or later. An 80386-based machine with a couple megabytes of extended memory is ideal.

A graphics display and video board, preferably compatible with the IBM VGA (Video Graphics Array) or better.

A mouse. Although a mouse is generally optional for most Windows programs, some of the programs in this book require one.

Sometimes readers of computer books are curious about the author's own system. When I was writing the first edition of PROGRAMMING WINDOWS, I used an IBM PC/AT Model 339 (8 MHz) with two 30-megabyte (MB) hard disks, 512 KB of memory on the system board, and a 1.5 MB Intel Above Board PS/AT. The system included a Microsoft mouse, an IBM 256-KB Enhanced Graphics Adapter (EGA), and a NEC MultiSync monitor. I wrote the book using WordStar 3.3 and printed everything on an IBM 5152 Graphics Printer.

For the second edition, I used a 20-MHz IBM PS/2 Model 70 with a 120-MB hard disk, 6 MB of memory, an IBM 8514/A graphics board (although I generally ran Windows in VGA mode), a NEC MultiSync 4D monitor, and a Microsoft mouse. I used Microsoft Word for revising the book chapters, printing on a NEC SilentWriter LC-890 PostScript printer. (Word for Windows was not available until I was well into the revision.)

PA book such as this could not have come about without help and encouragement from some very special people. I offer my heartfelt thanks with a handshake or hug (as appropriate) to the following people:

To everyone at Microsoft involved in Windows 3, for creating a system with fascinating depth and seemingly endless things to learn.

To all the Windows 3 developers who reviewed my chapters and offered comments and suggestions: Clark Cyr, David D'Souza, and particularly David Weise.

To the MS Online System Support people in the Windows SDK group who reviewed galleys of the entire book: Much gratitude to Todd Cole, who volunteered his group and coordinated the effort; special thanks to John Hagerson, Mike Thurlkill, Dennis Crain, David Long, Ed Mills, Steve Molstad, Richard Herrmann, Dan Boone, and Kyle J. Sparks; thanks also to Jeff Stone, Dan Quigley, Steve Thompson, Larry Israel, Teresa Posakony, Neil Sandlin, Curt Palmer, David Flenniken, Charles E. Kindel Jr., and Doug Laundry.

To everyone at Microsoft Press who has been involved in the first and second editions of PROGRAMMING WINDOWS, for behind-the-scenes work that makes all the difference in the world.

To my friends and editors at PC Magazine and Microsoft Systems Journal for their help and encouragement over the years.

To the readers of the first edition of PROGRAMMING WINDOWS who wanted to see a second edition. It's here and it's yours!

To my family, who thought I was crazy when I quit my job to write full time: to my Mom, my brother Steve and his wife Bernie and Christopher and Michelle, my sister Sue and her husband Rich and Erika and another one on the way. You're right. I was crazy.

To my friend Karen. Words cannot express....

To my friends at the ”DH“ (and especially Devon and Leslie) for enjoyable company and interesting conversation that has nothing whatsoever to do with computers. Completing this book gets me closer to writing that novel!

And most of all, as always, to Jan, who was as happy as I was when I called her and said, ”I finally finished the chapter on DDE.“

Charles Petzold

July 29, 1990