SkinStatic.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SkinStatic.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. //#include "dialog.h"
  5. #include "SkinStatic.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSkinStatic
  13. CSkinStatic::CSkinStatic()
  14. {
  15. m_nX=0;
  16. m_nY=0;
  17. m_strText="";
  18. }
  19. CSkinStatic::~CSkinStatic()
  20. {
  21. }
  22. BEGIN_MESSAGE_MAP(CSkinStatic, CStatic)
  23. //{{AFX_MSG_MAP(CSkinStatic)
  24. ON_WM_PAINT()
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CSkinStatic message handlers
  29. void CSkinStatic::LoadBitmap(LPCTSTR szImagePath)
  30. {
  31. m_bmpStatic.LoadImage(szImagePath);
  32. }
  33. void CSkinStatic::OnPaint()
  34. {
  35. CPaintDC dc(this); // device context for painting
  36. CRect rcClient;
  37. GetClientRect(&rcClient);
  38. CEnBitmap bmp;
  39. if (m_bmpStatic.m_hObject !=0)
  40. m_bmpStatic.ExtendDraw(&dc,rcClient,m_nX,m_nY);
  41. CRect rc=rcClient;
  42. rc.left =m_nTextStart;
  43. DrawText(&dc,rc,m_strText);
  44. }
  45. BOOL CSkinStatic::OnCommand(WPARAM wParam, LPARAM lParam)
  46. {
  47. //GetParent()->SendMessage(WM_COMMAND,wParam,lParam); // -Ô­;
  48. GetParent()->PostMessage(WM_COMMAND,wParam,lParam); // -¸Ä.2014-02-19;
  49. TRACE("-------------------------0.0----------------------------");
  50. return CStatic::OnCommand(wParam, lParam);
  51. }
  52. void CSkinStatic::SetText(CString strText, int nStart,COLORREF cr)
  53. {
  54. m_strText=strText;
  55. m_nTextStart=nStart;
  56. m_crText=cr;
  57. }
  58. BOOL CSkinStatic::DrawText(CDC *pDC,CRect rc ,CString strText)
  59. {
  60. CRect r;
  61. CString str;
  62. CRect rcButton;
  63. if (strText.GetLength() )
  64. {
  65. CFont *ofont;
  66. ofont = pDC->SelectObject( GetParent()->GetFont() );
  67. pDC->SetTextColor(m_crText);
  68. pDC->SetBkMode(TRANSPARENT);
  69. pDC->DrawText( strText, rc, DT_SINGLELINE | DT_VCENTER );
  70. pDC->SelectObject(ofont);
  71. }
  72. return TRUE;
  73. }