非常简单,基本散分的!欢迎欢迎!
我想弄一个透明按纽,我查了资料,说重载OnEraseBkgnd,直接return TURE。 就OK.
我是这样实现的,首先创建了一个基于对话框的工程,在上面增加了一个BUTTON,属性:ID IDC_BUTTON1
然后我用类向导给他添加了一个类,CBTN,
在CBTN的头文件中进行了OnEraseBkgnd函数的声明,然后进行了消息映射,这里是我手动添加的(我点CBTN没找到增加WINDOWS消息处理),代码如下,编译出错.
头文件
#if !defined(AFX_BTN_H__83C624F5_5E7A_4931_91CB_3C714DCF3371__INCLUDED_)
#define AFX_BTN_H__83C624F5_5E7A_4931_91CB_3C714DCF3371__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// BTN.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBTN window
class CBTN : public CButton
{
// Construction
public:
CBTN();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBTN)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CBTN();
bool OnEraseBkgnd(CDC *pDC);
// Generated message map functions
protected:
//{{AFX_MSG(CBTN)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
afx_msg bool OnEraseBkgnd(CDC *pDC);
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_BTN_H__83C624F5_5E7A_4931_91CB_3C714DCF3371__INCLUDED_)
.CPP如下
// BTN.cpp : implementation file
//
#include "stdafx.h"
#include "2.h"
#include "BTN.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBTN
CBTN::CBTN()
{
}
CBTN::~CBTN()
{
}
BEGIN_MESSAGE_MAP(CBTN, CButton)
//{{AFX_MSG_MAP(CBTN)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
ON_COMMAND(IDC_BUTTON1,onEraseBkgnd)
/////////////////////////////////////////////////////////////////////////////
// CBTN message handlers
bool CButton::OnEraseBkgnd(CDC *pDC)
{
return true;
}