SkinStatic.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "stdafx.h"
  2. #include "SkinStatic.h"
  3. #ifdef _DEBUG
  4. #define new DEBUG_NEW
  5. #undef THIS_FILE
  6. static char THIS_FILE[] = __FILE__;
  7. #endif
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CSkinStatic
  10. CSkinStatic::CSkinStatic()
  11. {
  12. m_nX=0;
  13. m_nY=0;
  14. m_strText="";
  15. m_pFont = NULL;
  16. //m_pFont.CreateFont(
  17. // 15, // nHeight
  18. // 0, // nWidth
  19. // 0, // nEscapement
  20. // 0, // nOrientation
  21. // FW_BOLD, // nWeight
  22. // FALSE, // bItalic
  23. // FALSE, // bUnderline
  24. // 0, // cStrikeOut
  25. // ANSI_CHARSET, // nCharSet
  26. // OUT_DEFAULT_PRECIS, // nOutPrecision
  27. // CLIP_DEFAULT_PRECIS, // nClipPrecision
  28. // DEFAULT_QUALITY, // nQuality
  29. // DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  30. // _T("Arial")); // lpszFacename
  31. }
  32. CSkinStatic::~CSkinStatic()
  33. {
  34. }
  35. BEGIN_MESSAGE_MAP(CSkinStatic, CStatic)
  36. //{{AFX_MSG_MAP(CSkinStatic)
  37. ON_WM_PAINT()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CSkinStatic message handlers
  42. void CSkinStatic::LoadBitmap(LPCTSTR szImagePath)
  43. {
  44. m_bmpStatic.LoadImage(szImagePath);
  45. }
  46. void CSkinStatic::OnPaint()
  47. {
  48. CPaintDC dc(this); // device context for painting
  49. CRect rcClient;
  50. GetClientRect(&rcClient);
  51. if (m_bmpStatic.m_hObject !=0)
  52. m_bmpStatic.ExtendDraw(&dc,rcClient,m_nX,m_nY);
  53. CRect rc = rcClient;
  54. rc.left = m_nTextStart;
  55. DrawText(&dc, rc, m_strText);
  56. }
  57. BOOL CSkinStatic::OnCommand(WPARAM wParam, LPARAM lParam)
  58. {
  59. GetParent()->SendMessage(WM_COMMAND,wParam,lParam);
  60. return CStatic::OnCommand(wParam, lParam);
  61. }
  62. void CSkinStatic::SetText(CString strText, int nStart, COLORREF cr)
  63. {
  64. m_strText = strText;
  65. m_nTextStart = nStart;
  66. m_crText = cr;
  67. Invalidate();
  68. }
  69. BOOL CSkinStatic::DrawText(CDC *pDC,CRect rc ,CString strText)
  70. {
  71. CRect r;
  72. CString str;
  73. CRect rcButton;
  74. if (strText.GetLength() )
  75. {
  76. if(m_pFont == NULL)
  77. m_pFont = GetParent()->GetFont();
  78. pDC->SelectObject(m_pFont);
  79. pDC->SetTextColor(m_crText);
  80. pDC->SetBkMode(TRANSPARENT);
  81. pDC->DrawText( strText, rc, DT_SINGLELINE | DT_VCENTER );
  82. }
  83. return TRUE;
  84. }
  85. void CSkinStatic::Redraw(CDC *pDC)
  86. {
  87. CRect rc = GetRectInParent();
  88. if (m_bmpStatic.m_hObject !=0)
  89. m_bmpStatic.ExtendDraw(pDC,rc,m_nX,m_nY);
  90. CRect rcText = rc;
  91. rcText.left += m_nTextStart;
  92. DrawText(pDC,rcText,m_strText);
  93. }
  94. CRect CSkinStatic::GetRectInParent()
  95. {
  96. CRect rcWindowParent;
  97. GetParent()->GetWindowRect(rcWindowParent);//client
  98. CRect rcWindow;
  99. GetWindowRect(&rcWindow);
  100. CRect rect;
  101. rect.left = rcWindow.left-rcWindowParent.left;
  102. rect.top = rcWindow.top-rcWindowParent.top;
  103. rect.right = rcWindow.right-rcWindowParent.left;
  104. rect.bottom = rcWindow.bottom-rcWindowParent.top;
  105. return rect;
  106. }