home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow_WinXP / VMR / VMRXcl / DDrawSupport.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.2 KB  |  117 lines

  1. //----------------------------------------------------------------------------
  2. //  File:   DDrawSupport.cpp
  3. //
  4. //  Desc:   DirectShow sample code
  5. //          Implementation of DDrawObject that provides basic DDraw functionality
  6. //
  7. //  Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
  8. //----------------------------------------------------------------------------
  9. #include "project.h"
  10. #include <d3d.h>
  11.  
  12. //----------------------------------------------------------------------------
  13. //  Initialize
  14. //
  15. //  Initialize DDrawObject by getting to fullscreen exclusive mode and 
  16. //  setting front and back buffer
  17. //----------------------------------------------------------------------------
  18. HRESULT
  19. CDDrawObject::Initialize(HWND hWndApp)
  20. {
  21.     HRESULT         hr;
  22.     DDSURFACEDESC2  ddsd;
  23.  
  24.     m_hwndApp = hWndApp;
  25.  
  26.     hr = DirectDrawCreateEx(NULL, (LPVOID *)&m_pDDObject,
  27.                             IID_IDirectDraw7, NULL);
  28.  
  29.     if (FAILED(hr)) {
  30.         return hr;
  31.     }
  32.  
  33.     // Get into fullscreen exclusive mode
  34.     hr = m_pDDObject->SetCooperativeLevel(hWndApp,
  35.                                           DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN |
  36.                                           DDSCL_ALLOWREBOOT);
  37.     if (FAILED(hr)) {
  38.         Terminate();
  39.         return hr;
  40.     }
  41.  
  42.     hr = m_pDDObject->SetDisplayMode(SCRN_WIDTH, SCRN_HEIGHT, SCRN_BITDEPTH,
  43.                                      0, DDSDM_STANDARDVGAMODE);
  44.  
  45.     if (FAILED(hr)) {
  46.         Terminate();
  47.         return hr;
  48.     }
  49.  
  50.  
  51.     // Create the primary surface with 1 back buffer
  52.     ZeroMemory(&ddsd, sizeof(ddsd));
  53.     ddsd.dwSize = sizeof(ddsd);
  54.     ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  55.     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
  56.                           DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
  57.     ddsd.dwBackBufferCount = 2;
  58.     hr = m_pDDObject->CreateSurface(&ddsd, &m_pPrimary, NULL);
  59.     if (FAILED(hr)) {
  60.         Terminate();
  61.         return hr;
  62.     }
  63.  
  64.     // Get a pointer to the back buffer
  65.     DDSCAPS2  ddscaps = { DDSCAPS_BACKBUFFER, 0, 0, 0 };
  66.     hr = m_pPrimary->GetAttachedSurface(&ddscaps, &m_pBackBuff);
  67.     if (FAILED(hr)) {
  68.         Terminate();
  69.         return hr;
  70.     }
  71.  
  72.  
  73.     // Get the screen size and save it as a rect
  74.     ZeroMemory(&ddsd, sizeof(ddsd));
  75.     ddsd.dwSize = sizeof(ddsd);
  76.     hr = m_pPrimary->GetSurfaceDesc(&ddsd);
  77.     if (!(SUCCEEDED(hr) &&
  78.          (ddsd.dwFlags & DDSD_WIDTH) && (ddsd.dwFlags & DDSD_HEIGHT))) {
  79.  
  80.         Terminate();
  81.         return hr;
  82.     }
  83.  
  84.     SetRect(&m_RectScrn, 0, 0, ddsd.dwWidth, ddsd.dwHeight);
  85.  
  86.     return S_OK;
  87. }
  88.  
  89. //----------------------------------------------------------------------------
  90. // Terminate
  91. //
  92. // return from exclusive mode
  93. //----------------------------------------------------------------------------
  94. HRESULT
  95. CDDrawObject::Terminate()
  96. {
  97.  
  98.     if (m_pBackBuff) {
  99.         m_pBackBuff->Release();
  100.         m_pBackBuff = NULL;
  101.     }
  102.  
  103.     if (m_pPrimary) {
  104.         m_pPrimary->Release();
  105.         m_pPrimary = NULL;
  106.     }
  107.  
  108.     if (m_pDDObject) {
  109.  
  110.         m_pDDObject->SetCooperativeLevel(m_hwndApp, DDSCL_NORMAL) ;
  111.         m_pDDObject->Release();
  112.         m_pDDObject = NULL;
  113.     }
  114.  
  115.     return S_OK;
  116. }
  117.