/*这个是.h文件*/
#if !defined(AFX_BMPBUTTON_H__31EF914C_A839_441A_8FB8_846E71DB1F99__INCLUDED_)
#define AFX_BMPBUTTON_H__31EF914C_A839_441A_8FB8_846E71DB1F99__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000class BmpButton:public CButton
{
public:
BmpButton();
virtual ~BmpButton();
public:
// Bitmaps for image display
CBitmap m_Up, m_Down, m_Focus, m_Disabled;
// Bitmap height and width information
int m_ImageWidth, m_ImageHeight;
// Flag for image on left or right
BOOL m_ImageOnLeft;public: void SetBitmap(CString& strPath);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg virtual void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg  BOOL OnEraseBkgnd(CDC* pDC);
protected:
//{{AFX_MSG(CBmpButton)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};
#endif
/*这个是Cpp文件*/
#include "stdafx.h"
#include "BmpButton.h"
//IMPLEMENT_DYNCREATE(BmpButton, CButton)
//BEGIN_MESSAGE_MAP(BmpButton, CButton)//END_MESSAGE_MAP()#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endifBEGIN_MESSAGE_MAP(BmpButton, CButton)
//{{AFX_MSG_MAP(CBmpButton)

// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BmpButton::BmpButton()
{

}BmpButton::~BmpButton()
{}void BmpButton::SetBitmap(CString& strPath)
{
//::SetBkColor(this,)
}void BmpButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{}void BmpButton::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{}BOOL BmpButton::OnEraseBkgnd(CDC* pDC)
{
CWnd::OnEraseBkgnd(pDC); return TRUE;
}
不管在哪里使用
Invalidate(),都不能实现妒忌OnEraseBKgnd()函数的调用