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

Take a look at Table 2.3 to see a (somewhat abridged) list of the various `MessageBox()` options.

Table 2.3 `MessageBox()` Options

Flag | Description
--- | ---

The following settings control the general style of the message box
`MB_OK` | The message box contains one pushbutton: OK. This is the default.
`MB_OKCANCEL` | The message box contains two pushbuttons: OK and Cancel.
`MB_RETRYCANCEL` | The message box contains two pushbuttons: Retry and Cancel.
`MB_YESNO` | The message box contains two pushbuttons: Yes and No.
`MB_YESNOCANCEL` | The message box contains three pushbuttons: Yes, No, and Cancel.
`MB_ABORTRETRYIGNORE` | The message box contains three pushbuttons: Abort, Retry, and Ignore.
This group controls the addition of an icon to add a little “poor man’s multimedia”
`MB_ICONEXCLAMATION` | An exclamation-point icon appears in the message box.
`MB_ICONINFORMATION` | An icon consisting of a lowercase letter `i` in a circle appears in the message box.
`MB_ICONQUESTION` | A question-mark icon appears in the message box.
`MB_ICONSTOP` | A stop-sign icon appears in the message box.
This flag group controls which button is highlighted by default
`MB_DEFBUTTONn` | Where `n` is a number (`1`…`4`) indicating which button is the default, numbered from left to right.

Note: There are additional advanced OS level flags, but we aren’t concerned with them. You can always look them up in the online compiler Win32 SDK Help if you want to know more.

You can logically `OR` the values together in Table 2.3 to create the desired message box. Usually, you will `OR` only one flag from each group.

And of course, like all good Win32 API functions, `MessageBox()` returns a value to let you know what happened. In our case, who cares? But in general, you might want to know the return value if the message box was a yes/no question and so forth. Table 2.4 lists the possible return values.

Table 2.4 Return Values for `MessageBox()`

Value | Button Selected
--- | ---

`IDABORT` | Abort
`IDCANCEL` | Cancel
`IDIGNORE` | Ignore
`IDNO` | No
`IDOK` | OK
`IDRETRY` | Retry
`IDYES` | Yes

Finally, a table that can list all the values without defoliating an entire forest! Anyway, this completes the line-by-line analysis of our first Windows program—click!

> Tip: Now I want you to get comfortable making changes to the program and compiling it in different ways. Try mucking with various compiler options, like optimization. Then try running the program through the debugger and see if you can figure that out. When you’re done, come back.

If you want to hear a sound, a cheap trick is to use the `MessageBeep()` function. You can look it up in the Win32 SDK. It’s similar to the `MessageBox()` function as far as simplicity of use. Here it is:

    BOOL MessageBeep(UINT utype); // the sound to play

The different sounds can be from among the constants shown in Table 2.5.

Table 2.5 Sound Identifiers for `MessageBeep()`

Value | Sound
--- | ---

`MB_ICONASTERISK` | System asterisk
`MB_ICONEXCLAMATION` | System exclamation
`MB_ICONHAND` | System hand
`MB_ICONQUESTION` | System question
`MB_OK` | System default
`0xFFFFFFFF` | Standard beep using the computer speaker—yuck!

Note: If you have an MS-Plus theme installed, you’re sure to get some interesting results.

See how cool the Win32 API is? There are literally hundreds of functions to play with. Granted, they aren’t the fastest things in the world, but for general housekeeping, I/O, and GUI stuff, they’re grrrreat! (I felt like Tony the Tiger for a second <BG>.)

Let’s take a moment to summarize what we know at this point about Windows programming. The first thing is that Windows is multitasking/multithreaded, so multiple applications can run simultaneously. However, we don’t have to do anything to make this happen. What does concern us is that Windows is event-driven. This means that we have to process events (which we have no idea how to do at this point) and respond to them. Okay, sounds good. And finally, all Windows programs start with the function `WinMain()`, which has a few more parameters than the normal DOS `main()` but is within the realm of logic and reason.

With all that in mind, it’s time to write a real Windows application. (But before we start, you might want to grab something to drink. Normally I would say Mountain Dew, but these days I’m a Red Bull man. Tastes like crap, but it keeps the synapses going and the can looks cool.)

### Real-World Windows Applications (Without Puck)

Even though the goal of this book is to write 3D games that run on Windows, you don’t need to know much about Windows programming. Actually, all you need is a basic Windows program that opens a window, processes messages, calls the main game loop, and that’s it. With that in mind, my goal in this section is to first show you how to create simple Windows programs, but at the same time to lay the groundwork for a game programming shell application that looks like a 32-bit DOS machine.

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.