Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required.
Read instantly on your browser with Kindle for Web.
Using your mobile phone camera - scan the code below and download the Kindle app.
Windows Graphics Programming: Win 32 Gdi and Directdraw (Hewlett-Packard Professional Books)
- ISBN-100130869856
- ISBN-13978-0130869852
- PublisherPrentice Hall
- Publication dateJanuary 1, 2000
- LanguageEnglish
- Dimensions7.5 x 2.5 x 9.75 inches
- Print length1234 pages
Customers who bought this item also bought
Editorial Reviews
From the Back Cover
- Win32 GDI and DirectDraw: Accurate, under the hood, and in depth
- Beyond the API: Internals, restrictions, performance, and real-life problems
- Complete: Pixel, lines, curves, filled area, bitmap, image processing, fonts, text, metafile, printing, and more
- Up to date: Windows 2000 and Windows 98 graphics enhancements
- CD-ROM: Exclusive and professional quality generic C++ classes, reusable functions, demonstration programs, kernel mode drivers, GDI exploration tools, and more!
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:
- Uncovering the Windows system architecture and graphics system internal data structure
- Building graphics API "spies" that show what's going on "under the hood"
- Detecting GDI resource leaks and other powerful troubleshooting techniques
- Expert techniques for working with the Win32 GDI and DirectDraw APIs
- Device context, coordinate space and transformation, pixels, lines, curves, and area fills
- Bitmaps, image processing, fonts, text, enhanced metafiles, printing, and more
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.
About the Author
FENG YUAN is a Software Design Engineer for Hewlett Packard in Vancouver, WA. He holds a Ph.D. in Software Engineering from Nanjing University. For the past four years, he has specialized in creating drivers for HP DeskJet printersgiving him a burning motivation and a unique opportunity to understand Windows graphics programming inside and out.
Excerpt. © Reprinted by permission. All rights reserved.
Preface
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.
What Is This Book About?
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.
How Is This Book Organized?
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.
How Should You Read This Book?
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.
What Is on the CD?
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:
- Visual C++ 6.0, for compiler.
- Visual Studio 6.0 Service pack 3, for compiler update, msdn.microsoft.com/vstudio/sp/vs6sp3.
- MSDN library, for on-line documentation.
- Platform SDK, for latest header files, library files, and tools, www.microsoft.com/downloads/sdks/platform/platform.asp. Make sure your VC 6.0 include and library directories are updated to use Platform SDK.
- Windows 2000 debug symbol files, used by several tools, and good for debugging, www.microsoft.com/windows200/downloads/otherdownloads/symbols.
- Windows 2000 DDK, needed by several kernel mode drivers, 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.
- WinDebug, used by tools in Chapter 3, 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.
What Is the Future of This Book?
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.
Product details
- Publisher : Prentice Hall (January 1, 2000)
- Language : English
- Hardcover : 1234 pages
- ISBN-10 : 0130869856
- ISBN-13 : 978-0130869852
- Item Weight : 4.55 pounds
- Dimensions : 7.5 x 2.5 x 9.75 inches
- Best Sellers Rank: #3,344,113 in Books (See Top 100 in Books)
- #915 in Computer Operating Systems (Books)
- #1,013 in Computer Graphics
- #1,176 in Microsoft OS Guides
- Customer Reviews:
About the author

