1、本程序基于前期我的博客文章MFC用CButtonST类实现图片透明按钮(免费源码下载)
2、添加CeXDib.cpp CeXDib.h ShadeButtonST.cpp ShadeButtonST.h到项目文件夹下,和FileView中如图。
3、在ButtonShadeDlg.h中添加代码
cpp
#include "ShadeButtonST.h"
#include "BtnST.h"
class CButtonShadeDlg : public CDialog
{
// Construction
public:
CButtonShadeDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CButtonShadeDlg)
enum { IDD = IDD_BUTTONSHADE_DIALOG };
CButtonST m_btnPrint;
CShadeButtonST m_btnCancel;
CShadeButtonST m_btnOK;
//}}AFX_DATA
...
}
4、在ButtonShadeDlg.cpp中添加代码
cpp
void CButtonShadeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CButtonShadeDlg)
DDX_Control(pDX, IDC_BUTTON1, m_btnPrint);
DDX_Control(pDX, IDCANCEL, m_btnCancel);
DDX_Control(pDX, IDOK, m_btnOK);
//}}AFX_DATA_MAP
}
BOOL CButtonShadeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_btnPrint.SetIcon(IDI_ICON_Print);
m_btnPrint.SetAlign(CButtonST::ST_ALIGN_VERT);
m_btnOK.SetShade(CShadeButtonST::SHS_HARDBUMP);
m_btnCancel.SetShade(CShadeButtonST::SHS_HARDBUMP);
...
}
运行程序