// ColorStatic.cpp : implementation file
//

#include "stdafx.h"
#include "ColorStatic.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CColorStatic

CColorStatic::CColorStatic()
{
        m_crBkColor = ::GetSysColor(COLOR_3DFACE); // Initializing the Background Color to the system face color.
        m_crTextColor = BLACK; // Initializing the text to Black
        m_brBkgnd.CreateSolidBrush(m_crBkColor); // Create the Brush Color for the Background.
}

CColorStatic::~CColorStatic()
{
}


BEGIN_MESSAGE_MAP(CColorStatic, CStatic)
        //{{AFX_MSG_MAP(CColorStatic)
        ON_WM_CTLCOLOR_REFLECT()
        ON_WM_ERASEBKGND()
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorStatic message handlers

HBRUSH CColorStatic::CtlColor(CDC* pDC, UINT nCtlColor)
{
        HBRUSH hbr;
        hbr = (HBRUSH)m_brBkgnd; // Passing a Handle to the Brush
        pDC->SetBkColor(m_crBkColor); // Setting the Color of the Text Background to the one passed by the Dialog
        pDC->SetTextColor(m_crTextColor); // Setting the Text Color to the one Passed by the Dialog

        if (nCtlColor)       // To get rid of compiler warning
        nCtlColor += 0;

        return hbr;

}

void CColorStatic::SetBkColor(COLORREF crColor)
{
        m_crBkColor = crColor; // Passing the value passed by the dialog to the member varaible for Backgound Color
        m_brBkgnd.DeleteObject(); // Deleting any Previous Brush Colors if any existed.
        m_brBkgnd.CreateSolidBrush(crColor); // Creating the Brush Color For the Static Text Background
        RedrawWindow();
}

void CColorStatic::SetTextColor(COLORREF crColor)
{
        m_crTextColor = crColor; // Passing the value passed by the dialog to the member varaible for Text Color
        RedrawWindow();
}

BOOL CColorStatic::OnEraseBkgnd(CDC* pDC)
{
        HBRUSH hbr;
        hbr = (HBRUSH)m_brBkgnd; // Passing a Handle to the Brush
        pDC->SetBkColor(m_crBkColor); // Setting the Color of the Text Background to the one passed by the Dialog
        pDC->SetTextColor(m_crTextColor); // Setting the Text Color to the one Passed by the Dialog

        return CStatic::OnEraseBkgnd(pDC);
}
