Setting Cooperation and ResolutionWe 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:
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!
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:
So now that the cooperation level is all taken care of, let's look at the function used to change the screen resolution:
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. |
|||||||||||||