GroupStatic.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. m_toggleCursorToHand = false;
  18. m_pFont = NULL;
  19. }
  20. CGroupStatic::~CGroupStatic()
  21. {
  22. }
  23. BEGIN_MESSAGE_MAP(CGroupStatic, CStatic)
  24. //{{AFX_MSG_MAP(CGroupStatic)
  25. ON_WM_SETCURSOR()
  26. //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CGroupStatic message handlers
  30. BOOL CGroupStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
  31. {
  32. #ifndef WIN32
  33. return CStatic::OnChildNotify(message, wParam, lParam, pLResult);
  34. #else
  35. // If not setting static control color, do default processing
  36. if( message != WM_CTLCOLORSTATIC )
  37. return CStatic::OnChildNotify(message, wParam, lParam, pLResult);
  38. HDC hdcChild = (HDC)wParam;
  39. // Set the foreground color
  40. ::SetTextColor( hdcChild, m_dwTextColor );
  41. // If a background color is pre-determined
  42. if(m_dwBkColor != -1)
  43. {
  44. ::SetBkMode(hdcChild, TRANSPARENT);
  45. ::SetBkColor(hdcChild, m_dwBkColor);
  46. m_brush.DeleteObject();
  47. m_brush.CreateSolidBrush(m_dwBkColor);
  48. *pLResult = (LRESULT)(m_brush.GetSafeHandle());
  49. }
  50. else
  51. {
  52. // Determine the current background color based on my parent window
  53. static COLORREF clrPrevValid = -1;
  54. HWND hParent = ::GetParent(m_hWnd);
  55. HDC hParentDc = ::GetDC(hParent);
  56. // Get the color based on the 0, 0 reference
  57. COLORREF clrParentBkground = ::GetPixel(hParentDc, 0, 0);
  58. ::ReleaseDC(hParent, hParentDc);
  59. // If found (not off of the screen or under another window)
  60. // set my current color to it
  61. if(clrParentBkground == -1)
  62. { clrParentBkground = clrPrevValid; }
  63. else
  64. { clrPrevValid = clrParentBkground; }
  65. // If either the current, or previous color found was not valid
  66. // allow to perform default processing
  67. if(clrParentBkground == -1)
  68. { return FALSE; }
  69. // Set the background mode to transparent
  70. ::SetBkMode(hdcChild, TRANSPARENT);
  71. // Set the background color and brush based on my parent's color
  72. ::SetBkColor(hdcChild, clrParentBkground);
  73. m_brush.DeleteObject();
  74. m_brush.CreateSolidBrush(clrParentBkground);
  75. *pLResult = (LRESULT)(m_brush.GetSafeHandle());
  76. }
  77. // Return TRUE to indicate that the message was handled
  78. return TRUE;
  79. #endif
  80. }
  81. /*************************************************************************
  82. *
  83. *************************************************************************/
  84. void CGroupStatic::SetFont( int nPointSize, LPCTSTR lpszFaceName, CDC* pDC )
  85. {
  86. // If a font has been allocated, delete it
  87. if( m_pFont )
  88. delete m_pFont;
  89. m_pFont = new CFont;
  90. // Create a font using the given attributes
  91. m_pFont->CreatePointFont( nPointSize, lpszFaceName, pDC );
  92. // Set the window's current font to the specified font
  93. CStatic::SetFont( m_pFont );
  94. }
  95. BOOL CGroupStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  96. {
  97. if (m_toggleCursorToHand)
  98. {
  99. HCURSOR h = ::LoadCursor(NULL, IDC_HAND);
  100. ::SetCursor(h);
  101. return TRUE;
  102. }
  103. return FALSE;
  104. }