按钮变成位图按钮

========位图按钮============

添加位图资源文件(打开资源视图,右键添加资源,选择导入。);创建wbutton.h wbutton.cpp AutoFont.h AutonFont.cpp 文件;

创建按钮变量

class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();


// 对话框数据
enum { IDD = IDD_ABOUTBOX };
CWBButton m_OK; //位图按钮
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
virtual BOOL OnInitDialog();
// 实现
protected:
DECLARE_MESSAGE_MAP()
};

绑定变量和控件

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDOK, m_OK);    //绑定
}

位图按钮显示

BOOL CAboutDlg::OnInitDialog() 
{
CDialog::OnInitDialog();


//设置“关于”对话框的位图按钮显示
m_OK.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );


return TRUE;  // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

wbutton.h:

#if !defined(AFX_WBBUTTON_H__518122CF_358F_11D4_8F4F_00402656D980__INCLUDED_)
#define AFX_WBBUTTON_H__518122CF_358F_11D4_8F4F_00402656D980__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CAutoFont;
#define SAFE_DELETE(p)  { if(p) { delete (p);     (p)=NULL; } }

 
// 功能:	位图按钮类,实现按钮的位图显示
// 修改人: 徐景周  
// 日期:	2001年2月8日

// This class implements a Window Blinds like button
class CWBButton : public CButton
{

public:
	CWBButton();

// Methods
public:
    // Bitmap Loding and Initialize
    bool LoadBitmaps
    (  
         UINT bmpID,			// bitmapID
         int count,				// Num Of Pics
         int TopHeight,			// Top Merigin for Resizing
         int BottomHeight,		// Bottom Merigin for Resizing
         int LeftWidth,			// Left Merigin for Resizing
         int RightWidth			// Right Merigin for Resizing
    );

	bool AutoLoadBitmaps        //根据按钮ID来装入位图,jingzhou xu
    (  
	     UINT bottonID,         // BottonID
		 CWnd* pParent,         // Parent pointer
         UINT bmpID,			// bitmapID
         int count,				// Num Of Pics
         int TopHeight,			// Top Merigin for Resizing
         int BottomHeight,		// Bottom Merigin for Resizing
         int LeftWidth,			// Left Merigin for Resizing
         int RightWidth			// Right Merigin for Resizing
    );

    // Set Merigins
    void SetButtonDef( int TopHeight, int BottomHeight, int LeftWidth, int RightWidth );

protected:

    enum mode
    {
        normal  = 0,
        select  = 1,
        focus   = 2,
        disable = 3
    };

    enum state
    {
        notInited    = 0,
        FileLoaded   = 1,
        BitmapInited = 2
    };

    int m_State;

    // Bitmaps
    bool InitBitmap( CBitmap & src, CBitmap & dist, int index, int count);
    void DrawBitmap( CDC * pDC, int mode );

    UINT m_RcId;       // Resource ID
    int  m_NumofPics;  

    CBitmap NormalBitmap;
    CBitmap SelectBitmap;
    CBitmap FocusBitmap;
    CBitmap DisableBitmap;

    int m_TopHeight; //= 8;
    int m_BottomHeight; //= 8;
    int m_LeftWidth; //= 8;
    int m_RightWidth;// = 17;

    int m_dwWidth;
    int m_dwHeight;

// Transpararent BackColor
protected:
    COLORREF m_BkColor;
public:
    void SetBackColor( COLORREF color ) { m_BkColor = color; }
    COLORREF GetBackColor() { return m_BkColor; }

//Fonts
protected:
    CAutoFont * m_pFnt;

public:
    void SetTextFont( CFont & fnt );
    void SetTextFont( CAutoFont & fnt );
    CFont * GetTextFont() { return (CFont *)m_pFnt; }
    CAutoFont * GetTextAutoFont() { return m_pFnt; }
    void SetFontColor( COLORREF color );
	
	//{
  {AFX_VIRTUAL(CWBButton)
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

public:
	virtual ~CWBButton();

	
protected:
	//{
  {AFX_MSG(CWBButton)
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

#ifndef _MEMDC_H_
#define _MEMDC_H_

//
// GCMemDC  - memory DC
//
// Author: Keith Rule
// Email:  keithr@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// This class implements a memory Device Context

class GCMemDC  : public CDC {
private:
	CBitmap*	m_bitmap;
	CBitmap*	m_oldBitmap;
	CDC*		m_pDC;
	CRect		m_rcBounds;
public:
	GCMemDC (CDC* pDC, const CRect& rcBounds) : CDC()
	{
		CreateCompatibleDC(pDC);
		m
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值