GroupStatic.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // GroupStatic.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cp_main.h"
  5. #include "GroupStatic.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CGroupStatic
  13. CGroupStatic::CGroupStatic()
  14. {
  15. m_dwTextColor = 0;
  16. m_dwBkColor = RGB(255, 255, 255);
  17. }
  18. CGroupStatic::~CGroupStatic()
  19. {
  20. }
  21. BEGIN_MESSAGE_MAP(CGroupStatic, CStatic)
  22. //{{AFX_MSG_MAP(CGroupStatic)
  23. // NOTE - the ClassWizard will add and remove mapping macros here.
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CGroupStatic message handlers
  28. BOOL CGroupStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  29. {
  30. #ifndef WIN32
  31. return CStatic::OnChildNotify(message, wParam, lParam, pLResult);
  32. #else
  33. // If not setting static control color, do default processing
  34. if( message != WM_CTLCOLORSTATIC )
  35. return CStatic::OnChildNotify(message, wParam, lParam, pLResult);
  36. HDC hdcChild = (HDC)wParam;
  37. // Set the foreground color
  38. ::SetTextColor( hdcChild, m_dwTextColor );
  39. // If a background color is pre-determined
  40. if(m_dwBkColor != -1)
  41. {
  42. ::SetBkMode(hdcChild, TRANSPARENT);
  43. ::SetBkColor(hdcChild, m_dwBkColor);
  44. m_brush.DeleteObject();
  45. m_brush.CreateSolidBrush(m_dwBkColor);
  46. *pLResult = (LRESULT)(m_brush.GetSafeHandle());
  47. }
  48. else
  49. {
  50. // Determine the current background color based on my parent window
  51. static COLORREF clrPrevValid = -1;
  52. HWND hParent = ::GetParent(m_hWnd);
  53. HDC hParentDc = ::GetDC(hParent);
  54. // Get the color based on the 0, 0 reference
  55. COLORREF clrParentBkground = ::GetPixel(hParentDc, 0, 0);
  56. ::ReleaseDC(hParent, hParentDc);
  57. // If found (not off of the screen or under another window)
  58. // set my current color to it
  59. if(clrParentBkground == -1)
  60. { clrParentBkground = clrPrevValid; }
  61. else
  62. { clrPrevValid = clrParentBkground; }
  63. // If either the current, or previous color found was not valid
  64. // allow to perform default processing
  65. if(clrParentBkground == -1)
  66. { return FALSE; }
  67. // Set the background mode to transparent
  68. ::SetBkMode(hdcChild, TRANSPARENT);
  69. // Set the background color and brush based on my parent's color
  70. ::SetBkColor(hdcChild, clrParentBkground);
  71. m_brush.DeleteObject();
  72. m_brush.CreateSolidBrush(clrParentBkground);
  73. *pLResult = (LRESULT)(m_brush.GetSafeHandle());
  74. }
  75. // Return TRUE to indicate that the message was handled
  76. return TRUE;
  77. #endif
  78. }
  79. /*************************************************************************
  80. *
  81. *************************************************************************/
  82. void CGroupStatic::SetFont( int nPointSize, LPCTSTR lpszFaceName, CDC* pDC )
  83. {
  84. // If a font has been allocated, delete it
  85. if( m_pFont )
  86. delete m_pFont;
  87. m_pFont = new CFont;
  88. // Create a font using the given attributes
  89. m_pFont->CreatePointFont( nPointSize, lpszFaceName, pDC );
  90. // Set the window's current font to the specified font
  91. CStatic::SetFont( m_pFont );
  92. }