Leaked source code of windows server 2003
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.

85 lines
2.5 KiB

  1. //---------------------------------------------------------------------------
  2. // BmpCache.cpp - single bitmap/hdc cache object for uxtheme
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "BmpCache.h"
  6. //---------------------------------------------------------------------------
  7. CBitmapCache::CBitmapCache()
  8. {
  9. _hBitmap = NULL;
  10. _iWidth = 0;
  11. _iHeight = 0;
  12. ZeroMemory(&_csBitmapCache, sizeof(_csBitmapCache));
  13. if( !InitializeCriticalSectionAndSpinCount(&_csBitmapCache, 0) )
  14. {
  15. ASSERT(!VALID_CRITICALSECTION(&_csBitmapCache));
  16. }
  17. }
  18. //---------------------------------------------------------------------------
  19. CBitmapCache::~CBitmapCache()
  20. {
  21. if (_hBitmap)
  22. {
  23. DeleteObject(_hBitmap);
  24. }
  25. SAFE_DELETECRITICALSECTION(&_csBitmapCache);
  26. }
  27. //---------------------------------------------------------------------------
  28. HBITMAP CBitmapCache::AcquireBitmap(HDC hdc, int iWidth, int iHeight)
  29. {
  30. SAFE_ENTERCRITICALSECTION(&_csBitmapCache);
  31. if ((iWidth > _iWidth) || (iHeight > _iHeight) || (! _hBitmap))
  32. {
  33. if (_hBitmap)
  34. {
  35. DeleteObject(_hBitmap);
  36. _hBitmap = NULL;
  37. _iWidth = 0;
  38. _iHeight = 0;
  39. }
  40. //---- create new bitmap & hdc ----
  41. struct {
  42. BITMAPINFOHEADER bmih;
  43. ULONG masks[3];
  44. } bmi;
  45. bmi.bmih.biSize = sizeof(bmi.bmih);
  46. bmi.bmih.biWidth = iWidth;
  47. bmi.bmih.biHeight = iHeight;
  48. bmi.bmih.biPlanes = 1;
  49. bmi.bmih.biBitCount = 32;
  50. bmi.bmih.biCompression = BI_BITFIELDS;
  51. bmi.bmih.biSizeImage = 0;
  52. bmi.bmih.biXPelsPerMeter = 0;
  53. bmi.bmih.biYPelsPerMeter = 0;
  54. bmi.bmih.biClrUsed = 3;
  55. bmi.bmih.biClrImportant = 0;
  56. bmi.masks[0] = 0xff0000; // red
  57. bmi.masks[1] = 0x00ff00; // green
  58. bmi.masks[2] = 0x0000ff; // blue
  59. _hBitmap = CreateDIBitmap(hdc, &bmi.bmih, CBM_CREATEDIB , NULL, (BITMAPINFO*)&bmi.bmih,
  60. DIB_RGB_COLORS);
  61. if (_hBitmap)
  62. {
  63. _iWidth = iWidth;
  64. _iHeight = iHeight;
  65. }
  66. }
  67. return _hBitmap;
  68. }
  69. //---------------------------------------------------------------------------
  70. void CBitmapCache::ReturnBitmap()
  71. {
  72. SAFE_LEAVECRITICALSECTION(&_csBitmapCache);
  73. }
  74. //---------------------------------------------------------------------------