www.pudn.com > kcbusyprogress_demo.rar > ButtonCol.cpp
/****************************************************************************
* class : CButtonCol
* author : Peter Mares / kinkycode.com (gui@ch.co.za)
* base class : CButton (MFC)
* notes : This is a quick hack and not for public consumption
*
* Disclaimer : Its free, it feels good and its from South Africa :)
****************************************************************************/
#include "stdafx.h"
#include "BusyProgress.h"
#include "ButtonCol.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CButtonCol
CButtonCol::CButtonCol()
: m_colBkg( GetSysColor(COLOR_3DFACE) )
, m_colText( GetSysColor(COLOR_BTNTEXT) )
{
}
CButtonCol::~CButtonCol()
{
}
BEGIN_MESSAGE_MAP(CButtonCol, CButton)
//{{AFX_MSG_MAP(CButtonCol)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CButtonCol message handlers
void CButtonCol::PreSubclassWindow()
{
ModifyStyle(0, BS_OWNERDRAW);
CButton::PreSubclassWindow();
}
/////////////////////////////////////////////////////////////////////////////
void CButtonCol::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC dc;
CBrush nBrush, *pOldBrush = NULL;
dc.Attach(lpDIS->hDC);
// This code only works with buttons.
ASSERT(lpDIS->CtlType == ODT_BUTTON);
// Draw the button frame.
nBrush.CreateSolidBrush( m_colBkg );
pOldBrush = dc.SelectObject(&nBrush);
dc.Rectangle(&lpDIS->rcItem);
dc.SelectObject(pOldBrush);
nBrush.DeleteObject();
// Get the button's text.
CString strText;
GetWindowText(strText);
// Draw the button text using the text color red.
COLORREF colOldText = dc.SetTextColor(m_colText);
dc.DrawText(strText, &lpDIS->rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
dc.SetTextColor(colOldText);
dc.Detach();
}