ShowPicStatic2.cpp 3.9 KB

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