Source code of Windows XP (NT5)
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.

81 lines
2.3 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. InitializeCriticalSection(&_csBitmapCache);
  13. }
  14. //---------------------------------------------------------------------------
  15. CBitmapCache::~CBitmapCache()
  16. {
  17. if (_hBitmap)
  18. {
  19. DeleteObject(_hBitmap);
  20. }
  21. DeleteCriticalSection(&_csBitmapCache);
  22. }
  23. //---------------------------------------------------------------------------
  24. HBITMAP CBitmapCache::AcquireBitmap(HDC hdc, int iWidth, int iHeight)
  25. {
  26. EnterCriticalSection(&_csBitmapCache);
  27. if ((iWidth > _iWidth) || (iHeight > _iHeight) || (! _hBitmap))
  28. {
  29. if (_hBitmap)
  30. {
  31. DeleteObject(_hBitmap);
  32. _hBitmap = NULL;
  33. _iWidth = 0;
  34. _iHeight = 0;
  35. }
  36. //---- create new bitmap & hdc ----
  37. struct {
  38. BITMAPINFOHEADER bmih;
  39. ULONG masks[3];
  40. } bmi;
  41. bmi.bmih.biSize = sizeof(bmi.bmih);
  42. bmi.bmih.biWidth = iWidth;
  43. bmi.bmih.biHeight = iHeight;
  44. bmi.bmih.biPlanes = 1;
  45. bmi.bmih.biBitCount = 32;
  46. bmi.bmih.biCompression = BI_BITFIELDS;
  47. bmi.bmih.biSizeImage = 0;
  48. bmi.bmih.biXPelsPerMeter = 0;
  49. bmi.bmih.biYPelsPerMeter = 0;
  50. bmi.bmih.biClrUsed = 3;
  51. bmi.bmih.biClrImportant = 0;
  52. bmi.masks[0] = 0xff0000; // red
  53. bmi.masks[1] = 0x00ff00; // green
  54. bmi.masks[2] = 0x0000ff; // blue
  55. _hBitmap = CreateDIBitmap(hdc, &bmi.bmih, CBM_CREATEDIB , NULL, (BITMAPINFO*)&bmi.bmih,
  56. DIB_RGB_COLORS);
  57. if (_hBitmap)
  58. {
  59. _iWidth = iWidth;
  60. _iHeight = iHeight;
  61. }
  62. }
  63. return _hBitmap;
  64. }
  65. //---------------------------------------------------------------------------
  66. void CBitmapCache::ReturnBitmap()
  67. {
  68. LeaveCriticalSection(&_csBitmapCache);
  69. }
  70. //---------------------------------------------------------------------------