Tutorial on creating the base for a DirectX fullscreen game 
written by Brian Bintz ( [email protected] )

Table of Contents:

  1. Creating a window
  2. Adding DirectDraw support
  3. Adding DirectInput support
  4. Threads and Synchronizing
  5. Timers and TimerEvents; creating an OnIdle function
  6. Loading BMP files and stripping into individual parts
  7. Drawing Isometric Map
  8. Storing Map Data
  9. whatever else I think of or is suggested

Part I: Creating a Window

For simple window needed by a DirectX app I have always found it easier to use Win32 api. I imagine MFC could also be used, but then you would have to link with the MFC lib all the time and would have the overhead of the extra features MFC gives you, which are really never used or needed. You can look on Dejanews if you want to read more into the debate of using MFC with DirectX.

Steps to create a window using API

  1. fill in WNDCLASS structure
  2. register the window
  3. create the window
  4. show it
  5. update it
The WNDCLASS looks like this:
 
typedef struct _WNDCLASS {    // wc
    UINT    style;
    WNDPROC lpfnWndProc;
    int     cbClsExtra;
    int     cbWndExtra;
    HANDLE  hInstance;
    HICON   hIcon;
    HCURSOR hCursor;
    HBRUSH  hbrBackground;
    LPCTSTR lpszMenuName;
    LPCTSTR lpszClassName;
} WNDCLASS;
 
look in the help files for more specifics on it. Basically, style should be CS_HREDRAW and CS_VREDRAW so that DirectX knows to redraw the screen. lpfnWndProc should be a ptr to your defined WindowProc. You should cast your function to a WNDPROC to be safe. Everything else should be fairly obvious, if you have problems email me.

NOTE on WNDPROC:
       WndProc is a pain to use in a class. It has to be defined as static so that a this* is not passed to it, since its supposed to be a C function. Unlike TimerEvents which allow a user to pass a custom variable as an added argument. TimerEvents will be discussed later. This extra argument can be used as a ptr to the functions owning class. Many different ways of getting around WndProc's problems have been discussed on Dejanews and your welcome to look there for more info. One way is to have a global ptr to the class, which your WndProc can use to access public variables. Private var access is another matter though and much more of a hassle, though. It should be defined something like the following

                   static long WINAPI WindowProc(HWND hWnd, UINT message,
                                                                       WPARAM wParam, LPARAM lParam )

To Register Window:
simply call RegisterClass( &your_wndclass );

To Create Window:
call CreateWindowEx( ); you should capture the returned HWND and save it because DirectX needs it to initialize the DirectDraw Object. I perfer to keep the window creation as simple as possible, so I create a popup the size of the screen. I get the screen size using GetSystemMetrics( ); lookup these functions for more info

Showing and Updating Window:
very easy simply call
       ShowWindow(hwnd, nCmdShow);
       UpdateWindow(hwnd);

Thats all there is to it and it is easy to build a class around this from which your individual programs can inherit from. If you need help on this email me, but you shouldn't need any.
 

Next up... Adding DirectDraw support


This document is copyright (c) 1998 by Brian Bintz (tetrabyte)
All rights reserved. Windows IG is a subdivision of TPU