Tricks of the Windows Game Programming Gurus:The Windows Programming Model

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

## Chapter 2
The Windows Programming Model

> “Lilu Dallas Multipass!”

> —Lilu, The 5th Element

Windows programming is like going to the dentist: You know it’s good for you, but no one likes doing it. Am I right? In this chapter, I’m going to show you the basics of Windows programming using my “Zen” methodology—or, in other words, the easy way. I can’t promise that you’ll like going to the dentist after reading this chapter, but I can promise you that you’ll like Windows programming a lot more than you ever did! Here’s what you’ll learn:

  • The history of Windows
  • Basic Windows architecture
  • Windows’ classes
  • Creating Windows
  • Windows event handlers
  • Event-driven programming and event loops
  • Opening multiple windows

### The Genesis of Windows

To put you in the mood for the onslaught of horror that I’m about to unleash upon your mind (especially you DOS diehards), let’s take a quick look at how Windows has shaped up over the past years and its relationship to the game development world—shall we?

#### Early Windows Versions

It all began with the release of Windows 1.0. This was Microsoft’s first attempt at a commercial windowed operating system, and it was pretty much a failure. Windows 1.0 was based completely on DOS (big mistake), wasn’t multitasking, ran really slow, and looked really bad. Its looks were probably the most important reason for its failure <BG>. Sarcasm aside, the problem was that Windows 1.0 needed much more hardware, graphics, and sound capabilities than the 80286 (or worst yet, 8086) machines of the time had to offer.

Nevertheless, Microsoft forged ahead, and shortly thereafter it released Windows 2.0. I actually remember working at Software Publishing Corporation when we got the beta of Windows 2.0. There was a boardroom filled with executives and the president of the company (as usual, he had a cocktail in his hand). We ran the Windows 2.0 beta demo and loaded multiple applications, and it seemed to work. However, at this time IBM Presentation Manager (PM) was out. PM simply looked a lot better, and it was based on OS/2, a vastly more advanced OS than Windows 2.0 (which was still a window manager simply overlaid on top of DOS). The verdict of the board that day: “Not bad, but not a viable OS for development. Let’s stick to DOS, and can I have another cocktail?”

#### Windows 3.x

In 1990, the planets must have been in alignment, because Windows 3.0 was released and it was pretty damn good! It wasn’t up to par with Mac OS yet, but who cared? (Real programmers hate Macs.) Finally, software developers could create sexy applications on the PC and start migrating away from DOS for business applications. This was the turning point for the PC and the thing that eventually put the Mac out of the running for business applications and later for desktop publishing. (That, along with Apple releasing new hardware every five minutes.)

Although Windows 3.0 worked well, it had a lot of problems, bugs, and so forth. Heck, it was a quantum leap ahead of Windows 2.0 in technology, so problems were to be expected. To fix these problems, Microsoft came out with Windows 3.1. The PR and marketing departments originally wanted to call it Windows 4.0, but Microsoft decided to simply call Windows 3.1 because it just didn’t have enough features to qualify as a major revision upgrade. Nor did it live up to all the hype the marketing department had built up.

Windows 3.1 was very solid. It had multimedia extensions like sound and video support, and it was a good all-around OS that got work done for the user in a uniform manner. In addition, there was another version called Windows 3.11 (Windows for Workgroups) with network support. The only problem was that Windows 3.1 was still a DOS application, for the most part, and ran under a DOS Extender.

#### Windows 95

On the other side of the planet, the game programming community was still chanting “DOS TILL HELL FREEZES OVER!”, and I was out in front burning a Windows 3.1 box myself! However, in 1995 hell did start to freeze over… Windows 95 was released, and it was a true 32-bit, multitasking, multithreaded operating system. Granted, it had some 16-bit code left in it, but for the most part, Windows 95 was the ultimate development and release platform for the PC.

(Of course, Windows NT 3.0 was also available. But NT just wasn’t feasible for the average user, so I’m not even acknowledging it yet in my story.)

When Windows 95 was released, it was the first time ever that I actually liked programming for Windows. I always hated Windows 1.0, 2.0, 3.0, and 3.1 for programming, although I hated it less and less with each release. But when Windows 95 came out, there was one thing that changed my mind, as well as a lot of other people’s—it looked cool! That’s all I needed.

> Tip: The most important thing in the game programming business is how the box looks and how the screen shots you send to magazines look. Sending the reviewers free stuff works too.

So almost overnight, Windows 95 changed the computing business. Sure, many companies today are still using Windows 3.1 (can you believe that?), but Windows 95 made the Intel-based PC the computer of choice for all applications—except games. Yes, DOS still had the hearts of game programmers, even though they knew it was only a matter of time.

In 1996, Microsoft released the Game SDK, which was basically the first version of DirectX. This technology worked on Windows 95 only, but it was simply too slow to compete with DOS games such as DOOM and Duke Nukem. Developers continued to develop for DOS32, but they knew it was only a matter of time before the DirectX technology would be fast enough to make games on the PC.

By version 3.0, DirectX was as fast as DOS32 on the same machines. By version 5.0, DirectX was very clean and the promises of the technology were coming true. But we’ll talk more about that later when we cover DirectX in Chapter 5, “DirectX Fundamentals and the Dreaded COM.” For now, just realize that Win32/DirectX is the only way to go on the PC for games. Back to the history lesson.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.