Tricks of the Windows Game Programming Gurus:Windows GDI, Controls, and Last-Minute Gift Ideas

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

Purpose: To get the general state of the button control. Possible return values are shown below.

`msg`: | `BM_GETSTATE`
`wparam`: | 0
`lparam`: | 0

Value | Description
--- | ---

`BST_CHECKED` | Indicates the button is checked.
`BST_FOCUS` | Specifies the focus state. A nonzero value indicates that the button has the keyboard focus.
`BST_INDETERMINATE` | Indicates the button is grayed because the state of the button is indeterminate. This value applies only if the button has the `BS_3STATE` or `BS_AUTO3STATE` style.
`BST_PUSHED` | Specifies the highlight state. A nonzero value indicates that the button is highlighted. A button is automatically highlighted when the user positions the cursor over it and presses and holds the left mouse button. The highlighting is removed when the user releases the mouse button.
`BST_UNCHECKED` | Indicates the button is unchecked.

Example:

    // this code can be used to get the state of the button

    switch(SendMessage(hwndbutton, BM_GETSTATE, 0, 0)

          {

          // what is the button state

          case BST_CHECKED:       { } break;

          case BST_FOCUS:         { } break;

          case BST_INDETERMINATE: { } break;

          case BST_PUSHED:      { } break;

          case BST_UNCHECKED:     { } break;

          default: break;

          } // end switch

Well, that’s it for child controls. At least you have an idea of what they are and how to handle them. Now it’s time to move onto querying information from Windows.

### Getting Information

Wall Street’s Gordon Gecko once said: “Why don’t you stop sending me information and start getting some?” These words are appropriate for this circumstance and many other things. Information about the system your game is running on is vital to making your game take advantage of all the resources that a system has to offer. As you would expect, Windows is full of information retrieval functions that acquire a myriad of details about Windows settings and the hardware itself.

Win32 supports a number of `Get*()` functions and DirectX supports a number of `GetCaps*()` functions. I’m only going to cover a few of the Win32 functions that I use from time to time. In the next part of the book you’ll see more of the information retrieval functions that DirectX supports. Those functions are more geared toward the multimedia end of the spectrum.

The following paragraphs describe three functions that I like to use from time to time. (There are many more.) Basically, anything you want to know about Windows is there and can be queried with a `“Get”` class function. Simply type `“get”` into the Win32 SDK Search engine within your compiler Help and you should find whatever you need. We’ll take a look at these three functions just to get a feel for using them.

The first function we’ll look at is called `GetSystemInfo()`. It basically returns everything you would ever want to know about the processing hardware you’re running on—things like the type of processor, how many processors, and so forth. Here’s the function prototype:

    VOID GetSystemInfo(

         LPSYSTEM_INFO lpSystemInfo);

        // address of system information structure

The function simply takes a pointer to a `SYSTEM_INFO` structure and fills in all the fields. Here’s what a `SYSTEM_INFO` structure looks like:

    typedef struct _SYSTEM_INFO

    { // sinf

    union {

          DWORD dwOemId;

          struct {

                 WORD wProcessorArchitecture;

                 WORD wReserved;

                 };

          };

    DWORD  dwPageSize;

    LPVOID lpMinimumApplicationAddress;

    LPVOID lpMaximumApplicationAddress;

    DWORD  dwActiveProcessorMask;

    DWORD  dwNumberOfProcessors;

    DWORD  dwProcessorType;

    DWORD  dwAllocationGranularity;

    WORD   wProcessorLevel;

    WORD   wProcessorRevision;

    } SYSTEM_INFO;

The details of all these fields are pages long and we don’t have room to cover them, but obviously there are some interesting fields. For example, `dwNumberOfProcessors` is the number of processors on the motherboard of the PC. `dwProcessorType` is the actual type of the processor, which can be one of the following:

  Value
  `PROCESSOR_INTEL_386`
  `PROCESSOR_INTEL_486`
  `PROCESSOR_INTEL_PENTIUM`

The other fields are all self-explanatory—just take a look at the Win32 SDK for details. This is an amazing function, however, if you think about it. Can you imagine how hard it is to determine the type of processor installed, let alone how many of them? Where would you even start?

You would start by writing a very complex detection algorithm that knows things about 486s, Pentiums, Pentium IIs, and so on, and it would poke and pry with writes and reads until it figured out what processor was on the machine. Of course, Pentium class processors have ID strings and machine flags, but 486s are a lot harder to figure out. The point is that this is a great function to get system-level information.

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.