Home > Store

Win32 Programming

Register your product to gain access to bonus material or receive a coupon.

Win32 Programming


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 1997
  • Dimensions: 7-3/8" x 9-1/4"
  • Pages: 1568
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-63492-9
  • ISBN-13: 978-0-201-63492-1

Windows developers: a thorough understanding of the Windows API will enable you to create applications that are elegant, efficient, and powerful.

You will find comprehensive information on all aspects of Windows GUI programming, such as:

  • Windows Controls, including the common controls
  • GDI, including new features like transformations and geometric pens
  • Printing, including a reusable print engine
  • Common dialogs, including customization
  • Background processing, including synchronization

In addition, the book covers such important advanced topics as creation of Dynamic Link Libraries, storage management, windows subclassing, the Multiple Document Interface (MDI), and threads and their synchronization.

More than just an introductory book, Win32 Programming is a reference to many of the more obscure and sometimes incomprehensible advanced features of the user interface and graphics subsystems. It is useful not only for C programmers but also for C++/MFC programmers because the API forms the basis for most MFC methods. The book's extensive and comprehensive index means you will never again have to search through pages of examples to find the example of the API function you want to see. This book is designed both to teach basic Windows programming and to be a useful companion for years to come.

This book comes in two volumes they both have the same ISBN. 0201634929 B04062001

Volume 1 ends with Chapter 10, Volume 2 begins with Chapter 11.



Click below for Supplements related to this title:

CD Contents

Download the CD Contents from the book.


Web Resources

Click below for Web Resources related to this title:
WiseOwl Consulting


I'm a Windows programmer; I've made my living for quite a few years now writing Windows programs. This book is a Win32-oriented edition of Brent Rector's earlier Win16 book on Windows programming (Developing Windows 3.1 Applications with Microsoft C/C++). We've not only brought it up-to-date with Win32, we've taken Brent's basic philosophy of how to create really good Windows programs (not just Windows programs that work) and shown how to build robust, maintainable, and powerful Win32 applications. Not only do you get the basics of Windows programming, we go into extreme depth in a number of selected areas to show you how to take advantage of the power of Windows GUI and graphics facilities. This is useful not only to the beginning Windows programmer, but even to the experienced Win16 programmer who wants to learn the power of the Win32 API.

The index itself is practically a reference manual. What used to drive me crazy as a new Windows programmer was finding out exactly how to use all those API calls. We've indexed most of the interesting examples in our sample code so you can quickly find out not only the details of the API call, but find descriptions of how to use and and examples of how we use it.

Accompanying the book is a rich collection of programs, some in C and some in C++, totalling over 100,000 lines of code. Much of this is in the Explorers, a collection of programs that lets you poke and prod at Windows' internals and see useful displays of the effects of doing so.

Although this book is a revision of Brent Rector's book on Win16 programming, it is more than just a straight substitution of Win32 terms for Win16 terms. This is a complete revision, showing many new and powerful Win32 features, for example, new GUI and graphics facilities. This book focuses on how to build real applications that can be brought up rapidly and are maintainable; even our examples use what we think of as "real application" techniques--no oversimplifications for exposition. We teach not only the basics of the API, but what constitutes good "Windows style." You get sample C skeleton code you can use to build your own Windows applications.

Sample Content

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:



Table of Contents

(Most chapters conclude with "Further Reading".)

Welcome xliii.

Tools Required xliii.

Typeface conventions xlv.

Icons for insertions xlv.


Introduction to Windows Concepts.

What Is Windows?

What Is Win32?

An Historical Perspective on User Interfaces.

Differences between a Windows Program and a Typical DOS or Unix Program.

Resource Sharing.

Graphical User Interface.

What about Unix, X, Motif, OS/2, or the Macintosh?

Input Facilities.

Memory Management.

Device-Independent Graphics.

The Windows Programming Model.

The Conceptual Model.

Windows and Their Associated Window Functions.

Windows Queues and the Message Loop.

Windows Operating Modes.

Program Memory Models.

Memory Models and Porting 16-bit Code.

__cdecl and __stdcall Calling Sequences.

Static and Dynamic Linking.

Dynamic Link Libraries.

Exports and Imports, or Who's Looking for Whom?

Windows Memory Management.

The windows.h Header File.

windows.h typedef Declarations.

Getting a Handle on Handles.

