home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Common / include / ddutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  5.0 KB  |  141 lines

  1. //-----------------------------------------------------------------------------
  2. // File: ddutil.cpp
  3. //
  4. // Desc: Routines for loading bitmap and palettes from resources
  5. //
  6. // Copyright (C) 1998-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef DDUTIL_H
  9. #define DDUTIL_H
  10.  
  11. #include <ddraw.h>
  12. #include <d3d.h>
  13.  
  14.  
  15.  
  16.  
  17. //-----------------------------------------------------------------------------
  18. // Classes defined in this header file 
  19. //-----------------------------------------------------------------------------
  20. class CDisplay;
  21. class CSurface;
  22.  
  23.  
  24.  
  25.  
  26. //-----------------------------------------------------------------------------
  27. // Flags for the CDisplay and CSurface methods
  28. //-----------------------------------------------------------------------------
  29. #define DSURFACELOCK_READ
  30. #define DSURFACELOCK_WRITE
  31.  
  32.  
  33.  
  34.  
  35. //-----------------------------------------------------------------------------
  36. // Name: class CDisplay
  37. // Desc: Class to handle all DDraw aspects of a display, including creation of
  38. //       front and back buffers, creating offscreen surfaces and palettes,
  39. //       and blitting surface and displaying bitmaps.
  40. //-----------------------------------------------------------------------------
  41. class CDisplay
  42. {
  43. protected:
  44.     LPDIRECTDRAW7        m_pDD;
  45.     LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer;
  46.     LPDIRECTDRAWSURFACE7 m_pddsBackBuffer;
  47.     LPDIRECTDRAWSURFACE7 m_pddsBackBufferLeft; // For stereo modes
  48.  
  49.     HWND                 m_hWnd;
  50.     RECT                 m_rcWindow;
  51.     BOOL                 m_bWindowed;
  52.     BOOL                 m_bStereo;
  53.  
  54. public:
  55.     CDisplay();
  56.     ~CDisplay();
  57.  
  58.     // Access functions
  59.     HWND                 GetHWnd()           { return m_hWnd; }
  60.     LPDIRECTDRAW7        GetDirectDraw()     { return m_pDD; }
  61.     LPDIRECTDRAWSURFACE7 GetFrontBuffer()    { return m_pddsFrontBuffer; }
  62.     LPDIRECTDRAWSURFACE7 GetBackBuffer()     { return m_pddsBackBuffer; }
  63.     LPDIRECTDRAWSURFACE7 GetBackBufferLeft() { return m_pddsBackBufferLeft; }
  64.  
  65.     // Status functions
  66.     BOOL    IsWindowed()                     { return m_bWindowed; }
  67.     BOOL    IsStereo()                       { return m_bStereo; }
  68.  
  69.     // Creation/destruction methods
  70.     HRESULT CreateFullScreenDisplay( HWND hWnd, DWORD dwWidth, DWORD dwHeight,
  71.                                      DWORD dwBPP );
  72.     HRESULT CreateWindowedDisplay( HWND hWnd, DWORD dwWidth, DWORD dwHeight );
  73.     HRESULT InitClipper();
  74.     HRESULT UpdateBounds();
  75.     virtual HRESULT DestroyObjects();
  76.  
  77.     // Methods to create child objects
  78.     HRESULT CreateSurface( CSurface** ppSurface, DWORD dwWidth,
  79.                            DWORD dwHeight );
  80.     HRESULT CreateSurfaceFromBitmap( CSurface** ppSurface, TCHAR* strBMP,
  81.                                      DWORD dwDesiredWidth,
  82.                                      DWORD dwDesiredHeight );
  83.     HRESULT CreateSurfaceFromText( CSurface** ppSurface, HFONT hFont,
  84.                                    TCHAR* strText, 
  85.                                    COLORREF crBackground,
  86.                                    COLORREF crForeground );
  87.     HRESULT CreatePaletteFromBitmap( LPDIRECTDRAWPALETTE* ppPalette, const TCHAR* strBMP );
  88.  
  89.     // Display methods
  90.     HRESULT Clear( DWORD dwColor = 0L );
  91.     HRESULT ColorKeyBlt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  92.                          RECT* prc = NULL );
  93.     HRESULT Blt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  94.                  RECT* prc=NULL, DWORD dwFlags=0 );
  95.     HRESULT Blt( DWORD x, DWORD y, CSurface* pSurface, RECT* prc = NULL );
  96.     HRESULT ShowBitmap( HBITMAP hbm, LPDIRECTDRAWPALETTE pPalette=NULL );
  97.     HRESULT SetPalette( LPDIRECTDRAWPALETTE pPalette );
  98.     HRESULT Present();
  99. };
  100.  
  101.  
  102.  
  103.  
  104. //-----------------------------------------------------------------------------
  105. // Name: class CSurface
  106. // Desc: Class to handle aspects of a DirectDrawSurface.
  107. //-----------------------------------------------------------------------------
  108. class CSurface
  109. {
  110.     LPDIRECTDRAWSURFACE7 m_pdds;
  111.     DDSURFACEDESC2       m_ddsd;
  112.     BOOL                 m_bColorKeyed;
  113.  
  114. public:
  115.     LPDIRECTDRAWSURFACE7 GetDDrawSurface() { return m_pdds; }
  116.     BOOL                 IsColorKeyed()    { return m_bColorKeyed; }
  117.  
  118.     HRESULT DrawBitmap( HBITMAP hBMP, DWORD dwBMPOriginX = 0, DWORD dwBMPOriginY = 0, 
  119.                         DWORD dwBMPWidth = 0, DWORD dwBMPHeight = 0 );
  120.     HRESULT DrawBitmap( TCHAR* strBMP, DWORD dwDesiredWidth, DWORD dwDesiredHeight );
  121.     HRESULT DrawText( HFONT hFont, TCHAR* strText, DWORD dwOriginX, DWORD dwOriginY,
  122.                       COLORREF crBackground, COLORREF crForeground );
  123.  
  124.     HRESULT SetColorKey( DWORD dwColorKey );
  125.     DWORD   ConvertGDIColor( COLORREF dwGDIColor );
  126.     static HRESULT GetBitMaskInfo( DWORD dwBitMask, DWORD* pdwShift, DWORD* pdwBits );
  127.  
  128.     HRESULT Create( LPDIRECTDRAW7 pDD, DDSURFACEDESC2* pddsd );
  129.     HRESULT Create( LPDIRECTDRAWSURFACE7 pdds );
  130.     HRESULT Destroy();
  131.  
  132.     CSurface();
  133.     ~CSurface();
  134. };
  135.  
  136.  
  137.  
  138.  
  139. #endif // DDUTIL_H
  140.  
  141.