
Copyright© 1998 by Charles Petzold

PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright (c) 1998 by Charles Petzold
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any
means without the written permission of the publisher.
Library of Congress Cataloging-in-Publication Data
Petzold, Charles, 1953-
Programming Windows / Charles Petzold. -- 5th ed.
p. cm.
Rev. ed. of: Programming Windows 95.
Includes index.
ISBN 1-57231-995-X
1. Microsoft Windows (Computer file) 2. Operating systems
(Computers) I. Petzold, Charles, 1953-. Programming Windows 95.
II. Title.
QA76.76.O63P533 1998
005.265--dc21 98-42529
CIP
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 WCWC 4 3 2 1 0 9
Distributed in Canada by Penguin Books Canada Limited.
A CIP catalogue record for this book is available from the British Library.
Microsoft Press books are available through booksellers and distributors worldwide. For further information about
international editions, contact your local Microsoft Corporation office or contact Microsoft Press International
directly at fax (425) 936-7329. Visit our Web site at mspress.microsoft.com.
Macintosh, QuickTime, and TrueType fonts are registered trademarks of Apple Computer, Inc. Intel is a registered
trademark of Intel Corporation. Developer Studio, DirectX, IntelliMouse, Microsoft, Microsoft Press, Microsoft
QuickBasic, MS-DOS, MSDN, Natural, Visual Basic, Visual C++, Visual Studio, Windows, and Windows NT are
either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Other product and company names mentioned herein may be the trademarks of their respective owners.
The names of example companies, products, people, characters, and/or data mentioned herein are fictitious and
are in no way intended to represent any real individual, company, product, or event, unless otherwise noted.
Acquisitions Editor: Ben Ryan
Project Editor: Devon Musgrave
Technical Editor: Dail Magee, Jr.


Author's Note
Visit my web site www.cpetzold.com for updated information regarding this book, including possible bug reports
and new code listings. You can address mail regarding problems in this book to [email protected]. Although
I'll also try to answer any easy questions you may have, I can't make any promises. I'm usually pretty busy, and
my cat refuses to learn the Windows API.
I'd like to thank everyone at Microsoft Press for another great job in putting together this book. I think this "10
th
Anniversary Edition" of Programming Windows is the best edition yet. Many other people at Microsoft (including
some of the early developers of Microsoft Windows) also helped out when I was writing the earlier editions, and
these fine people are listed in those editions.
Thanks also to my family and friends, and in particular those more recent friends (you know who you are!) whose
support has made this book possible. To you this book is dedicated.
Charles Petzold
October 5, 1998

Chapter 1
Getting Started
This book shows you how to write programs that run under Microsoft Windows 98, Microsoft Windows NT 4.0, and
Windows NT 5.0. These programs are written in the C programming language and use the native Windows
application programming interfaces (APIs). As I'll discuss later in this chapter, this is not the only way to write
programs that run under Windows. However, it is important to understand the Windows APIs regardless of what
you eventually use to write your code.
As you probably know, Windows 98 is the latest incarnation of the graphical operating system that has become the
de facto standard for IBM-compatible personal computers built around 32-bit Intel microprocessors such as the
486 and Pentium. Windows NT is the industrial-strength version of Windows that runs on PC compatibles as well
as some RISC (reduced instruction set computing) workstations.
There are three prerequisites for using this book. First, you should be familiar with Windows 98 from a user's
perspective. You cannot hope to write applications for Windows without understanding its user interface. For this
reason, I suggest that you do your program development (as well as other work) on a Windows-based machine
using Windows applications.
Second, you should know C. If you don't know C, Windows programming is probably not a good place to start. I
recommend that you learn C in a character-mode environment such as that offered under the Windows 98 MS-
DOS Command Prompt window. Windows programming sometimes involves aspects of C that don't show up much
in character-mode programming; in those cases, I'll devote some discussion to them. But for the most part, you
should have a good working familiarity with the language, particularly with C structures and pointers. Some
knowledge of the standard C run-time library is helpful but not required.
Third, you should have installed on your machine a 32-bit C compiler and development environment suitable for
doing Windows programming. In this book, I'll be assuming that you're using Microsoft Visual C++ 6.0, which can
be purchased separately or as a part of the Visual Studio 6.0 package.
That's it. I'm not going to assume that you have any experience at all programming for a graphical user interface
such as Windows.