Using the Windows C Runtime Libraries and Header Files.

Using Strict Type Checking.

Naming Conventions.

Function Names.

Parameter Names.

Example Code.

Diving Right In.

Further Reading.


A Skeletal Windows Application.

The Skeleton Application Source Program.

The WinMain Function.

The Parameters to WinMain.

WinMain Initialization.

Initialization: initInstance.

WinMain's Message Loop.

The Window Function.

General Structure.

Message Handling: WM_DESTROY.

Message Handling: WM_COMMAND.

The About Dialog Function.

The Components of the Skeleton Application.

Resource Definition Files.

The Skeleton.h Header File.

Building and Running the Skeleton Program.

Message Crackers.

Further Reading.


Exploring Variations on a Window.

Default Behavior for a Window.

My, How Stylish You Look.

Class Styles.

Window Styles.

Overlapped Windows.

Pop-up Windows.

Child Windows.

Other Window Styles.

Extended Window Styles.

The Panes Example Program.

The Panes Source Code.

Class Registration in Panes.

Window Creation in Panes.

Message Handling in Panes.

The Window Explorer.

Further Reading.


Displaying text in a Window.

Device and Display Contexts.

When Do You Get a Display Context?

Displaying Output upon Receipt of a WM_PAINT Message.

How Do You Get a Display Context?

Processing a WM_PAINT Message.

Using TextOut to Display Text.

Logical Coordinates and Device Coordinates.

The MM_TEXT Mapping Mode.

What Do the Characters Look Like?

How to Use Text Metrics.

Displaying Information about the Windows Environment.

Introduction to Scroll Bars.

The Parts of a Scroll Bar.

Scrolling Text.

Subclassing a Window Class.

What is subclassing?

Subclassing Techniques.

The Sysinfo Program.

The Source Code.

Sysinfo Initialization.

Subclassing the System Metrics Window Class.

Displaying the System Metrics.

Scrolling the Window.

Coming Attractions.


Examining a Device Context in Depth.

What Is a Device Context?

Display Contexts: A Specific Type of Device Context.

The Common Display Context.

The Class Display Context.

The Private Display Context.

The Parent Display Context.

The Window Display Context.

Other Types of Device Contexts.

Creating a Device Context.

The Information Context.

The Memory Device Context.

The Metafile Device Context.

The Capabilities of a Device.

The Attributes of a Device Context.

Color Attributes.

Defining a Color.

The Bitmap, Brush, Font, Pen, and Region Attributes and Objects.

Deleting objects.

Special Considerations on Object Selection.

The Mapping Mode, Window Origin and Extent, and Viewport Origin and Extent.

Various Windows Coordinate Systems.

The Viewport and the Window.

The Physical Measurement Mapping Modes.

The Remaining Device Context Attributes.

Saving and Restoring the State of a Device Context.

The DC Explorer.

Further Reading.


Graphical Output: Pixels, Lines, and Polygons.

Getting and Setting the Color of a Pixel.

Lines, Pens, and Drawing Modes.

The GDI Queue.

Drawing Lines.

Creating Pens.

Drawing Modes.

More-complex Lines.

Drawing Filled Areas.

Drawing Rectangles and Ellipses.

Drawing Polygons.

Creating and Using Stock and Custom Brushes.

Stock Brushes.

Custom Brushes.

Creating and Using Bitmaps.

Bitmap Functions.

Creating a Bitmap.

Creating a Bitmap Resource from a Bitmap File.

Creating and Drawing into a Blank Bitmap.

Creating an Initialized Bitmap.

Creating an Initialized Bitmap from a DIB.

The BitBlt, StretchBlt, and StretchDIBits Functions.

The StretchBlt Function.

The StretchDIBits Function.

The MaskBlt and PlgBlt Functions.

The PlgBlt function.

The MaskBlt Function.

Miscellaneous Bitmap and Drawing Functions.

Bitmap Functions.


The DrawEdge Function.

The GDI Batch Queue (in detail).

Region Functions.

Advanced Windows Graphics: Paths and Transformations.

Transformation Matrices.

Regions Revisited: ExtCreateRegion.

Paths: Completely General Shapes for Drawing, Clipping, and Filling.

The GDI Explorer.

What's Next?

Further Reading.


Keyboard, Mouse, and Timer Input.

Keyboard Input.

