Register your product to gain access to bonus material or receive a coupon.
The world's most complete guide to Windows graphics programming!
Hewlett-Packard Professional Books
To deliver high-performance Windows applications, you need an in-depth understanding of the Win32 GDI and DirectDrawbut until now, it's been virtually impossible to discover what's going on "behind" Microsoft's API calls. This book rips away the veil, giving experienced Windows programmers all the information and techniques they need to maximize performance, efficiency, and reliability! You'll discover how to make the most of Microsoft's Windows graphics APIsincluding the important new graphics capabilities built into Windows 2000. Coverage includes:
Windows Graphics Programming delivers extensive code, practical techniques, and unprecedented insightplus an exclusive CD-ROM containing original system-level tools, kernel mode drivers, sample code, and generic C++ classes for Windows graphics programming without MFC. If you want to build Windows graphics applications that deliver breakthrough performance and reliability, you'll find this book indispensable.
Click here for a sample chapter for this book: 0130869856.pdf
1. Basic Techniques and Knowledge.
Basic Windows Programming in C/C++. Assembly Language. Program Development Environment. Win32 Executable File Format. Architecture of Microsoft Windows OS. Summary.
Windows Graphics System Components. GDI Architecture. DirectX Architecture. Printing Architecture. Graphics Engine. Display Drivers. Printer Drivers. Summary.
Handles and Object-Oriented Programming. Decoding GDI Object Handles. Locating the GDI Object Handle Table. Decoding the GDI Object Handle Table. User Mode Data Structure of GDI Objects. Accessing Kernel Mode Address Space. WinDbg and the GDI Debugger Extension. GDI Kernel Mode Data Structure. DirectDraw Data Structure. Summary.
Spying on Win32 API Calls. Spying on Win32 GDI. Spying on DirectDraw COM Interfaces. Spying on GDI System Calls. Spying on the DDI Interface. Summary.
Modern Video Display Card. Device Context. Formalizing Device Context. Sample Program: Generic Frame Window. Sample Program: Painting and Device Context. Summary.
The Physical Device Coordinate Space. The Device Coordinate Space. The Page Coordinate Space and Mapping Modes. The World Coordinate Space. Using Coordinate Spaces. Sample Program: Scrolling and Zoom. Summary.
GDI Objects, Handles, and Handle Table. Clipping. Color. Drawing Pixels. Sample Program: Mandelbrot Set. Summary.
Binary Raster Operations. Background Mode and Background Color. Pens. Lines. Bezier Curves. Arcs. Paths. Sample: Drawing Your Own Styled-Lines. Summary.
Brushes. Rectangles. Ellipses, Chords, Pies, and Rounded Rectangles. Polygons. Closed Paths. Regions. Gradient Fills. Area Fills in Reality. Summary.
Device-Independent Bitmap Formats. A DIB Class. Displaying a DIB. Memory Device Contexts. Device-Dependent Bitmaps. Using DDBS. DIB Section. Summary.
Ternary Raster Operations. Transparent Bitmaps. Transparency without a Mask Bitmap. Alpha Blending. Summary.
Generic Pixel Access. Bitmap Affine Transformation. Fast Specialized Bitmap Transformer. Bitmap Color Transformation. Bitmap Pixel Transformation. Bitmap Spatial Filters. Summary.
System Palette. The Logical Palette. Palette Messages. Palette and Bitmaps. Color Quantization. Bitmap Color-Depth Reduction. Summary.
What's a Font? Bitmap Fonts. Vector Fonts. TrueType Fonts. Font Installation and Embedding. Summary.
Logical Fonts. Querying Logical Font. Simple Text Drawing. Advanced Text Drawing. Text Formatting. Text Effects. Summary.
Metafile Basics. Inside an Enhanced Metafile. Enumerating an EMF. An EMF as a Programming Tool. Summary.
Understanding the Spooler. Basic Printing Using GDI. Design for Printing. Drawing on Printer Device Context. Summary.
Component Object Model (COM). DirectDraw Basics. Building a DirectDraw Graphics Library. Direct3D Immediate Mode. Summary.
To be truly valuable, a new book on Windows programming should be in-depth, complete, up to date, accurate, practical, and useful.
An in-depth book should go beneath the API layer to talk about API design rationale, internal data structure, and implementation outline. It should provide spying and exploration tools for you.
A complete and up-to-date book should focus on the best implementation of Win32 API so far, Windows 2000, which will be basis for future Microsoft operating systems, and cover its new features.
An accurate book should be based on actual exploration of Win32 API features and verify all the details. Relying solely on Microsoft documentation is definitely not good enough, because it merely describes the abstract Win32 API and unfortunately has some incomplete, out-of-date, and vague information.
A practical and useful book for programmers and software engineers should go beyond mere description of API and simple illustrative examples, to solve real-world problems, provide reusable building blocks, supply useful tools, and encourage readers to write professional programs.
In particular, a book of this sort is needed to elucidate Win32 GDI, or Windows graphics programming in general, which is a fundamental building block of all Windows programs. The most in-depth coverage to date may be provided by Matt Pietrek's books, which discuss the internal working of Windows 3.1 GDI. The most complete and up-to-date description of GDI is offered by Microsoft's MSDN library. Half of Charles Petzold's famous book Programming Windows, Fifth Edition, is devoted to Windows 98 GDI programming.
But for the whole Windows programming community dealing with Windows GDI frequently, something more in-depth, more complete, more up-to-date, more accurate, and more useful is needed. These are the goals that have guided the preparation of this book.
This book is about Windows graphics programming using Win32 GDI API, with an introduction to DirectDraw, and an even more brief introduction to Direct3D Immediate Mode. It covers common features implemented on all Win32 platforms, pure 32-bit features implemented on Windows NT/2000 only, and the most recent additions to GDI for Windows 2000 and Windows 98. For example, alpha blending, transparent bitblting, gradient fill, right-to-left reading order, layered window, and sending JPEG/PNG images to printer are fully covered.
This book is about programming Windows with a deep understanding of how things are actually implemented, so as to use Win32 API more effectively, efficiently, and confidently.
This book is about reading any Win32 documentation perceptively and analytically, trying to understand the minds of people designing and implementing Win32 API, and using logical reasoning and experiments to fully understand Win32 API, even to find missing information and identify mistakes in its documentation.
This book is about using programming tools effectively to help you understand Win32 API. More importantly, it demonstrates how you can build your own tools, often using hard-core system programming techniques, and design interesting experiments to explore the undocumented world underneath Win32 API. The first few chapters can be read as a system-level Windows programming book, which can be applied to other areas of Windows programming.
This book is about creating reusable building blocks for practical employment. Besides simple testing and demonstration programs, the book contains lots of reusable functions, C++ classes, drivers, tools, and nontrivial programs, which can be used in actual production-quality Windows programs. It develops a whole C++ class library of object-oriented Windows programming, which supports simple window, SDI window, MDI window, dialog box, toolbar, status window, property sheet, sub-classing, common dialog box, etc. It provides classes for DIB/DDB/DIB section handling, EMF rendering, image processing, color quantization, error-diffusion halftoning, JPEG image decoding/encoding, font file decoding, font embedding, PANOSE font matching, glyph drawing, 3D text, device-independent multiple-page layout, DirectDraw wrapper, Direct3D IM wrapper, and so on.
The code shown in this book does not rely on Microsoft Foundation Class, or any third-party class library, so it can be used in any C++ program. All the class names start with the letter "K," so you can easily mix them with MFC, ATL, or OWL, or your own class library.
The book covers Windows graphics programming at three layers: the implementation layer, the API layer, and the application layer.
The implementation layer covers what is behind the Win32 GDI API and DirectX COM interfaces, which is the undocumented world of Windows graphics engine and the Win32 subsystem client DLLs. Chapters 2, 3, and 4 cover the behind-the-scenes implementation layer to build a solid foundation for understanding the API layer.
The API layer provides precise, accurate, step-by-step description of Win32 GDI API, DirectDraw, and a little bit of Direct3D IM. The application layer builds on top of the API layer to solve real-world problems, implement reusable functions, C++ classes, and nontrivial programs. The API layer and application layer are mixed together according to individual topics. Normally, the first part of a chapter covers the API layer and then moves to real application-related programs. For more complicated topics like bitmap, one chapter covers the basics and two chapters cover more advanced usage.
Chapter 1, "Basic Techniques and Knowledge," reviews basic Windows programming techniques, which will be used in the rest of the book. It covers basic Windows programming, Intel assembly language, the program development environment, the Win32 executable file format, and the architecture of the Windows operating system. My favorite part is simple API hooking by overwriting Win32 module's import/export directories.
Chapter 2, "Windows Graphics System Architecture," gives a grand tour of the Windows graphics system from the Win32 subsystem DLLs down to the graphics device drivers. It touches on Windows graphics system components, GDI architec-
ture, DirectX architecture, printing subsystem architecture, the graphics engine, display drivers, and finally printer drivers. My favorite parts are the description of system service calls, which bridges user mode GDI implementation with the kernel mode graphics engine, a tool to list undocumented system service calls (from GDI32.DLL, USER32.DLL, NTDLL.DLL, and WIN32K.SYS), and a simple printer driver which generates HTML pages with embedded bitmaps.
Chapter 3, "GDI/DirectDraw Internal Data Structures," can be read as a detective story or treasure-hunting adventure. It starts by explaining the Win32 handle-based object-orient programming paradigm, then tries to understand what a GDI object handle is, proceeds to actually locate the GDI handle table, decode it, and finally expose the complicated web of data structures the Windows graphics system keeps internally. Virtual memory querying, Microsoft's debug symbol files, homegrown tools and Microsoft Visual C++ debugger are used to locate the GDI handle table. A kernel mode driver is developed to read from the kernel mode address space. The Fosterer program developed in Chapter 3 uses Microsoft's GDI debugger extension to decode the GDI handle table, and graphics engine/DirectX internal data structures, all with the convenience of a single machine. You just can't afford to miss trying the Fosterer program, on either a Windows NT or Windows 2000 machine. But first, you need to install debug symbol files and get Microsoft's WinDbg.
Description of internal data structure should be treated as reference material to gain deep understanding or help in DDI level debugging, as the details may change from release to release, even from service pack to service pack. Feel free to skip any sections not interesting to you and come back when you need some insights, for example to understand GDI object resource usage or performance issues.
Chapter 4, "Spying in the Windows Graphics System," presents various techniques and tools for spying on Windows graphics system and the whole Windows system in general. You will learn about injecting DLL into foreign processes, hooking into the API calling chain, information gathering, decoding, and reporting, API specification for the spying program, spying on Win32 API calls, API hooking by binary-relocation, system service call hooking, COM interface hooking, and finally kernel mode DDI interface hooking. My favorite parts are using assembly to write proxy routines, and hooking on intramodular calls, system service calls, and DDI calls to watch how the system really works. Chapter 4 is for hard-core programmers; skip it if you do not need it now.
Chapter 5, "Graphics Device Abstraction," begins a description of the whole Windows graphics programming APIs and practice usage. Chapter 5 deals with video display card, frame buffer, GDI device context object, generic frame window class, and painting in a window. My favorite part is the WinPaint program that visualizes a window's painting messages.
Chapter 6, "Coordinate Spaces and Transformation," discusses the four coordinate spaces supported by GDI, window-to-viewport mapping, world coordinate transformation (affine transformation), and finally their usage in scrolling and zooming. I missed playing WeiQi, an oriental board game, so much during the writing of this book that I wrote a simple WeiQi board displaying program as Chapter 6's sample program.
Chapter 7, "Pixels," gives a generic description of GDI objects, handles, and handle table on the GDI API level, which is followed by a program to monitor system-wide GDI handle usage. It then discusses simple region and provides a complete picture of GDI clipping, color spaces, and pixel drawing, ending with a Mandelbrot set drawing program. The best part may be the description of the system region, meta region, clipping region, and Rao region, which are used by GDI to control clipping, and the ClipRegion program to visualize them.
Chapter 8, "Lines and Curves," covers binary raster operations, background modes, background colors, logical pen object, lines, Bezier curves, arcs, paths, and drawing your own style lines not supported directly by GDI. The part I like most may be the mathematics involved in converting elliptical curves to Bezier curves.
Chapter 9, "Areas," covers brushes, rectangles, ellipses, chords, pies, rounded rectangles, polygons, closed paths, regions, gradient fills, and a summary of various area-fill techniques used by graphics applications. My favorites are the use of gradient fill to draw 3D buttons and the description of region-related data structure.
Chapter 10, "Bitmap Basics," focuses on the three bitmap formats supported by GDI, which are device-independent bitmaps, device-dependent bitmaps, and DIB section. Also covered are wrapper classes for DIB, DDB, and DIB section, memory device contexts, and common usage of these bitmaps. My favorite parts are the wrapper classes, especially using memory-mapped DIB section to implement device-independent high-resolution rendering of enhanced metafiles.
Chapter 11, "Advanced Bitmap Graphics," covers ternary raster operations, transparent bitmap, bitmap transparency without masks, alpha blending, and the new Windows 2000 feature, layered window. My favorite part is the complete coverage of raster operations, especially the raster operating chart and simulation of quaternary raster operation using multiple ternary raster operations.
Chapter 12, "Image Processing Using Windows Bitmaps," discusses direct pixel access in bitmaps, bitmap affine transformation, bitmap color transformation, bitmap pixel transformation, and bitmap spatial filters. My favorite part is the object-oriented template-based design of the generic image-processing framework presented in this chapter, which can be easily extended.
Chapter 13, "Palettes," covers the system palette, logical palettes, palette messages, palettes for bitmaps, color quantization, and bitmap color-depth reduction using error diffusion. The octree color quantization algorithm implementation has been seen to generate better palette than commercial software.
Chapter 14, "Fonts," covers character sets, code pages, glyph, typeface, font family, bitmap fonts, vector fonts, TrueType fonts, font installation, and font embedding. I especially like decoding the TrueType font file.
Chapter 15, "Text," discusses logical fonts, font mapping, PANOSE typeface matching, text metrics, simple text drawing, advanced text drawing, text formatting, and text effects. The last section on text effects is the best; it includes coloring text, shadowing, embossing, engraving, soft-shadowing, rotation, vertical text, fitting text on curves, treating text as images, treating text as outline, and even simple 3D text.
Chapter 16, "Metafile," covers basic creating and displaying of metafiles, detailed internal metafile organization, encoding of GDI feature in metafiles, decoding metafiles, enumerating metafiles, EMF decompiler, and capturing EMF from spooler. The best parts are the EMF decompiler and the EmfScope program, which captures Windows 95/98 EMF spool files.
Chapter 17, "Printing," discusses print spooler, basic printing using GDI, designing your application for printing, JPEG image printing (including sending JPEG directly to a printer driver), and C++ syntax highlighted source code printing. The best part is a generic framework for multiple-page, multiple-column page layout that is independent of device resolution and display scale. Both the JPEG and source code printing programs use this generic framework.
Chapter 18, "DirectDraw and Direct3D Immediate Mode," is an introduction to the 2D/3D drawing portions of DirectX for experienced GDI programmers. It covers a COM primer, wrapper classes for DirectDraw and DirectDraw surface, three ways of drawing in DirectDraw, DirectDraw clipper, off-screen surface, font and text in DirectDraw, wrapper class for basic DirectDraw Immediate Mode, windowed-mode DirectX, double-buffering, and texture. The part I enjoy most is using GDI to create a DirectDraw font surface, which can be used to display text efficiently on DirectX surfaces.
This book is mainly written for intermediate, experienced, or advanced programmers using the Win32 API or class libraries based upon it.
Novice Windows programmers should start either with another book or with on-line help to get familiar with the skeleton and basic concepts of a Windows program, and step through a program to understand how it works.
If you're interested only in Windows graphics programming stuff, or you're not interested in behind-the-scenes system-level implementation details, read Chapters 1 and 2, skip Chapters 3 and 4, and read Chapter 5 onward. You can even skip some sections in Chapters 1 and 2. Starting from Chapter 5, the contents are developed quite gradually in a systematic fashion.
If you're an experienced or advanced programmer, you know perfectly well
what interests you most. Maybe you will check a few things first and then jump to Chapter 3.
If you're interested only in system-level programming like API spying, read parts of Chapters 1 and 2, and then Chapters 3 and 4.
If you're not a programmerfor example, if you're a test engineeryou may want to read Chapter 2 to get an overall view of the Windows graphics system, and maybe the first part of Chapter 3 in order to know more than enough to talk about GDI resource leak problems, and get a tool or tools to detect resource leak.
This book comes with lots of sample programs, together with reusable functions and classes. To be more specific, it has over 1300 KB of C++ source files, 400 KB of C++ header files, plus a slightly modified version of JPEG library source files, which is based on the Independent JPEG Group's free source code (www.ijg.org). The complete source code is compiled into 49 executable files, three kernel mode drivers, and one user mode dynamic library.
Naturally, not all the source code can be printed in the book. The CD contains all the source code, Microsoft Visual C++ 6.0 workspace files, precompiled debug mode and release mode binary files, and some JPEG images to be used with chapters related to bitmap/image handling. The CD has an automatic installation program, which will install the contents of the CD, program groups, links and important web addresses for downloading Microsoft tools and for support.
The programs were developed and tested on the Windows 2000 final release (build 2195), with a display card supporting DirectX 7.0 2D/3D-hardware acceleration, although most programs should work on Windows 95/98/NT 4.0 systems and do not need DirectX support.
To compile all the programs, make sure the following are installed on your system:
www.microsoft.com/downloads/sdks/platform/platform.asp
. Make sure your VC 6.0 include and library directories are updated to use Platform SDK.www.microsoft.com/windows200/downloads/otherdownloads/symbols
.www.microsoft.com/ddk
. Add DDK's inc directory to your VC include directories. Add DDK's libfre\i386 directory to VC library file directories.www.microsoft.com/ddk/debugging
.Although all the sample code in this book is written in C++ without MFC, MFC/ATL/OWL programmers can easily make use of the code developed here. Even Visual Basic or Delphi programmers can benefit from the text and sample code from the book, because these development environments allow direct calling of Win32 API functions.
Writing is a great opportunity for the author, forcing him to organize ideas, conduct research, and present material in an orderly fashion. When a book is finished, the author benefits most. Hopefully, fellow programmers can also learn from the book, which is detailed recording of my own learning.
More importantly, the classroom for learning is now suddenly exploded from my office cubicle and my home office to the whole wide world; now you all become my teachers and classmates. If you find any mistake or bug, or if you have a comment, suggestion, or complaint, please contact me through my personal web site: http://www.fengyuan.com
.
The web site will also provide frequently asked questions, updates, instructions for using the more complicated sample programs, and so on.