VC++ MFC中 使用BMP按钮

本文档介绍了如何在VC++ MFC应用程序中创建一个使用BMP图像作为按钮背景的自绘按钮。首先定义了一个名为CBmpButton的类,该类继承自CButton,并提供了设置和绘制透明BMP的功能。接着,通过在对话框类中实例化CBmpButton类,并在DoDataExchange函数中映射按钮控件,以及在OnInitDialog中设置图像数据,实现了BMP按钮的显示。注意,按钮样式应设置为owner draw和bitmap。
摘要由CSDN通过智能技术生成
*********ins-ert***********编译出错请去掉“-”


1. 用下面的类CBmpButton
2. 例化一个CBmpButton并将 控件映射 到想要显示为BMP的按钮上
3. 注意: 要显示BMP的按钮的style属性应选为: owner draw , bitmap
4. 在按钮所在的类里的 3处 添加:
在*.H文件中:
#include "BmpButton.h" //-- 包含头文件

//---------------------------
//-- 添加1
//---------------------------
// Dialog Data
//{ {AFX_DATA(CBitmapButtonDlg)
enum { IDD = IDD_BITMAPBUTTON_DIALOG };
CBmpButton m_BmpButton; //-- added here
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA

//---------------------------
//-- 添加1
//---------------------------
// Dialog Data
//{ {AFX_DATA(CBitmapButtonDlg)
enum { IDD = IDD_BITMAPBUTTON_DIALOG };
CBmpButton m_BmpButton; //-- added here
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA


//---------------------------
//-- 添加2
//---------------------------
void CBitmapButtonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{ {AFX_DATA_MAP(CBitmapButtonDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDOK, m_BmpButton);//-- added here


//}}AFX_DATA_MAP
}
//---------------------------
//-- 添加3
//---------------------------
BOOL CBitmapButtonDlg::OnInitDialog()
{
......系统初始化代码

m_BmpButton.SetData( TRUE, IDB_OK );
return TRUE;
}


//---------------------------------------------------------------------------------
//-- 给予CBUTTON的CBmpButton类如下
//-- BmpButton.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 > 1000
// BmpButton.h : header file
//

/
// CBmpButton window

class CBmpButton : public CButton
{
// Construction
public:
CBmpButton();



// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{ {AFX_VIRTUAL(CBmpButton)
//}}AFX_VIRTUAL


// Implementation
public:
BOOL SetData( BOOL ImageOnLeft, UINT IDUp, UINT IDDown=0, UINT IDFocus=0, UINT IDDisabled=0);
void DrawTransparent(CDC* pDC, int x, int y, CBitmap* hbmImage, BOOL LowerLeft=TRUE, COLORREF crColor=0);
void Emboss( CBitmap& Dest, CBitmap& bmSource );
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);

// 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;



virtual ~CBmpButton();

// Generated message map funct
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值