SkinStatic.cpp 3.1 KB

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