CDirectDrawGame.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
- ///////////////////////////////////////////////////////////////////////////////
- /// File: CDirectDrawGame.h
- /// Purpose: Declaration of CDirectDrawGame Class
- ///
- /// This class represents the DirectX components required to construct
- /// a simple DirectX based game.
- ///////////////////////////////////////////////////////////////////////////////
- /// Configuation Management
- ///
- /// Who When Description
- /// ===========================================================================
- /// R. Walter 28-Dec-2003 Initial Version/Release
- ///
- ///////////////////////////////////////////////////////////////////////////////
- /// Copyright 2003: Robert Walter All rights reserved
- ///////////////////////////////////////////////////////////////////////////////
- #ifndef CDIRECTDRAWGAME_H_
- #define CDIRECTDRAWGAME_H_
- /// HEADER DEFINES ////////////////////////////////////////////////////////////
- #define WIN32_LEAN_AND_MEAN
- /// HEADER FILE INCLUDES //////////////////////////////////////////////////////
- #include <windows.h>
- #include <windowsx.h>
- #include <objbase.h>
- #include <string.h>
- #include <ddraw.h>
- #include <dinput.h>
- /// TYPE / CLASS DECLARATIONS /////////////////////////////////////////////////
- class CDirectDrawGame
- {
- protected:
- // DirectDraw member variables
- LPDIRECTDRAW7 m_lpdd7;
- LPDIRECTDRAWSURFACE7 m_lpdds_primary;
- LPDIRECTDRAWSURFACE7 m_lpdds_back;
- // DirectInput member variables
- LPDIRECTINPUT8 m_lpdi8;
- LPDIRECTINPUTDEVICE8 m_di_keyboard;
- UCHAR m_di_keystate[256];
- // Win32 member variables
- HINSTANCE m_instance;
- HWND m_main_hwnd;
- HDC m_hdc;
-
- // DirectDraw screen property variables
- DWORD m_screen_width;
- DWORD m_screen_height;
- DWORD m_screen_bpp;
- // frame rate management variables
- DWORD m_frame_fps;
- DWORD m_wait_ms;
- DWORD m_tick_cnt;
- // 16-bit color management variables
- WORD m_num_red_bits;
- WORD m_num_green_bits;
- WORD m_num_blue_bits;
- WORD m_low_red_bit;
- WORD m_low_green_bit;
- WORD m_low_blue_bit;
- // 16-bit color management functions
- void CalculateRGBBitShift(DWORD p_bit_mask, WORD* p_low_bit, WORD* p_num_bits);
- DWORD RGBto16BitColor(DWORD p_red, DWORD p_green, DWORD p_blue);
-
- public:
- // constructors
- CDirectDrawGame();
-
- // destructors
- virtual ~CDirectDrawGame();
- // DirectX initialization functions
- bool InitializeDirectDraw();
- bool InitializeDirectInput();
- void ShutdownDirectDraw();
- void ShutdownDirectInput();
- // DirectDraw helper functions
- bool StartScene(const DWORD p_color);
- bool DrawRectangle(RECT* p_rectangle, const DWORD p_color);
- bool EndScene();
- // DirectInput helper functions
- bool GetKeyboardState(UCHAR* p_keyboard);
- // GDI helper function
- bool StartGDIDrawing();
- bool DrawGDIText(char* p_text, DWORD p_r, DWORD p_g, DWORD p_b, HFONT p_font, int p_x, int p_y);
- void EndGDIDrawing();
-
- // class helper functions
- void SetApplicationInstance(const HINSTANCE p_instance);
- void SetFrameRate(const DWORD p_frame_fps);
- void SetScreenProperties(const DWORD p_screen_width, const DWORD p_screen_height, const DWORD p_screen_bpp);
- void SetWindowHandle(const HWND p_hwnd);
- // frame rate management functions
- void FrameRateStart();
- void FrameRateEnd();
- };
- #endif