SkinStatic.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. return CStatic::OnCommand(wParam, lParam);
  49. }
  50. void CSkinStatic::SetText(CString strText, int nStart,COLORREF cr)
  51. {
  52. m_strText=strText;
  53. m_nTextStart=nStart;
  54. m_crText=cr;
  55. }
  56. BOOL CSkinStatic::DrawText(CDC *pDC,CRect rc ,CString strText)
  57. {
  58. CRect r;
  59. CString str;
  60. CRect rcButton;
  61. if (strText.GetLength() )
  62. {
  63. CFont *ofont;
  64. ofont = pDC->SelectObject( GetParent()->GetFont() );
  65. pDC->SetTextColor(m_crText);
  66. pDC->SetBkMode(TRANSPARENT);
  67. pDC->DrawText( strText, rc, DT_SINGLELINE | DT_VCENTER );
  68. pDC->SelectObject(ofont);
  69. }
  70. return TRUE;
  71. }