GdiImageDrawer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "stdafx.h"
  2. #include "GdiImageDrawer.h"
  3. #include "MemDC.h"
  4. #include "CP_Main.h"
  5. CGdiImageDrawer::CGdiImageDrawer()
  6. {
  7. m_pStdImage = NULL;
  8. }
  9. CGdiImageDrawer::~CGdiImageDrawer()
  10. {
  11. delete m_pStdImage;
  12. }
  13. BOOL CGdiImageDrawer::LoadStdImage(UINT id, LPCTSTR pType)
  14. {
  15. m_pStdImage = new CGdiPlusBitmapResource;
  16. return m_pStdImage->Load(id, pType);
  17. }
  18. BOOL CGdiImageDrawer::LoadStdImageDPI(UINT id96, UINT id120, UINT id144, UINT id192, LPCTSTR pType)
  19. {
  20. BOOL ret = FALSE;
  21. if (theApp.m_metrics.GetDPIX() >= 192)
  22. {
  23. ret = LoadStdImage(id192, pType);
  24. }
  25. else if (theApp.m_metrics.GetDPIX() >= 144)
  26. {
  27. ret = LoadStdImage(id144, pType);
  28. }
  29. else if (theApp.m_metrics.GetDPIX() >= 120)
  30. {
  31. ret = LoadStdImage(id120, pType);
  32. }
  33. else
  34. {
  35. ret = LoadStdImage(id96, pType);
  36. }
  37. return ret;
  38. }
  39. void CGdiImageDrawer::Draw(CDC* pScreenDC, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown)
  40. {
  41. int width = m_pStdImage->m_pBitmap->GetWidth();
  42. int height = m_pStdImage->m_pBitmap->GetHeight();
  43. CRect rectWithBorder(posX, posY, posX + width, posY + height);
  44. int two = theApp.m_metrics.ScaleX(2);
  45. rectWithBorder.InflateRect(two, two, two, two);
  46. CDC dcBk;
  47. CBitmap bmp;
  48. CClientDC clDC(pWnd);
  49. //Copy the background over the entire area
  50. dcBk.CreateCompatibleDC(&clDC);
  51. bmp.CreateCompatibleBitmap(&clDC, 1, 1);
  52. dcBk.SelectObject(&bmp);
  53. dcBk.BitBlt(0, 0, 1, 1, &clDC, rectWithBorder.left-1, rectWithBorder.top, SRCCOPY);
  54. bmp.DeleteObject();
  55. //pScreenDC->StretchBlt(rectWithBorder.left, rectWithBorder.top, rectWithBorder.Width(), rectWithBorder.Height(), &dcBk, 0, 0, 1, 1, SRCCOPY);
  56. //Draw the png file
  57. if (mouseDown)
  58. {
  59. int one = theApp.m_metrics.ScaleX(1);
  60. posX += one;
  61. posY += one;
  62. }
  63. Gdiplus::Graphics graphics(pScreenDC->m_hDC);
  64. graphics.DrawImage(*m_pStdImage, posX, posY, width, height);
  65. //If we are hoving over then draw the border
  66. if(mouseHover && mouseDown == false)
  67. {
  68. pScreenDC->Draw3dRect(rectWithBorder, RGB(255, 255, 255), RGB(255, 255, 255));
  69. }
  70. }