This phrase might like
an oxymoron, but when creating a game for Windows CE, you have to take
into account the different platforms you may have to, or choose to, support
in the future. The older Windows CE machines, running Windows CE 1.00,
are limited to 2-bit displays, a custom bitmap format (.2bp) and can have
as small as 480x240 displays. Now, the SDK will automatically convert
.bmp files to .2bp format for you, when you target version 1.0 or 1.01
of Windows CE (as I discovered to my pleasant surprise.) But, you still
must know how and where you're going to display those bitmap images. The
latest and greatest devices range from 240x320, four gray-scale displays
to 640x480 8-bit displays, with 800x600x16-bit supported by the H/PC Pro.
Therefore, the first thing we want to do is find out what display environment
we're working in. The way we find this out is with GetSystemMetrics().
Where you make this call is up to you, just so long as you do it before
you draw to the display. I chose to place it in the constructor for the
CWizCEView class.
Setting Up the Display
Add four int variables
to the CWizCEView class: CScreenWidth,
CScreenHeight, CViewOffsetX, CViewOffsetY.
We'll use these to retrieve the width and height of the screen, and to
calculate the offset required to center the view on the display. The first
thing we do is get the width and height of our display.
// get the width of
the
//
screen and save it for
later
CScreenWidth = ::GetSystemMetrics(SM_CXSCREEN); CScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
// determine what display we're using so we can
//tell which .BMP to display
If(CScreenWidth > CScreenHeight) {
COrientation = HPC;
if(CScreenHeight > 240)
We also need to add an enum
for which display orientation we're using:
enum { HPC, PALMPC,
PROPC };
int COrientation;
Depending upon the orientation,
we'll use either a bitmap that is 320x200, or 240x240. The display orientation
would not determine what bitmap we use, because we'd be using a tilemap
to draw the display. But for now we're just pasting a .bmp to the screen.
Try to compile this; there should be no noticeable difference in the application,
but now is a good time to test this part of the code before we go on.
Showing the Backdrop
Now it's time to add the
.bmps we'll be using. We'll add them right into the project for now, rather
than having them accessed as files later. That prevents some headaches
and saves the overhead of writing the file access routines. Later we won't
do this, because we'll want the ability to change bitmaps without recompiling
the application (for developing a sequel, for example.)
How to include bitmap resources
in a Visual C++ project is beyond the scope of this article, so I'll just
say that you should add two bitmap resources for Hall1.bmp and Hall2.bmp,
and name them Hall1 and Hall2. Hall1 is the landscape orientation of the
background bitmap for HPCs, and Hall2 is the portrait orientation for
PalmPCs. Create a CBitmap class object as part of the CWizCEView
class called "Background". Insert the following code into the CWizCEView()
constructor after the code we've just added:
What we do here is straightforward,
preparing for the future. Depending upon the orientation of the display
(landscape for HPCs, portrait for PalmPCs), we set the view offset with
this formula, which centers the bitmap in the display. We'll have to use
these offsets for all of our drawing, to keep the backdrop, sprites and
foreground objects all displayed in the same screen area. The Loadbitmap
calls load the appropriate bitmap from which to get the backdrop imagery,
again dependent upon the display orientation. For HPCs or HPC Pros, it
selects Hall1.bmp, the landscape orientation. For PalmPCs, it selects
the portrait orientation.
The TEXT
macro is one of those Windows CE gotchas you need to watch out for. For
Windows 9x, the LoadBitmap
call uses a LPCSTR pointer;
in MFC, they use the _T()
function to convert to Unicode; in Windows CE, we have the TEXT
macro. Basically all this does is convert a 1 byte/character ANSI string
into a 2-byte/character Unicode string.