ShowPicStatic2.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "stdafx.h"
  2. #include "ylgl.h"
  3. #include "ShowPicStatic2.h"
  4. #include "PreviewDlg.h"
  5. #ifdef _DEBUG
  6. //#define new DEBUG_NEW //wangwenbin modify 2014-04-27
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. Bitmap *g_pImgStaBuf=NULL;
  11. ShowPicStatic2::ShowPicStatic2()
  12. {
  13. m_pImageBk=NULL;
  14. m_nFrameMode=-1;
  15. m_bStretch=1;
  16. if(g_pImgStaBuf==NULL)g_pImgStaBuf=new Bitmap(1500, 1500, PixelFormat24bppRGB);
  17. }
  18. ShowPicStatic2::~ShowPicStatic2()
  19. {
  20. ReleaseData();
  21. }
  22. BEGIN_MESSAGE_MAP(ShowPicStatic2, CStatic)
  23. ON_WM_PAINT()
  24. ON_WM_SETCURSOR()
  25. ON_WM_ERASEBKGND()
  26. END_MESSAGE_MAP()
  27. void ShowPicStatic2::OnPaint()
  28. {
  29. CPaintDC dc(this);
  30. try
  31. {
  32. CRect rc;
  33. GetClientRect(&rc);
  34. Graphics bufgraph(g_pImgStaBuf);
  35. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  36. bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pBlackBrush, destinationRect);
  37. /* if(m_nFrameMode==1)//蓝框蓝边
  38. {
  39. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  40. bufgraph.FillRectangle(g_pBlueBrush2, destinationRect);
  41. rc.DeflateRect (1,1);
  42. Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
  43. bufgraph.FillRectangle(g_pBlueBrush, destinationRect2);
  44. }
  45. else if(m_nFrameMode==2)//蓝框黑边
  46. {
  47. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  48. bufgraph.FillRectangle(g_pBlackBrush, destinationRect);
  49. rc.DeflateRect (1,1);
  50. Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
  51. bufgraph.FillRectangle(g_pBlueBrush, destinationRect2);
  52. }
  53. else if(m_nFrameMode==3)//白框灰边
  54. {
  55. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  56. bufgraph.FillRectangle(g_pWhiteBrush2, destinationRect);
  57. rc.DeflateRect (2,2);
  58. Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
  59. bufgraph.FillRectangle(g_pWhiteBrush, destinationRect2);
  60. }*/
  61. if(m_nFrameMode==100)//蓝框红边,代表选中状态
  62. {
  63. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  64. bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pRedBrush, destinationRect);
  65. rc.DeflateRect (1,1);
  66. Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
  67. bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pBlackBrush, destinationRect2);
  68. }
  69. if(m_pImageBk)
  70. {
  71. int width=m_pImageBk->GetWidth();
  72. int height=m_pImageBk->GetHeight();
  73. if(m_bStretch)
  74. RectFitDes(width, height, rc);
  75. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  76. bufgraph.DrawImage(m_pImageBk, destinationRect, 0,0,width,height,UnitPixel);
  77. }
  78. {
  79. Graphics dcgraph(dc.GetSafeHdc());
  80. GetClientRect(&rc);
  81. Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
  82. dcgraph.DrawImage(g_pImgStaBuf, destinationRect, 0,0,rc.Width (), rc.Height (),UnitPixel);
  83. }
  84. }
  85. catch(...)
  86. {
  87. }
  88. }
  89. void ShowPicStatic2::ReleaseData()
  90. {
  91. try
  92. {
  93. if(m_pImageBk)
  94. {
  95. delete m_pImageBk;
  96. m_pImageBk=NULL;
  97. }
  98. }
  99. catch(...)
  100. {
  101. }
  102. }
  103. BOOL ShowPicStatic2::OnEraseBkgnd(CDC* pDC)
  104. {
  105. return TRUE;
  106. }
  107. void ShowPicStatic2::SetPicPath(CString pathname)
  108. {
  109. try
  110. {
  111. ReleaseData();
  112. if(!::PathFileExists (pathname))
  113. {
  114. Invalidate();
  115. return;
  116. }
  117. pathname.MakeLower ();
  118. if(pathname.Right (3)=="jpg")
  119. {
  120. LoadImageFromBuf(&m_pImageBk, pathname);
  121. }
  122. Invalidate();
  123. }
  124. catch(...)
  125. {
  126. }
  127. }
  128. extern HCURSOR g_cursorhand;
  129. BOOL ShowPicStatic2::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  130. {
  131. ::SetCursor(g_cursorhand);
  132. return TRUE;
  133. }