The Input Focus.

The Key Press and Release Messages.

The Virtual-key Code.

Key Transition Message Crackers.

Character Messages.

The Character Sets.

The Unicode Character Set.

The Caret.

The Keyboard Explorer Program.

Mouse Input.

Mouse Messages.

Hit Testing: The WM_NCHITTEST Message.

Nonclient-area Mouse Messages.

Client-area Mouse Messages.

Capturing the Mouse.

Simple Drag-and-Drop.

The Cursor.

Custom Cursors.

Predefined Cursors.

Displaying the Cursor.

Loading Cursors from Other Sources.

Loading System Cursors.

Setting System Cursors.

Moving the Cursor with the Keyboard.

Towers of Hanoi Example Program.

Timer Input.

Sending WM_TIMER Messages to a Window Function.

Sending WM_TIMER Messages to a Callback Function.

Using the Timer.

Structured Exception Handling.

Further Reading.


Using Controls: Overview; Static, Button, and Edit Classes.

Creating a Control in a Window.

Control Notifications.

Using Controls.

Fonts in Controls.

The STATIC Class.

"Dynamic" Static Controls.

Owner-draw Static Controls.

Simple Frame Example.

The BUTTON Class.

BUTTON Class Styles.

Button Control Notification Messages.

Problems with Buttons and the Input Focus.

Handling Input Focus Changes in Child Windows.

Push Buttons.

Check Boxes.

Radio Buttons.

Owner-draw Buttons.

Group Boxes.

The EDIT Class.

The Edit Class Styles.

Changing Styles.

Messages to an Edit Control.

Working with Selections.

Setting Contents, Copy, Cut, and Paste.

Working with Multiline Edit Controls.

Line Scrolling and Formatting.

Coordinate Mapping.

Edit Control Notification Messages.



Using Controls: ListBox, ComboBox, ImageList, and .

TreeView Classes.

The LISTBOX Class.

The LISTBOX Class Styles.

Messages to a List Box Control.

Adding, Inserting, and Deleting Items from a List Box.

Selecting an Item in a Single-selection List Box.

Determining the Selection in a Single-selection List Box.

Selecting Items in a Multiple-selection or Extended-selection List Box.

Determining the Selection in a Multiple-select List Box.

File Names in List Boxes.

Establishing a Horizontal Scroll Bar.

List Box Notification Messages.


The COMBOBOX Class Styles.

Messages to a Combo Box Control.

Smart Drop-down Lists.

Adding, Inserting, and Deleting Items from a Combo Box.

Selecting an Item in a Combo Box.

Combo Box Notification Messages.

Combo Boxes and List Boxes Are Not Interchangeable.

Improving Performance for List Boxes and Combo Boxes.

Setting Locales for List Boxes and Combo Boxes.

Image Lists.

The TreeView Class.

Messages to Tree View Controls.

Inserting Items in a Tree View.

Selecting an Item.

Getting Information about an Item.

Tree View Notifications.

Image Lists.

Implementing Drag-and-Drop Features.

"Smart" Drag-and-Drop.

Label Editing.

Stop the Presses.

Tree Control Summary.

Further Reading.


Using Controls: Scroll Bar, Trackbar, Up/Down, and .

Progress Classes.


The SCROLLBAR Class Styles.

Messages to a Scroll Bar Control.

Setting Scroll Bar Parameters.

Retrieving Scroll Bar Parameters.

Enabling Scroll Bar Arrows.

Scroll Bar Notifications.

Keyboard Notifications.

Using the Size Box.

The Trackbar Control.

Using Trackbars.

Trackbar Messages.

Simple Trackbars.

Setting the Line and Page Sizes.

Trackbars with Selection.

Tick Marks.

Simple Tick Marks.

Custom Tick Marks.

Problems with Tick Marks in Trackbar Controls.

Stop The Presses News.

Up/Down Controls.

Messages to Up/Down Controls.

Using Up/Down Controls.

Notifications from Up/Down Controls.

Buddy Controls.

Up/Down Accelerators.

The Progress Bar Control.

Stop The Presses.

The Control Explorer.

Further Reading.


Dialog Boxes.

What Is a Dialog Box?

Dialog Functions and Callback Functions.

Modal and Modeless Dialog Boxes.

Modal Dialog Boxes.

Modeless Dialog Boxes.

