/win32/shellext/TortoiseIconBitmap.cpp

https://bitbucket.org/tortoisehg/hgtk/ · C++ · 45 lines · 33 code · 12 blank · 0 comment · 5 complexity · ecce9db9bc2f2773c5d2e9fcf3cd55e6 MD5 · raw file

  1. #include "stdafx.h"
  2. #include "TortoiseUtils.h"
  3. #include <map>
  4. #include "IconBitmapUtils.h"
  5. HBITMAP GetTortoiseIconBitmap(const std::string& iconname)
  6. {
  7. IconBitmapUtils bmpUtils;
  8. typedef std::map<std::string, HBITMAP> BitmapCacheT;
  9. static BitmapCacheT bmpcache_;
  10. BitmapCacheT::const_iterator i = bmpcache_.find(iconname);
  11. if (i != bmpcache_.end())
  12. return i->second;
  13. if (bmpcache_.size() > 200)
  14. {
  15. TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: too many bitmaps in cache");
  16. return 0;
  17. }
  18. HICON hIcon = GetTortoiseIcon(iconname);
  19. if (!hIcon)
  20. return 0;
  21. HBITMAP hBmp = bmpUtils.IconToBitmapPARGB32(hIcon);
  22. if (!hBmp)
  23. {
  24. TDEBUG_TRACE("**** GetTortoiseIconBitmap: error: something wrong in bmpUtils.ConvertToPARGB32(hIcon)");
  25. return 0;
  26. }
  27. bmpcache_[iconname] = hBmp;
  28. TDEBUG_TRACE(
  29. "GetTortoiseIconBitmap: added '" << iconname << "' to bmpcache_"
  30. " (" << bmpcache_.size() << " bitmaps in cache)"
  31. );
  32. return hBmp;
  33. }