我写的一个自绘按钮,当时就是想做成XP按钮效果,后来配合自己程序修改了一下颜色:
#if !defined(AFX_BUTTONEX_H__F175FCFD_FE1A_44CF_9AA1_DD92173EC685__INCLUDED_)
#define AFX_BUTTONEX_H__F175FCFD_FE1A_44CF_9AA1_DD92173EC685__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ButtonEx.h : header file
///////////////////////////////////////////////////////////////////////////////
// CButtonEx windowclass CButtonEx : public CButton
{
// Construction
public:
CButtonEx();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CButtonEx)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL// Implementation
public:
void SetButtonColor(COLORREF colButton){m_colButton=colButton;}
void SetEraseColor(COLORREF colErase){m_colErase=colErase;}
virtual ~CButtonEx(); // Generated message map functions
protected:
//{{AFX_MSG(CButtonEx)
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private: COLORREF m_colButton;
COLORREF m_colErase;};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_BUTTONEX_H__F175FCFD_FE1A_44CF_9AA1_DD92173EC685__INCLUDED_)////////////////////////////////////////////////////////////////////// ButtonEx.cpp : implementation file
//#include "stdafx.h"
#include "ButtonEx.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CButtonExCButtonEx::CButtonEx()
{
m_colButton=m_colErase=0xF7F3F7;
}CButtonEx::~CButtonEx()
{
}
BEGIN_MESSAGE_MAP(CButtonEx, CButton)
//{{AFX_MSG_MAP(CButtonEx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CButtonEx message handlersvoid CButtonEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect=lpDrawItemStruct->rcItem;
COLORREF colOutLine,colInLine,colHighLine,colDarkLine,colText;
CString strCaption;
GetWindowText(strCaption);
UINT state=lpDrawItemStruct->itemState;
if(state&ODS_SELECTED)
{
//Button is selected
colOutLine=m_colErase;
colInLine=0x84867B;
colHighLine=0xB5BEBD;
colDarkLine=0xB5BEBD;
colText=0x000000;
}
else if(state&ODS_DISABLED)
{
//Button is disabled
colOutLine=0xC6C3C6;
colInLine=m_colButton;
colHighLine=0xFFFFFF;
colDarkLine=m_colButton;
colText=0xB5BEBD;
}
else
{
//Normal button
colOutLine=0x84867B;
colInLine=0xB5BEBD;
colHighLine=0xFFFFFF;
colDarkLine=m_colButton;
colText=0x000000;
}

//Draw Button Eadge
pDC->Draw3dRect(rect,colOutLine,colOutLine);
rect.DeflateRect(1,1);
pDC->Draw3dRect(rect,colInLine,colInLine);
rect.DeflateRect(1,1);
pDC->Draw3dRect(rect,colHighLine,colDarkLine);
//Draw Button Face
pDC->SetBkColor(0xffffff);
pDC->SetTextColor(m_colButton);
pDC->FillRect(rect,pDC->GetHalftoneBrush());
//Draw Caption
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(colText);
pDC->DrawText(strCaption,&lpDrawItemStruct->rcItem,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
//Release 
ReleaseDC(pDC);

}