📄 picbutton.cpp
字号:
/*
* Copyright (c) 2002, Bcdliang
* All rights reserved.
*
* 文件名称:PicButton.cpp
* 摘 要:类CPicButton的实现
*
* 当前版本:1.01
* 作 者:LIANG Zheng
* 完成日期:2002年7月19日
*/
#include "stdafx.h"
#include "PicButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPicButton
CPicButton::CPicButton()
{
}
CPicButton::~CPicButton()
{
}
////////////////////////////////////////////////////////////////////////
/*
* 函数名称:SetPic
* 函数介绍:指定背景图和前景图的资源ID, 设定按扭的图案
* 输入参数:UINT uIDBack, 背景图的资源ID
UINT uIDFore, 前景图的资源ID
* 输出参数:无
* 返回值 :无
*/
void CPicButton::SetPic(UINT uIDBack, UINT uIDFore)
{
CDC *pDC, dcBack, dcFore;
HBITMAP hbmpBack, hbmpFore;
CBitmap bmpBack, bmpFore, *bmpOldBack, *bmpOldFore;
BITMAP bmpinfo;
CRect rect;
this->GetClientRect(&rect);
// Create DC.
pDC = this->GetDC();
dcBack.CreateCompatibleDC(pDC);
dcFore.CreateCompatibleDC(pDC);
// Load the bitmap.
hbmpBack = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(uIDBack),
IMAGE_BITMAP,
rect.Width(),
rect.Height(),
0);
ASSERT(hbmpBack);
hbmpFore = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(uIDFore),
IMAGE_BITMAP,
0,
0,
0);
ASSERT(hbmpFore);
// Attach bitmap handle to bitmap object.
bmpBack.Attach(hbmpBack);
bmpFore.Attach(hbmpFore);
// Get the information of the foreground bitmap.
bmpFore.GetBitmap(&bmpinfo);
// Select the bitmap object to the memory dc
bmpOldBack = dcBack.SelectObject(&bmpBack);
bmpOldFore = dcFore.SelectObject(&bmpFore);
// Combine the foreground bitmap with the background bitmap.
dcBack.BitBlt((rect.Width() - bmpinfo.bmWidth)/2,
(rect.Height() - bmpinfo.bmHeight)/2,
bmpinfo.bmWidth,
bmpinfo.bmHeight,
&dcFore,
0,
0,
SRCAND);
// Select the bitmap object out of the memory dc, and detach
// the windows GDI object(bitmap) from the bitmap object.
// (windows GDI object must be detached before used!)
dcBack.SelectObject(bmpOldBack);
dcFore.SelectObject(bmpOldFore);
bmpBack.Detach();
bmpFore.Detach();
// Set the button bitmap.
this->SetBitmap(hbmpBack);
// Delete the bitmap object & the memory dc.
bmpBack.DeleteObject();
bmpFore.DeleteObject();
dcBack.DeleteDC();
dcFore.DeleteDC();
}
BEGIN_MESSAGE_MAP(CPicButton, CButton)
//{{AFX_MSG_MAP(CPicButton)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPicButton message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -