Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1199 lines
35 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //-----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgDirectDrawDisplay.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // starting point for adding extra functionality.
  13. //-----------------------------------------------------------------------------
  14. //-----------------------------------------------------------------------------
  15. // File: ddutil.cpp
  16. //
  17. // Desc: DirectDraw framewark classes. Feel free to use this class as a
  18. // starting point for adding extra functionality.
  19. //
  20. //
  21. // Copyright (c) 1995-2001 Microsoft Corporation. All rights reserved.
  22. //-----------------------------------------------------------------------------
  23. //#define STRICT
  24. #include "stdafx.h"
  25. #include "LgDirectDrawDisplay.h"
  26. //-----------------------------------------------------------------------------
  27. // Name: CLgDirectDrawDisplay()
  28. // Desc:
  29. //-----------------------------------------------------------------------------
  30. CLgDirectDrawDisplay::CLgDirectDrawDisplay()
  31. {
  32. m_pDD = NULL;
  33. m_pddsFrontBuffer = NULL;
  34. m_pddsBackBuffer = NULL;
  35. m_pddsBackBufferLeft = NULL;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Name: ~CLgDirectDrawDisplay()
  39. // Desc:
  40. //-----------------------------------------------------------------------------
  41. CLgDirectDrawDisplay::~CLgDirectDrawDisplay()
  42. {
  43. DestroyObjects();
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Name: DestroyObjects()
  47. // Desc:
  48. //-----------------------------------------------------------------------------
  49. HRESULT CLgDirectDrawDisplay::DestroyObjects()
  50. {
  51. SAFE_RELEASE( m_pddsBackBufferLeft );
  52. SAFE_RELEASE( m_pddsBackBuffer );
  53. SAFE_RELEASE( m_pddsFrontBuffer );
  54. if( m_pDD )
  55. m_pDD->SetCooperativeLevel( m_hWnd, DDSCL_NORMAL );
  56. SAFE_RELEASE( m_pDD );
  57. return S_OK;
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Name: CreateFullScreenDisplay()
  61. // Desc:
  62. //-----------------------------------------------------------------------------
  63. HRESULT CLgDirectDrawDisplay::CreateFullScreenDisplay( HWND hWnd, DWORD dwWidth,
  64. DWORD dwHeight, DWORD dwBPP )
  65. {
  66. HRESULT hr;
  67. // Cleanup anything from a previous call
  68. DestroyObjects();
  69. // DDraw stuff begins here
  70. if( FAILED( hr = DirectDrawCreateEx( NULL, (VOID**)&m_pDD,
  71. IID_IDirectDraw7, NULL ) ) )
  72. return E_FAIL;
  73. // Set cooperative level
  74. hr = m_pDD->SetCooperativeLevel( hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN );
  75. if( FAILED(hr) )
  76. return E_FAIL;
  77. // Set the display mode
  78. if( FAILED( m_pDD->SetDisplayMode( dwWidth, dwHeight, dwBPP, 0, 0 ) ) )
  79. return E_FAIL;
  80. // Create primary surface (with backbuffer attached)
  81. DDSURFACEDESC2 ddsd;
  82. ZeroMemory( &ddsd, sizeof( ddsd ) );
  83. ddsd.dwSize = sizeof( ddsd );
  84. ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  85. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
  86. DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
  87. ddsd.dwBackBufferCount = 1;
  88. if( FAILED( hr = m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer,
  89. NULL ) ) )
  90. return E_FAIL;
  91. // Get a pointer to the back buffer
  92. DDSCAPS2 ddscaps;
  93. ZeroMemory( &ddscaps, sizeof( ddscaps ) );
  94. ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  95. if( FAILED( hr = m_pddsFrontBuffer->GetAttachedSurface( &ddscaps,
  96. &m_pddsBackBuffer ) ) )
  97. return E_FAIL;
  98. m_pddsBackBuffer->AddRef();
  99. m_hWnd = hWnd;
  100. m_bWindowed = FALSE;
  101. UpdateBounds();
  102. return S_OK;
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Name: CreateWindowedDisplay()
  106. // Desc:
  107. //-----------------------------------------------------------------------------
  108. HRESULT CLgDirectDrawDisplay::CreateWindowedDisplay( HWND hWnd, DWORD dwWidth, DWORD dwHeight )
  109. {
  110. HRESULT hr;
  111. // Cleanup anything from a previous call
  112. DestroyObjects();
  113. // DDraw stuff begins here
  114. if( FAILED( hr = DirectDrawCreateEx( NULL, (VOID**)&m_pDD,
  115. IID_IDirectDraw7, NULL ) ) )
  116. return E_FAIL;
  117. // Set cooperative level
  118. hr = m_pDD->SetCooperativeLevel( hWnd, DDSCL_NORMAL );
  119. if( FAILED(hr) )
  120. return E_FAIL;
  121. /*
  122. RECT rcWork;
  123. RECT rc;
  124. DWORD dwStyle;
  125. // If we are still a WS_POPUP window we should convert to a normal app
  126. // window so we look like a windows app.
  127. dwStyle = GetWindowStyle( hWnd );
  128. dwStyle &= ~WS_POPUP;
  129. dwStyle |= WS_CHILD; //WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX;
  130. SetWindowLong( hWnd, GWL_STYLE, dwStyle );
  131. // Aet window size
  132. SetRect( &rc, 0, 0, dwWidth, dwHeight );
  133. AdjustWindowRectEx( &rc, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL,
  134. GetWindowExStyle(hWnd) );
  135. SetWindowPos( hWnd, NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top,
  136. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
  137. SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
  138. SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
  139. // Make sure our window does not hang outside of the work area
  140. SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
  141. GetWindowRect( hWnd, &rc );
  142. if( rc.left < rcWork.left ) rc.left = rcWork.left;
  143. if( rc.top < rcWork.top ) rc.top = rcWork.top;
  144. SetWindowPos( hWnd, NULL, rc.left, rc.top, 0, 0,
  145. SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
  146. */
  147. LPDIRECTDRAWCLIPPER pcClipper;
  148. // Create the primary surface
  149. DDSURFACEDESC2 ddsd;
  150. ZeroMemory( &ddsd, sizeof( ddsd ) );
  151. ddsd.dwSize = sizeof( ddsd );
  152. ddsd.dwFlags = DDSD_CAPS;
  153. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  154. if( FAILED( m_pDD->CreateSurface( &ddsd, &m_pddsFrontBuffer, NULL ) ) )
  155. return E_FAIL;
  156. // Create the backbuffer surface
  157. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  158. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE/* | DDSCAPS_VIDEOMEMORY*/;
  159. ddsd.dwWidth = dwWidth;
  160. ddsd.dwHeight = dwHeight;
  161. if( FAILED( hr = m_pDD->CreateSurface( &ddsd, &m_pddsBackBuffer, NULL ) ) )
  162. return E_FAIL;
  163. if( FAILED( hr = m_pDD->CreateClipper( 0, &pcClipper, NULL ) ) )
  164. return E_FAIL;
  165. if( FAILED( hr = pcClipper->SetHWnd( 0, hWnd ) ) )
  166. {
  167. pcClipper->Release();
  168. return E_FAIL;
  169. }
  170. if( FAILED( hr = m_pddsFrontBuffer->SetClipper( pcClipper ) ) )
  171. {
  172. pcClipper->Release();
  173. return E_FAIL;
  174. }
  175. // Done with clipper
  176. pcClipper->Release();
  177. m_hWnd = hWnd;
  178. m_bWindowed = TRUE;
  179. UpdateBounds();
  180. return S_OK;
  181. }
  182. HRESULT CLgDirectDrawDisplay::BackBufferDrawText( HFONT hFont, TCHAR* strText, PRECT pRect, DWORD dwFlags, COLORREF crForeground, BOOL bTransparent, COLORREF crBackground )
  183. {
  184. HDC hDC = NULL;
  185. HRESULT hr;
  186. if( m_pddsBackBuffer == NULL || strText == NULL )
  187. return E_INVALIDARG;
  188. // Make sure this surface is restored.
  189. if( FAILED( hr = m_pddsBackBuffer->Restore() ) )
  190. return hr;
  191. if( FAILED( hr = m_pddsBackBuffer->GetDC( &hDC ) ) )
  192. return hr;
  193. // Set the background and foreground color
  194. INT nBkColor = SetBkColor( hDC, crBackground );
  195. INT nTextColor = SetTextColor( hDC, crForeground );
  196. INT nBkMode = SetBkMode( hDC, bTransparent ? TRANSPARENT : OPAQUE );
  197. HFONT hOldFont = hFont ? (HFONT)SelectObject( hDC, hFont ) : NULL;
  198. // Use GDI to draw the text on the surface
  199. DrawText( hDC, strText, _tcslen(strText), pRect, dwFlags );
  200. SetBkColor( hDC, nBkColor );
  201. SetTextColor( hDC, nTextColor );
  202. SetBkMode( hDC, nBkMode );
  203. if( hFont )
  204. SelectObject( hDC, hOldFont );
  205. if( FAILED( hr = m_pddsBackBuffer->ReleaseDC( hDC ) ) )
  206. return hr;
  207. return S_OK;
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Name:
  211. // Desc:
  212. //-----------------------------------------------------------------------------
  213. HRESULT CLgDirectDrawDisplay::CreateSurface( CLgDirectDrawSurface** ppSurface,
  214. DWORD dwWidth, DWORD dwHeight )
  215. {
  216. if( NULL == m_pDD )
  217. return E_POINTER;
  218. if( NULL == ppSurface )
  219. return E_INVALIDARG;
  220. HRESULT hr;
  221. DDSURFACEDESC2 ddsd;
  222. ZeroMemory( &ddsd, sizeof( ddsd ) );
  223. ddsd.dwSize = sizeof( ddsd );
  224. ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  225. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN/* | DDSCAPS_VIDEOMEMORY*/;
  226. ddsd.dwWidth = dwWidth;
  227. ddsd.dwHeight = dwHeight;
  228. (*ppSurface) = new CLgDirectDrawSurface();
  229. if( FAILED( hr = (*ppSurface)->Create( m_pDD, &ddsd ) ) )
  230. {
  231. delete (*ppSurface);
  232. return hr;
  233. }
  234. return S_OK;
  235. }
  236. //-----------------------------------------------------------------------------
  237. // Name: CLgDirectDrawDisplay::CreateSurfaceFromBitmap()
  238. // Desc: Create a DirectDrawSurface from a bitmap resource or bitmap file.
  239. // Use MAKEINTRESOURCE() to pass a constant into strBMP.
  240. //-----------------------------------------------------------------------------
  241. HRESULT CLgDirectDrawDisplay::CreateSurfaceFromBitmap( CLgDirectDrawSurface** ppSurface,
  242. TCHAR* strBMP,
  243. DWORD dwDesiredWidth,
  244. DWORD dwDesiredHeight )
  245. {
  246. HRESULT hr;
  247. HBITMAP hBMP = NULL;
  248. BITMAP bmp;
  249. DDSURFACEDESC2 ddsd;
  250. if( m_pDD == NULL || strBMP == NULL || ppSurface == NULL )
  251. return E_INVALIDARG;
  252. *ppSurface = NULL;
  253. // Try to load the bitmap as a resource, if that fails, try it as a file
  254. hBMP = (HBITMAP) LoadImage( GetModuleHandle(NULL), strBMP,
  255. IMAGE_BITMAP, dwDesiredWidth, dwDesiredHeight,
  256. LR_CREATEDIBSECTION );
  257. if( hBMP == NULL )
  258. {
  259. hBMP = (HBITMAP) LoadImage( NULL, strBMP,
  260. IMAGE_BITMAP, dwDesiredWidth, dwDesiredHeight,
  261. LR_LOADFROMFILE | LR_CREATEDIBSECTION );
  262. if( hBMP == NULL )
  263. return E_FAIL;
  264. }
  265. // Get size of the bitmap
  266. GetObject( hBMP, sizeof(bmp), &bmp );
  267. // Create a DirectDrawSurface for this bitmap
  268. ZeroMemory( &ddsd, sizeof(ddsd) );
  269. ddsd.dwSize = sizeof(ddsd);
  270. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  271. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  272. ddsd.dwWidth = bmp.bmWidth;
  273. ddsd.dwHeight = bmp.bmHeight;
  274. (*ppSurface) = new CLgDirectDrawSurface();
  275. if( FAILED( hr = (*ppSurface)->Create( m_pDD, &ddsd ) ) )
  276. {
  277. delete (*ppSurface);
  278. return hr;
  279. }
  280. // Draw the bitmap on this surface
  281. if( FAILED( hr = (*ppSurface)->DrawBitmap( hBMP, 0, 0, 0, 0 ) ) )
  282. {
  283. DeleteObject( hBMP );
  284. return hr;
  285. }
  286. DeleteObject( hBMP );
  287. return S_OK;
  288. }
  289. //-----------------------------------------------------------------------------
  290. // Name: CLgDirectDrawDisplay::CreateSurfaceFromText()
  291. // Desc: Creates a DirectDrawSurface from a text string using hFont or the default
  292. // GDI font if hFont is NULL.
  293. //-----------------------------------------------------------------------------
  294. HRESULT CLgDirectDrawDisplay::CreateSurfaceFromText( CLgDirectDrawSurface** ppSurface,
  295. HFONT hFont, TCHAR* strText,
  296. COLORREF crBackground, COLORREF crForeground )
  297. {
  298. HDC hDC = NULL;
  299. LPDIRECTDRAWSURFACE7 pDDS = NULL;
  300. HRESULT hr;
  301. DDSURFACEDESC2 ddsd;
  302. SIZE sizeText;
  303. if( m_pDD == NULL || strText == NULL || ppSurface == NULL )
  304. return E_INVALIDARG;
  305. *ppSurface = NULL;
  306. hDC = GetDC( NULL );
  307. if( hFont )
  308. SelectObject( hDC, hFont );
  309. GetTextExtentPoint32( hDC, strText, _tcslen(strText), &sizeText );
  310. ReleaseDC( NULL, hDC );
  311. // Create a DirectDrawSurface for this bitmap
  312. ZeroMemory( &ddsd, sizeof(ddsd) );
  313. ddsd.dwSize = sizeof(ddsd);
  314. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  315. ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
  316. ddsd.dwWidth = sizeText.cx;
  317. ddsd.dwHeight = sizeText.cy;
  318. (*ppSurface) = new CLgDirectDrawSurface();
  319. if( FAILED( hr = (*ppSurface)->Create( m_pDD, &ddsd ) ) )
  320. {
  321. delete (*ppSurface);
  322. return hr;
  323. }
  324. if( FAILED( hr = (*ppSurface)->DrawText( hFont, strText, 0, 0,
  325. crBackground, crForeground, FALSE ) ) )
  326. return hr;
  327. return S_OK;
  328. }
  329. //-----------------------------------------------------------------------------
  330. // Name:
  331. // Desc:
  332. //-----------------------------------------------------------------------------
  333. HRESULT CLgDirectDrawDisplay::Present()
  334. {
  335. HRESULT hr;
  336. if( NULL == m_pddsFrontBuffer && NULL == m_pddsBackBuffer )
  337. return E_POINTER;
  338. while( 1 )
  339. {
  340. if( m_bWindowed )
  341. hr = m_pddsFrontBuffer->Blt( &m_rcWindow, m_pddsBackBuffer,
  342. NULL, DDBLT_WAIT, NULL );
  343. else
  344. hr = m_pddsFrontBuffer->Flip( NULL, 0 );
  345. if( hr == DDERR_SURFACELOST )
  346. {
  347. m_pddsFrontBuffer->Restore();
  348. m_pddsBackBuffer->Restore();
  349. }
  350. if( hr != DDERR_WASSTILLDRAWING )
  351. return hr;
  352. }
  353. }
  354. //-----------------------------------------------------------------------------
  355. // Name:
  356. // Desc:
  357. //-----------------------------------------------------------------------------
  358. HRESULT CLgDirectDrawDisplay::ShowBitmap( HBITMAP hbm, LPDIRECTDRAWPALETTE pPalette )
  359. {
  360. if( NULL == m_pddsFrontBuffer || NULL == m_pddsBackBuffer )
  361. return E_POINTER;
  362. // Set the palette before loading the bitmap
  363. if( pPalette )
  364. m_pddsFrontBuffer->SetPalette( pPalette );
  365. CLgDirectDrawSurface backBuffer;
  366. backBuffer.Create( m_pddsBackBuffer );
  367. if( FAILED( backBuffer.DrawBitmap( hbm, 0, 0, 0, 0 ) ) )
  368. return E_FAIL;
  369. return Present();
  370. }
  371. //-----------------------------------------------------------------------------
  372. // Name:
  373. // Desc:
  374. //-----------------------------------------------------------------------------
  375. HRESULT CLgDirectDrawDisplay::ColorKeyBlt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
  376. RECT* prc )
  377. {
  378. if( NULL == m_pddsBackBuffer )
  379. return E_POINTER;
  380. return m_pddsBackBuffer->BltFast( x, y, pdds, prc, DDBLTFAST_SRCCOLORKEY );
  381. }
  382. //-----------------------------------------------------------------------------
  383. // Name:
  384. // Desc:
  385. //-----------------------------------------------------------------------------
  386. HRESULT CLgDirectDrawDisplay::Blt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds, RECT* prc,
  387. DWORD dwFlags )
  388. {
  389. if( NULL == m_pddsBackBuffer )
  390. return E_POINTER;
  391. return m_pddsBackBuffer->BltFast( x, y, pdds, prc, dwFlags );
  392. }
  393. //-----------------------------------------------------------------------------
  394. // Name:
  395. // Desc:
  396. //-----------------------------------------------------------------------------
  397. HRESULT CLgDirectDrawDisplay::Blt( DWORD x, DWORD y, CLgDirectDrawSurface* pSurface, RECT* prc )
  398. {
  399. if( NULL == pSurface )
  400. return E_INVALIDARG;
  401. if( pSurface->IsColorKeyed() )
  402. return Blt( x, y, pSurface->GetDDrawSurface(), prc, DDBLTFAST_SRCCOLORKEY );
  403. else
  404. return Blt( x, y, pSurface->GetDDrawSurface(), prc, 0L );
  405. }
  406. HRESULT CLgDirectDrawDisplay::Blt( CLgDirectDrawSurface *pSurface, PRECT pDstRect, PRECT pSrcRect, DWORD dwFlags )
  407. {
  408. if( NULL == pSurface )
  409. return E_INVALIDARG;
  410. /*
  411. RECT srcRect;
  412. if( !pSrcRect )
  413. ::SetRect( pSrcRect = &srcRect, 0, 0, pSurface->GetSize().cx, pSurface->GetSize().cy );
  414. RECT dstRect;
  415. if( !pDstRect )
  416. ::GetClientRect( GetHWnd(), pDstRect = &dstRect );
  417. */
  418. return m_pddsBackBuffer->Blt( pDstRect, pSurface->GetDDrawSurface(), pSrcRect, dwFlags, NULL );
  419. }
  420. //-----------------------------------------------------------------------------
  421. // Name:
  422. // Desc:
  423. //-----------------------------------------------------------------------------
  424. HRESULT CLgDirectDrawDisplay::Clear( DWORD dwColor )
  425. {
  426. if( NULL == m_pddsBackBuffer )
  427. return E_POINTER;
  428. // Erase the background
  429. DDBLTFX ddbltfx;
  430. ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
  431. ddbltfx.dwSize = sizeof(ddbltfx);
  432. ddbltfx.dwFillColor = dwColor;
  433. return m_pddsBackBuffer->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );
  434. }
  435. //-----------------------------------------------------------------------------
  436. // Name:
  437. // Desc:
  438. //-----------------------------------------------------------------------------
  439. HRESULT CLgDirectDrawDisplay::SetPalette( LPDIRECTDRAWPALETTE pPalette )
  440. {
  441. if( NULL == m_pddsFrontBuffer )
  442. return E_POINTER;
  443. return m_pddsFrontBuffer->SetPalette( pPalette );
  444. }
  445. //-----------------------------------------------------------------------------
  446. // Name:
  447. // Desc:
  448. //-----------------------------------------------------------------------------
  449. HRESULT CLgDirectDrawDisplay::CreatePaletteFromBitmap( LPDIRECTDRAWPALETTE* ppPalette,
  450. const TCHAR* strBMP )
  451. {
  452. HRSRC hResource = NULL;
  453. RGBQUAD* pRGB = NULL;
  454. BITMAPINFOHEADER* pbi = NULL;
  455. PALETTEENTRY aPalette[256];
  456. HANDLE hFile = NULL;
  457. DWORD iColor;
  458. DWORD dwColors;
  459. BITMAPFILEHEADER bf;
  460. BITMAPINFOHEADER bi;
  461. DWORD dwBytesRead;
  462. if( m_pDD == NULL || strBMP == NULL || ppPalette == NULL )
  463. return E_INVALIDARG;
  464. *ppPalette = NULL;
  465. // Try to load the bitmap as a resource, if that fails, try it as a file
  466. hResource = FindResource( NULL, strBMP, RT_BITMAP );
  467. if( hResource )
  468. {
  469. pbi = (LPBITMAPINFOHEADER) LockResource( LoadResource( NULL, hResource ) );
  470. if( NULL == pbi )
  471. return E_FAIL;
  472. pRGB = (RGBQUAD*) ( (BYTE*) pbi + pbi->biSize );
  473. // Figure out how many colors there are
  474. if( pbi == NULL || pbi->biSize < sizeof(BITMAPINFOHEADER) )
  475. dwColors = 0;
  476. else if( pbi->biBitCount > 8 )
  477. dwColors = 0;
  478. else if( pbi->biClrUsed == 0 )
  479. dwColors = 1 << pbi->biBitCount;
  480. else
  481. dwColors = pbi->biClrUsed;
  482. // A DIB color table has its colors stored BGR not RGB
  483. // so flip them around.
  484. for( iColor = 0; iColor < dwColors; iColor++ )
  485. {
  486. aPalette[iColor].peRed = pRGB[iColor].rgbRed;
  487. aPalette[iColor].peGreen = pRGB[iColor].rgbGreen;
  488. aPalette[iColor].peBlue = pRGB[iColor].rgbBlue;
  489. aPalette[iColor].peFlags = 0;
  490. }
  491. return m_pDD->CreatePalette( DDPCAPS_8BIT, aPalette, ppPalette, NULL );
  492. }
  493. // Attempt to load bitmap as a file
  494. hFile = CreateFile( strBMP, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL );
  495. if( NULL == hFile )
  496. return E_FAIL;
  497. // Read the BITMAPFILEHEADER
  498. ReadFile( hFile, &bf, sizeof(bf), &dwBytesRead, NULL );
  499. if( dwBytesRead != sizeof(bf) )
  500. {
  501. CloseHandle( hFile );
  502. return E_FAIL;
  503. }
  504. // Read the BITMAPINFOHEADER
  505. ReadFile( hFile, &bi, sizeof(bi), &dwBytesRead, NULL );
  506. if( dwBytesRead != sizeof(bi) )
  507. {
  508. CloseHandle( hFile );
  509. return E_FAIL;
  510. }
  511. // Read the PALETTEENTRY
  512. ReadFile( hFile, aPalette, sizeof(aPalette), &dwBytesRead, NULL );
  513. if( dwBytesRead != sizeof(aPalette) )
  514. {
  515. CloseHandle( hFile );
  516. return E_FAIL;
  517. }
  518. CloseHandle( hFile );
  519. // Figure out how many colors there are
  520. if( bi.biSize != sizeof(BITMAPINFOHEADER) )
  521. dwColors = 0;
  522. else if (bi.biBitCount > 8)
  523. dwColors = 0;
  524. else if (bi.biClrUsed == 0)
  525. dwColors = 1 << bi.biBitCount;
  526. else
  527. dwColors = bi.biClrUsed;
  528. // A DIB color table has its colors stored BGR not RGB
  529. // so flip them around since DirectDraw uses RGB
  530. for( iColor = 0; iColor < dwColors; iColor++ )
  531. {
  532. BYTE r = aPalette[iColor].peRed;
  533. aPalette[iColor].peRed = aPalette[iColor].peBlue;
  534. aPalette[iColor].peBlue = r;
  535. }
  536. return m_pDD->CreatePalette( DDPCAPS_8BIT, aPalette, ppPalette, NULL );
  537. }
  538. //-----------------------------------------------------------------------------
  539. // Name:
  540. // Desc:
  541. //-----------------------------------------------------------------------------
  542. HRESULT CLgDirectDrawDisplay::UpdateBounds()
  543. {
  544. if( m_bWindowed )
  545. {
  546. GetClientRect( m_hWnd, &m_rcWindow );
  547. ClientToScreen( m_hWnd, (POINT*)&m_rcWindow );
  548. ClientToScreen( m_hWnd, (POINT*)&m_rcWindow+1 );
  549. }
  550. else
  551. {
  552. SetRect( &m_rcWindow, 0, 0, GetSystemMetrics(SM_CXSCREEN),
  553. GetSystemMetrics(SM_CYSCREEN) );
  554. }
  555. return S_OK;
  556. }
  557. //-----------------------------------------------------------------------------
  558. // Name: CLgDirectDrawDisplay::InitClipper
  559. // Desc:
  560. //-----------------------------------------------------------------------------
  561. HRESULT CLgDirectDrawDisplay::InitClipper()
  562. {
  563. LPDIRECTDRAWCLIPPER pClipper;
  564. HRESULT hr;
  565. // Create a clipper when using GDI to draw on the primary surface
  566. if( FAILED( hr = m_pDD->CreateClipper( 0, &pClipper, NULL ) ) )
  567. return hr;
  568. pClipper->SetHWnd( 0, m_hWnd );
  569. if( FAILED( hr = m_pddsFrontBuffer->SetClipper( pClipper ) ) )
  570. return hr;
  571. // We can release the clipper now since g_pDDSPrimary
  572. // now maintains a ref count on the clipper
  573. SAFE_RELEASE( pClipper );
  574. return S_OK;
  575. }
  576. HRESULT CLgDirectDrawDisplay::RestoreAllSurfaces()
  577. {
  578. if( m_pDD )
  579. return E_INVALIDARG;
  580. HRESULT hr = m_pDD->RestoreAllSurfaces();
  581. if( FAILED(hr) )
  582. {
  583. if( m_pddsFrontBuffer )
  584. {
  585. hr = m_pddsFrontBuffer->Restore();
  586. if( FAILED(hr) )
  587. return hr;
  588. }
  589. if( m_pddsBackBuffer )
  590. {
  591. hr = m_pddsBackBuffer->Restore();
  592. if( FAILED(hr) )
  593. return hr;
  594. }
  595. if( m_pddsBackBufferLeft )
  596. {
  597. hr = m_pddsBackBufferLeft->Restore();
  598. if( FAILED(hr) )
  599. return hr;
  600. }
  601. }
  602. return S_OK;
  603. }
  604. //-----------------------------------------------------------------------------
  605. // Name:
  606. // Desc:
  607. //-----------------------------------------------------------------------------
  608. CLgDirectDrawSurface::CLgDirectDrawSurface()
  609. {
  610. m_pdds = NULL;
  611. m_bColorKeyed = NULL;
  612. }
  613. //-----------------------------------------------------------------------------
  614. // Name:
  615. // Desc:
  616. //-----------------------------------------------------------------------------
  617. CLgDirectDrawSurface::~CLgDirectDrawSurface()
  618. {
  619. SAFE_RELEASE( m_pdds );
  620. }
  621. //-----------------------------------------------------------------------------
  622. // Name:
  623. // Desc:
  624. //-----------------------------------------------------------------------------
  625. HRESULT CLgDirectDrawSurface::Create( LPDIRECTDRAWSURFACE7 pdds )
  626. {
  627. m_pdds = pdds;
  628. if( m_pdds )
  629. {
  630. m_pdds->AddRef();
  631. // Get the DDSURFACEDESC structure for this surface
  632. m_ddsd.dwSize = sizeof(m_ddsd);
  633. m_pdds->GetSurfaceDesc( &m_ddsd );
  634. }
  635. return S_OK;
  636. }
  637. //-----------------------------------------------------------------------------
  638. // Name:
  639. // Desc:
  640. //-----------------------------------------------------------------------------
  641. HRESULT CLgDirectDrawSurface::Create( LPDIRECTDRAW7 pDD, DDSURFACEDESC2* pddsd )
  642. {
  643. HRESULT hr;
  644. // Create the DDraw surface
  645. if( FAILED( hr = pDD->CreateSurface( pddsd, &m_pdds, NULL ) ) )
  646. return hr;
  647. // Prepare the DDSURFACEDESC structure
  648. m_ddsd.dwSize = sizeof(m_ddsd);
  649. // Get the DDSURFACEDESC structure for this surface
  650. m_pdds->GetSurfaceDesc( &m_ddsd );
  651. return S_OK;
  652. }
  653. //-----------------------------------------------------------------------------
  654. // Name:
  655. // Desc:
  656. //-----------------------------------------------------------------------------
  657. HRESULT CLgDirectDrawSurface::Destroy()
  658. {
  659. SAFE_RELEASE( m_pdds );
  660. return S_OK;
  661. }
  662. //-----------------------------------------------------------------------------
  663. // Name: CLgDirectDrawSurface::DrawBitmap()
  664. // Desc: Draws a bitmap over an entire DirectDrawSurface, stretching the
  665. // bitmap if nessasary
  666. //-----------------------------------------------------------------------------
  667. HRESULT CLgDirectDrawSurface::DrawBitmap( HBITMAP hBMP,
  668. DWORD dwBMPOriginX, DWORD dwBMPOriginY,
  669. DWORD dwBMPWidth, DWORD dwBMPHeight )
  670. {
  671. HDC hDCImage;
  672. HDC hDC;
  673. BITMAP bmp;
  674. DDSURFACEDESC2 ddsd;
  675. HRESULT hr;
  676. if( hBMP == NULL || m_pdds == NULL )
  677. return E_INVALIDARG;
  678. // Make sure this surface is restored.
  679. if( FAILED( hr = m_pdds->Restore() ) )
  680. return hr;
  681. // Get the surface.description
  682. ddsd.dwSize = sizeof(ddsd);
  683. m_pdds->GetSurfaceDesc( &ddsd );
  684. if( ddsd.ddpfPixelFormat.dwFlags == DDPF_FOURCC )
  685. return E_NOTIMPL;
  686. // Select bitmap into a memoryDC so we can use it.
  687. hDCImage = CreateCompatibleDC( NULL );
  688. if( NULL == hDCImage )
  689. return E_FAIL;
  690. SelectObject( hDCImage, hBMP );
  691. // Get size of the bitmap
  692. GetObject( hBMP, sizeof(bmp), &bmp );
  693. // Use the passed size, unless zero
  694. dwBMPWidth = ( dwBMPWidth == 0 ) ? bmp.bmWidth : dwBMPWidth;
  695. dwBMPHeight = ( dwBMPHeight == 0 ) ? bmp.bmHeight : dwBMPHeight;
  696. // Stretch the bitmap to cover this surface
  697. if( FAILED( hr = m_pdds->GetDC( &hDC ) ) )
  698. return hr;
  699. StretchBlt( hDC, 0, 0,
  700. ddsd.dwWidth, ddsd.dwHeight,
  701. hDCImage, dwBMPOriginX, dwBMPOriginY,
  702. dwBMPWidth, dwBMPHeight, SRCCOPY );
  703. if( FAILED( hr = m_pdds->ReleaseDC( hDC ) ) )
  704. return hr;
  705. DeleteDC( hDCImage );
  706. return S_OK;
  707. }
  708. //-----------------------------------------------------------------------------
  709. // Name: CLgDirectDrawSurface::DrawBitmap()
  710. // Desc: Draws a bitmap over an entire DirectDrawSurface, stretching the
  711. // bitmap if nessasary
  712. //-----------------------------------------------------------------------------
  713. HRESULT CLgDirectDrawSurface::DrawBitmap( CLgImageDIB *pImageDIB )
  714. {
  715. // HDC hDCImage;
  716. HDC hDC;
  717. // BITMAP bmp;
  718. DDSURFACEDESC2 ddsd;
  719. HRESULT hr;
  720. if( pImageDIB == NULL || m_pdds == NULL )
  721. return E_INVALIDARG;
  722. // Make sure this surface is restored.
  723. if( FAILED( hr = m_pdds->Restore() ) )
  724. return hr;
  725. // Get the surface.description
  726. ddsd.dwSize = sizeof(ddsd);
  727. m_pdds->GetSurfaceDesc( &ddsd );
  728. if( ddsd.ddpfPixelFormat.dwFlags == DDPF_FOURCC )
  729. return E_NOTIMPL;
  730. // Stretch the bitmap to cover this surface
  731. if( FAILED( hr = m_pdds->GetDC( &hDC ) ) )
  732. return hr;
  733. RECT rect = { 0, 0, ddsd.dwWidth, ddsd.dwHeight };
  734. pImageDIB->Draw( hDC, &rect, FALSE );
  735. if( FAILED( hr = m_pdds->ReleaseDC( hDC ) ) )
  736. return hr;
  737. /*
  738. // Select bitmap into a memoryDC so we can use it.
  739. hDCImage = CreateCompatibleDC( NULL );
  740. if( NULL == hDCImage )
  741. return E_FAIL;
  742. SelectObject( hDCImage, hBMP );
  743. // Get size of the bitmap
  744. GetObject( hBMP, sizeof(bmp), &bmp );
  745. // Use the passed size, unless zero
  746. dwBMPWidth = ( dwBMPWidth == 0 ) ? bmp.bmWidth : dwBMPWidth;
  747. dwBMPHeight = ( dwBMPHeight == 0 ) ? bmp.bmHeight : dwBMPHeight;
  748. // Stretch the bitmap to cover this surface
  749. if( FAILED( hr = m_pdds->GetDC( &hDC ) ) )
  750. return hr;
  751. StretchBlt( hDC, 0, 0,
  752. ddsd.dwWidth, ddsd.dwHeight,
  753. hDCImage, dwBMPOriginX, dwBMPOriginY,
  754. dwBMPWidth, dwBMPHeight, SRCCOPY );
  755. if( FAILED( hr = m_pdds->ReleaseDC( hDC ) ) )
  756. return hr;
  757. DeleteDC( hDCImage );
  758. */
  759. return S_OK;
  760. }
  761. //-----------------------------------------------------------------------------
  762. // Name: CLgDirectDrawSurface::DrawText()
  763. // Desc: Draws a text string on a DirectDraw surface using hFont or the default
  764. // GDI font if hFont is NULL.
  765. //-----------------------------------------------------------------------------
  766. HRESULT CLgDirectDrawSurface::DrawText( HFONT hFont, TCHAR* strText,
  767. DWORD dwOriginX, DWORD dwOriginY,
  768. COLORREF crBackground, COLORREF crForeground, BOOL bTransparent )
  769. {
  770. HDC hDC = NULL;
  771. HRESULT hr;
  772. if( m_pdds == NULL || strText == NULL )
  773. return E_INVALIDARG;
  774. // Make sure this surface is restored.
  775. if( FAILED( hr = m_pdds->Restore() ) )
  776. return hr;
  777. if( FAILED( hr = m_pdds->GetDC( &hDC ) ) )
  778. return hr;
  779. // Set the background and foreground color
  780. INT nBkColor = SetBkColor( hDC, crBackground );
  781. INT nTextColor = SetTextColor( hDC, crForeground );
  782. INT nBkMode = SetBkMode( hDC, bTransparent ? TRANSPARENT : OPAQUE );
  783. HFONT hOldFont = hFont ? (HFONT)SelectObject( hDC, hFont ) : NULL;
  784. // Use GDI to draw the text on the surface
  785. TextOut( hDC, dwOriginX, dwOriginY, strText, _tcslen(strText) );
  786. SetBkColor( hDC, nBkColor );
  787. SetTextColor( hDC, nTextColor );
  788. SetBkMode( hDC, nBkMode );
  789. if( hFont )
  790. SelectObject( hDC, hOldFont );
  791. if( FAILED( hr = m_pdds->ReleaseDC( hDC ) ) )
  792. return hr;
  793. return S_OK;
  794. }
  795. //-----------------------------------------------------------------------------
  796. // Name: CLgDirectDrawSurface::ReDrawBitmapOnSurface()
  797. // Desc: Load a bitmap from a file or resource into a DirectDraw surface.
  798. // normaly used to re-load a surface after a restore.
  799. //-----------------------------------------------------------------------------
  800. HRESULT CLgDirectDrawSurface::DrawBitmap( TCHAR* strBMP,
  801. DWORD dwDesiredWidth, DWORD dwDesiredHeight )
  802. {
  803. HBITMAP hBMP;
  804. HRESULT hr;
  805. if( m_pdds == NULL || strBMP == NULL )
  806. return E_INVALIDARG;
  807. // Try to load the bitmap as a resource, if that fails, try it as a file
  808. hBMP = (HBITMAP) LoadImage( GetModuleHandle(NULL), strBMP,
  809. IMAGE_BITMAP, dwDesiredWidth, dwDesiredHeight,
  810. LR_CREATEDIBSECTION );
  811. if( hBMP == NULL )
  812. {
  813. hBMP = (HBITMAP) LoadImage( NULL, strBMP, IMAGE_BITMAP,
  814. dwDesiredWidth, dwDesiredHeight,
  815. LR_LOADFROMFILE | LR_CREATEDIBSECTION );
  816. if( hBMP == NULL )
  817. return E_FAIL;
  818. }
  819. // Draw the bitmap on this surface
  820. if( FAILED( hr = DrawBitmap( hBMP, 0, 0, 0, 0 ) ) )
  821. {
  822. DeleteObject( hBMP );
  823. return hr;
  824. }
  825. DeleteObject( hBMP );
  826. return S_OK;
  827. }
  828. //-----------------------------------------------------------------------------
  829. // Name:
  830. // Desc:
  831. //-----------------------------------------------------------------------------
  832. HRESULT CLgDirectDrawSurface::SetColorKey( DWORD dwColorKey )
  833. {
  834. if( NULL == m_pdds )
  835. return E_POINTER;
  836. m_bColorKeyed = TRUE;
  837. DDCOLORKEY ddck;
  838. ddck.dwColorSpaceLowValue = ConvertGDIColor( dwColorKey );
  839. ddck.dwColorSpaceHighValue = ConvertGDIColor( dwColorKey );
  840. return m_pdds->SetColorKey( DDCKEY_SRCBLT, &ddck );
  841. }
  842. //-----------------------------------------------------------------------------
  843. // Name: CLgDirectDrawSurface::ConvertGDIColor()
  844. // Desc: Converts a GDI color (0x00bbggrr) into the equivalent color on a
  845. // DirectDrawSurface using its pixel format.
  846. //-----------------------------------------------------------------------------
  847. DWORD CLgDirectDrawSurface::ConvertGDIColor( COLORREF dwGDIColor )
  848. {
  849. if( m_pdds == NULL )
  850. return 0x00000000;
  851. COLORREF rgbT;
  852. HDC hdc;
  853. DWORD dw = CLR_INVALID;
  854. DDSURFACEDESC2 ddsd;
  855. HRESULT hr;
  856. // Use GDI SetPixel to color match for us
  857. if( dwGDIColor != CLR_INVALID && m_pdds->GetDC(&hdc) == DD_OK)
  858. {
  859. rgbT = GetPixel(hdc, 0, 0); // Save current pixel value
  860. SetPixel(hdc, 0, 0, dwGDIColor); // Set our value
  861. m_pdds->ReleaseDC(hdc);
  862. }
  863. // Now lock the surface so we can read back the converted color
  864. ddsd.dwSize = sizeof(ddsd);
  865. hr = m_pdds->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL );
  866. if( hr == DD_OK)
  867. {
  868. dw = *(DWORD *) ddsd.lpSurface;
  869. if( ddsd.ddpfPixelFormat.dwRGBBitCount < 32 ) // Mask it to bpp
  870. dw &= ( 1 << ddsd.ddpfPixelFormat.dwRGBBitCount ) - 1;
  871. m_pdds->Unlock(NULL);
  872. }
  873. // Now put the color that was there back.
  874. if( dwGDIColor != CLR_INVALID && m_pdds->GetDC(&hdc) == DD_OK )
  875. {
  876. SetPixel( hdc, 0, 0, rgbT );
  877. m_pdds->ReleaseDC(hdc);
  878. }
  879. return dw;
  880. }
  881. //-----------------------------------------------------------------------------
  882. // Name: CLgDirectDrawSurface::GetBitMaskInfo()
  883. // Desc: Returns the number of bits and the shift in the bit mask
  884. //-----------------------------------------------------------------------------
  885. HRESULT CLgDirectDrawSurface::GetBitMaskInfo( DWORD dwBitMask, DWORD* pdwShift, DWORD* pdwBits )
  886. {
  887. DWORD dwShift = 0;
  888. DWORD dwBits = 0;
  889. if( pdwShift == NULL || pdwBits == NULL )
  890. return E_INVALIDARG;
  891. if( dwBitMask )
  892. {
  893. while( (dwBitMask & 1) == 0 )
  894. {
  895. dwShift++;
  896. dwBitMask >>= 1;
  897. }
  898. }
  899. while( (dwBitMask & 1) != 0 )
  900. {
  901. dwBits++;
  902. dwBitMask >>= 1;
  903. }
  904. *pdwShift = dwShift;
  905. *pdwBits = dwBits;
  906. return S_OK;
  907. }
  908. HRESULT CLgDirectDrawSurface::Clear( DWORD dwColor )
  909. {
  910. if( NULL == m_pdds )
  911. return E_POINTER;
  912. // Erase the background
  913. DDBLTFX ddbltfx;
  914. ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
  915. ddbltfx.dwSize = sizeof(ddbltfx);
  916. ddbltfx.dwFillColor = dwColor;
  917. return m_pdds->Blt( NULL, NULL, NULL, DDBLT_COLORFILL, &ddbltfx );
  918. }