Using Registered Window Messages.

Creating a Dialog Box.

Using CreateWindow versus CreateDialog.

Passing Parameters When Creating a Dialog Box.


What to Do in the WM_INITDIALOG Handler.

Creating a Dialog Box Template in Your Resource Definition File.

The Pizza-ordering Program.

Resizable Dialogs.

Handling Double-click Activation.

Window-related Data and How to Manage It.


Returning Values from a Dialog.

Using Properties.

Initializing the Pizza Dialog.

Setting Initial Control Values.

Changing the Caption Text.

Enabling and Disabling Controls.

Saving the State of the Dialog.

Using Idle Time to Update Controls.

Some Remaining Problems.

Creating a Dialog Box Using DLGTEMPLATE Structure.

Creating a Dialog Box Template: An Example.

Creating Controls in the Dialog.

Adding Other Control Functions.

The Message Box.

The MessageBox Explorer.


Menus, Accelerators, Icons, String Resources, and MessageTable Resources.


Defining and Creating a Menu.

Defining a Menu Template in Your Resource Definition File.

Win32 4.x Menus.

Creating a Menu Dynamically in Win32 3.x.

Appending, Inserting, and Modifying Menu Items in Win32 3.x.

Creating a Menu Dynamically: Win32 4.x.


Appending, Inserting, and Modifying Menu Items in Win32 4.x.

Radio Button Menu Items.

Default Menu Items.

Summary: A Comparison of Win32 3.x and Win32 4.x Menu Capabilities.

Bitmap Menu Items.

Owner-Draw Menu Items.

Separator Menu Items.

String Menu Items.

Controlling the Appearance of an Item on a Menu in Win32 3.x.

Controlling the Appearance of an Item on a Menu in Win32 4.x.

Creating a Menu Based on a Template.

The Win32 3.x Menu Templates.

The Win32 4.x Menu Templates.

Creating the Menu from a Template.

Class and Window Menus.

Initializing a Menu before It Is Displayed.

Altering a Menu.

Enabling, Disabling, and Graying an Item on a Menu.

Checking and Unchecking a Menu Item.

Using a Bitmap as a Menu Item.

Using a Bitmap as a Custom Menu Item Check Mark.

Menu Messages.

Maintaining Menu State.

Tracking the Menu Selection.

Using a Floating Pop-up Menu.

The System Menu.

The Menus Example Program.

The Menu Explorer.


Creating an Accelerator Table.

Loading an Accelerator Table.

Creating Accelerator Tables Dynamically.

Displaying Accelerators in the Menu.

Accelerators and the Message Loop.

Accelerators without Menu Items.

Icon Resources.

Defining an Icon Resource.

Loading an Icon Resource.

Displaying an Icon Resource.

Class Icons.

The LoadImage Function.

Drawing Icons Yourself.

Switching to a Different Icon.

Displaying Different Icons in Win32 3.x.

Displaying Different Icons in Win32 4.x.

Displaying an Icon in a Dialog Box.

String Resources.

Defining a String Resource.

Localization and Strings.

FormatMessage Function and MESSAGETABLE Resources.

A Formatted MessageBox Function.

The FormatMessage Format String.

The full FormatMessage specification.


Further Reading.



An Overview of the Printing Process.

Using the Default Printer.

Using Any Installed Printer.

Getting the Printer DC for Any Printer.

Checking for Selection Options.

Determining Device Mode Values.

Hazards with Device Mode Values.

Setting the dmTTOption.

The dmPaperSize field.

The dmDefaultSource Field.

Setting Device Mode Values.

Three Elements Required in a Printing Windows Application.

Obtaining Information about a Printer.

Allowing Other Program Interactions while Printing.

The Abort Function.

The Abort Dialog Function.

A (Slightly) More Complex Abort Function.

Printing a Document.

Using Custom Dialog Templates and Hook Functions.

Using a Custom Dialog Templates.

Using a Hook Function.

A General Printing DLL.

The Goals of the Print DLL.

The Input Structure.

The Query Function.

Writing the PRINTIT.DLL Callbacks.

The FormatLine Callback.

The PrintIt Code.

The doPrintIt Function.

The checkFilter Function.

The printLoop Function.

The doHeading Function.

The startPrint Function.

Using an External Abort Dialog Template and Hook Function.

Calling doPrintIt with a Custom Dialog and Hook.

