Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
96 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 What is DirectX?
 COM
 Setting Up
 DirectDraw
 Cooperation Levels
 Creating Sufaces

 Printable version
 Discuss this article
 in the forums



The Series
 Beginning Windows
 Programming

 Using Resources
 in Win32 Programs

 Tracking Your
 Window/Using GDI

 Introduction
 to DirectX

 Palettes and Pixels
 in DirectDraw

 Bitmapped Graphics
 in DirectDraw

 Developing the
 Game Structure

 Basic Tile Engines
 Adding Characters
 Tips and Tricks

Setting Cooperation and Resolution

We don't need anything fancy here; setting the cooperation level with Windows is as easy as calling IDirectDraw7::SetCooperativeLevel(), and setting the resolution is a simple call to IDirectDraw7::SetDisplayMode(). Is that cool or what? First up is the cooperation level. Here's the function you use:

HRESULT SetCooperativeLevel( HWND hWnd, DWORD dwFlags );

The return type is the HRESULT you should already be getting used to seeing from these DirectX functions. On all such calls, you should be using the SUCCEEDED() or FAILED() macros to test the result of the call. Here are the parameters:

HWND hWnd: Something familiar! Pass the handle to your main window, so Windows knows who's going to be hording all of its resources. :)

DWORD dwFlags: This should look familiar too. Every time we've seen a dwFlags parameter, it almost always results in a big list of constants that can be combined with the | operator. I'd hate to disappoint you!

DDSCL_ALLOWMODEXAllows the use of Mode X display modes (like 320x200, 320x240, or 320x400). This must be combined with DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN.
DDSCL_ALLOWREBOOTAllows the use of the Ctrl+Alt+Del Windows shortcut while running.
DDSCL_EXCLUSIVEIndicates the application will have exclusive access to the display screen; must be combined with DDSCL_FULLSCREEN.
DDSCL_FULLSCREENMicrosoft's effort to create redundancy; it must be combined with DDSCL_EXCLUSIVE. :)
DDSCL_NORMALIndicates a normal Windows application. Use this for windowed DirectX programs. Cannot be combined with DDSCL_ALLOWMODEX, DDSCL_EXCLUSIVE, or DDSCL_FULLSCREEN.
DDSCL_NOWINDOWCHANGESIndicates that DirectDraw may not minimze or restore the application window on activation.

There are also a few flags specific to Windows 98 and NT 5.0 that deal with device windows, but I've left them off the list because we'll only be using these simple flags. Since we want to create a fullscreen application in 640x480x16 resolution, we would use the following call:

lpdd7->SetCooperativeLevel(hwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

So now that the cooperation level is all taken care of, let's look at the function used to change the screen resolution:

HRESULT SetDisplayMode( DWORD dwWidth, DWORD dwHeight, DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags );

Remember to test for success or failure! Most of the parameters are just what you'd expect:

DWORD dwWidth, dwHeight: The dimensions of the new display mode, in pixels.

DWORD dwBPP: The color depth of the new display mode, in bits per pixel. This can be set to 8, 16, 24, or 32. be warned, most video cards do not support 24-bit color.

DWORD dwRefreshRate: This is used to set the refresh rate for the screen, but you should probably just set it to 0, which indicates that the default for your display mode should be used.

DWORD dwFlags: Sorry, I haven't got a big list for you this time. The only valid flag is DDSDM_STANDARDVGAMODE, which sets screen mode 0x13 (the DOS coder's best friend!) instead of Mode X 320x200x8 mode. If you're using something other than 320x200x8, which you almost certainly will be, set this to 0.

That's all it takes to set the resolution to what you want it to be. Keep in mind that the video card may not support every resolution you want to create. 640x480, 800x600, 1024x876, etc. are pretty standard, but if you ask for something like 542x336, you'll almost certainly get an error. Some devices will build some odd display modes, but the idea is to be compatible with as many machines as possible, right? Let's move on.




Next : Creating Surfaces