========位图按钮============
添加位图资源文件(打开资源视图,右键添加资源,选择导入。);创建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