The Page Setup Dialog.

Page Setup Custom Painting Hook.

The Print Explorer.


Memory Management.

Dynamic Memory Allocation-The Simple Approach.

Some Details about Simple Memory Allocation.

Fixed, Moveable, and Discardable Memory Blocks.

Managing Memory Blocks Using the Global- Functions.

Allocating a Fixed Memory Block.

Allocating a Moveable Memory Block.

Allocating a Discardable Global Memory Block.

Allocating a Shareable Memory Block.

Locking and Unlocking Memory Blocks.

Reallocating a Memory Block.

Freeing a Memory Block.

Other Default Heap Functions.

Dynamic Memory Allocation-When Performance Matters.

System Memory Organization.

The Local Heap, the Global Heap, and malloc/new .

(Win16 programmers only!).

Supporting Multiple Heaps.

Considerations When Using the Default Heap.

Page Thrashing - Random Access.

Page Thrashing - Sequential Access.

Synchronization Bottlenecks.

Dynamic Heaps.

Heap Serialization.

Locality of Reference.

Reducing Heap Fragmentation.

Using C++.

Thread-Local Storage.

Using Thread-Local Storage.

The thread Attribute.

Sharing Thread-Local Storage.

Thread-Local Storage Summary.

The Heap Explorer.



Further Reading.


What Is a Font?

Types of Windows Fonts.

Raster Fonts.

Stroke or Vector Fonts.

TrueType Fonts.

Font Resources.

Device Fonts.

Using a Stock Font.

Enumerating Fonts.

Defining a Logical Font.

The LOGFONT Structure.

The Font-matching Scheme.

Getting Information About a Font.


TrueType and ABC Widths.

Pair Kerning.

Track Kerning.

The Font Explorer.

Reading the Font Explorer Display.

Some Font Explorer Application Tips.

Kerning Explorer Anomalies.

Well-behaved Fonts.

Further Reading.


Dynamic Link Libraries.

A Special Note to Win16 Programmers.

What Is a Dynamic Link Library?

Static and Dynamic Linking.

Benefits of Using DLLs.

Constraints Unique to a DLL.

The Stack.

Static Data.

The DllEntryPoint Function.

A DLL Module Definition File.

Importing Symbols.

Importing Data.

Summary of Export Techniques.

Exploring DLL Techniques.

A DLL Requiring No Initialization.

A DLL Requiring Initialization/Finalization.

A Simple Localization Function Library.

A DLL Containing Dialog Resources.

A Resource-only DLL Containing Strings and Other Resources.

DLLs with User-defined Resources.

A DLL That Uses the C Runtime System.

A DLL That Provides Thread-Local Support.

A DLL That Uses a Shared Data Segment.

The Wineyes Example DLL Module: Hook Support.

System Hook Function Types.

The Wineyes Application Module.

Further Reading.


The Multiple Document Interface.

The Behavior of an MDI Application.

The Basic Steps to Creating an MDI Application.

Creating the Frame Window.

Creating the Client Window.

Creating a Child Window.

MDI Client Window Messages.

The MDI Example Program.

Program Initialization.

The MDI Application Message Loop.

The Frame Window Function.

The MDI Child Window Functions.

Embedding an Edit Control.

Updating Toolbars.

WM_CTLCOLORxxx Messages.

Non-solid Brushes.

Handling MessageBox Color Changes.

Object-oriented WM_CTLCOLOR.

The CtlColor Explorer.


Further Reading.



Synchronization basics.

What is synchronization?

Simple synchronization problems.

Synchronization Mechanisms.

Correctness doesn't just happen.

Win32 Synchronization Primitives.



Critical Sections.


Waiting for Synchronization.

Waiting for Threads.

Abandoned Mutexes.

Why you must use synchronization primitives.

Using Synchronization Primitives.

Avoiding Synchronization.

Synchronization via Messages.


Thread Creation.

Inter-thread control.

The Synchronization Explorer.

Further Reading.

Appendix A.

Ternary Raster-Operation Codes.

Appendix B.

Message Cracker Summary.

Appendix C.

windowssx.h, commctrl.h, extensions.h, and tchar.h.

windowsx.h, commctrl.h and extensions.h.

The tchar.h file.

Appendix D.

Using #pragma(warning).

Index. 0201634929T04062001


Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership