ColourEdit.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * ColourEdit.cpp
  3. * --------------
  4. * Purpose: Implementation of a coloured edit UI item.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "ColourEdit.h"
  11. OPENMPT_NAMESPACE_BEGIN
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CColourEdit
  14. CColourEdit::CColourEdit()
  15. {
  16. m_crText = RGB(0, 0, 0); //default text color
  17. }
  18. CColourEdit::~CColourEdit()
  19. {
  20. if(m_brBackGnd.GetSafeHandle()) //delete brush
  21. m_brBackGnd.DeleteObject();
  22. }
  23. BEGIN_MESSAGE_MAP(CColourEdit, CEdit)
  24. ON_WM_CTLCOLOR_REFLECT()
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CColourEdit message handlers
  28. HBRUSH CColourEdit::CtlColor(CDC *pDC, UINT nCtlColor)
  29. {
  30. MPT_UNREFERENCED_PARAMETER(nCtlColor);
  31. pDC->SetTextColor(m_crText); //set text color
  32. pDC->SetBkColor(m_crBackGnd); //set the text's background color
  33. return m_brBackGnd; //return the brush used for background - this sets control background
  34. }
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Implementation
  37. void CColourEdit::SetBackColor(COLORREF rgb)
  38. {
  39. m_crBackGnd = rgb; //set background color ref (used for text's background)
  40. if(m_brBackGnd.GetSafeHandle()) //free brush
  41. m_brBackGnd.DeleteObject();
  42. m_brBackGnd.CreateSolidBrush(rgb); //set brush to new color
  43. Invalidate(TRUE); //redraw
  44. }
  45. void CColourEdit::SetTextColor(COLORREF rgb)
  46. {
  47. m_crText = rgb; // set text color ref
  48. Invalidate(TRUE); // redraw
  49. }
  50. OPENMPT_NAMESPACE_END