Discover more of the author’s books, see similar authors, read book recommendations and more.
Related products with free delivery on eligible orders
Customer reviews
Customer Reviews, including Product Star Ratings help customers to learn more about the product and decide whether it is the right product for them.
To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.
Learn more how customers reviews work on Amazon-
Top reviews
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
I liked the coverage of Bitmaps (loading and saving to disk, filtering and alpha blending), the detailed explanation of routines we take for granted (like simple lines, regions or fonts)...
All the examples consist of a series of C++ reusable classes wrapping functionality
Also did'nt expect it to look like brand new since I bought it used.
It is not perfect but you cannot do without it.
With 1000+ pages, this book is a very broad and deep interview of windows graphics system. This book is for advanced developers. It does not teach you hand by hand how to draw a text, how to draw a window..., instead, this book is for the person who want to know how Microsoft implemented the Win32 graphics system. This book includes many windows internals and undocumented stuff.
I want to say thanks and show respect to the author 'Feng Yuan', for his kindness to publish the knowledge.
Keep in mind this book was published in 2001, I whish there will be a 2nd version, which include the new changes in Windows XP, and include details of the OpenGL's connection with GRE. And about the new Longhorn graphics engine.
While reading and testing, I'd got doubtful of the reliability of this book.
This book provides many useful information, but don't swallow whatever this book says.
The first half of the book attempts to look 'under the hood'. Here is presented a curious and confusing mixture of GDI details, advanced spying tools and techniques, and accounts of spelunking experiences. None of this seems ordered in a logical manner - Pietrek, for example, saves the spelunking experiences to a chapter of its own, at the end of his book. Chapters have easy-to-follow analysis on the documented user-mode level, freely interspersed with unfamiliar and difficult discussions of the mostly undocumented Kernel-mode level. With no clear separation between the elementary and advanced material, it swings sharply from the pedantically clear, to the obscure unexplained. For example, after the excellent details of how to locate the GDI handle table, it merely tells you what the DC structure is, without telling you how it was deciphered. While we are given full details of API tracing in the conventional manner (a la Richter), with source code, we are only given the briefest abstract discussion of a new, unconventional API spying. In the latter case, there is a cursory mention that it is explored in unidentified 'quite a few magazine articles'.
All of this is further obfuscated with presentations of C++ wrapper classes, when what is really required is a clear discussion of the relevant WinAPI functions.
There is also quite a bit of repetition of material in different chapters (such as the structure of the GDI handle table), and some material is in strange places (such as the tool for tracking all GDI handles in the system, grouped by handle type, which appears in the chapter "Pixels").
The second half of the book leaves the undocumented and low-level stuff, to discuss vanilla GDI programming. The information here is well presented, well organized, and clear. It covers drawing pixels, lines, bitmaps, image processing, palettes, fonts, raster operations, printing, and finally DirectDraw. Almost no use whatsoever is made of the extensive 'under the hood' information painstakingly gathered in the first half. What is missing in the reams of C++ classes presented here are some classes to process the standard image formats other than bitmaps i.e. JPEGs, GIFs and PNGs. For JPEGs particularly, a good C++ class is sorely missing for all of us who have tried to read the cross-platform, cross-compiler, cross-eyed code distributed by the Independent JPEG Group.
The final chapter on DirectDraw is a great disappointment. DirectDraw is simply too large a subject for a single chapter, and such a chapter would only serve some purpose if it could impart an intuitive understanding of DirectDraw concepts, such as what a 'surface' is, and how it compares to a GDI device context. Instead we are treated once again to a series of C++ wrapper classes, the sort of stuff that more properly belongs on Yuan's Web site, than in this already-overweight book.
Regarding the tools on the CD - I could not start some of them from the Start menu. They (surprisingly) have an inconsistent GUI, and source code does not appear overly well commented. Even worse, the code makes extensive use of templates which obfuscate rather than illuminate the sample programs. Although 'proper' programmers are meant to be familiar with templates, many are not, and they have no place in a book that ostensibly is about GDI, rather than good programming practice. However, some of the tools are extremely useful and worth adding to your arsenal.
Although billed as covering Win9x as well as WinNT, there seems to be little more than a cursory mention of the 9x family. This is a shame, as although developers may justifiably detest the Win9x family, it accounts for the overwhelming majority of home computers, and a good GDI book should cover it in depth. In particular, I was looking for 'under the hood' information on Win9x, both the 32-bit GDI32.dll, and the 16-bit GDI.EXE, down to which most GDI calls thunk. Unless I was sleeping, I saw none of this in Yuan's book, and have to revert back to Pietrek's Secrets for this kind of information.
In summary, I think this is a superb book for detailed 'above the hood' GDI work. For those interested in GDI 'under the hood', there is excellent material, as well as good spelunking tools. However, I must say that I was quite disappointed with this book as a result of expectations raised too high by its claims, which end up obscuring the many good aspects of the book. It would gain from a rewrite, cutting out the chapter on DirectDraw, and correcting the worst of the faults that have crept in as a result of poor organization and editing.
