/********************************************************************
created: 2005/06/03
created: 3:6:2005 13:22
filename: x:\Software\Mfc\Source\Controls\Buttons\RoundButton2.cpp
file path: x:\Software\Mfc\Source\Controls\Buttons
file base: RoundButton2
file ext: cpp
author: Markus Zocholl
purpose: CRoundButton2 defines a universal Button-Control with the
following features:
* Shape is a rounded Rectangle
* Button includes Border and Button-Face
* Many parameters to get an individual look
* Functions of Button to be en- or disabled:
- Button (disabled means a static control with userdefined styles)
- Hover
*********************************************************************/
#include "StdAfx.h"
#include <math.h>
#include ".\RoundButton2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/************************************************************************/
/* Construction and Destruction */
/************************************************************************/
//! Construction
CRoundButton2::CRoundButton2(void):
m_bDefaultButton(false)
, m_bIsCheckButton(false)
, m_bIsRadioButton(false)
, m_bIsHotButton(false)
, m_bMouseOnButton(false)
, m_bIsChecked(false)
, m_ptRoundButtonStyle(NULL)
, m_rBtnSize(CRect(0, 0, 0, 0))
, m_bRedraw(false)
, m_sOldCaption(_T(""))
{
// Set Standards in Font-Style
m_tLogFont.lfHeight = 16;
m_tLogFont.lfWidth = 0;
m_tLogFont.lfEscapement = 0;
m_tLogFont.lfOrientation = 0;
m_tLogFont.lfWeight = FW_BOLD;
m_tLogFont.lfItalic = false;
m_tLogFont.lfUnderline = false;
m_tLogFont.lfStrikeOut = false;
m_tLogFont.lfCharSet = DEFAULT_CHARSET;
m_tLogFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
m_tLogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
m_tLogFont.lfQuality = ANTIALIASED_QUALITY;
m_tLogFont.lfPitchAndFamily = DEFAULT_PITCH;
strcpy(m_tLogFont.lfFaceName, "Tahoma");
m_tBtnFont.CreateFontIndirect(&m_tLogFont);
// Set Standard Font-Color
m_tTextColor.m_tDisabled = RGB(64, 64, 64);
m_tTextColor.m_tEnabled = RGB( 0, 0, 0);
m_tTextColor.m_tClicked = RGB( 0, 0, 0);
m_tTextColor.m_tPressed = RGB( 0, 0, 0);
m_tTextColor.m_tHot = RGB( 0, 0, 0);
}
//! Destruction
CRoundButton2::~CRoundButton2(void)
{
}
/************************************************************************/
/* public Functions */
/************************************************************************/
// Set Style of Button
bool CRoundButton2::SetRoundButtonStyle(CRoundButtonStyle* _ptRoundButtonStyle)
{
// Check, if Button-Style is given
if (_ptRoundButtonStyle == NULL)
return false;
// Set Pointer to ButtonStyle
m_ptRoundButtonStyle = _ptRoundButtonStyle;
// Redraw Button
m_bRedraw = true;
// All Done
return false;
}
// Set Font of Button
bool CRoundButton2::SetFont(LOGFONT* _ptLogFont)
{
if (_ptLogFont == NULL)
return false;
// Delete Font, if already given
if (m_tBtnFont.m_hObject != NULL)
m_tBtnFont.DeleteObject();
// Store Infos local
memcpy(&m_tLogFont, _ptLogFont, sizeof(LOGFONT));
// Create new Font
m_tBtnFont.CreateFontIndirect(&m_tLogFont);
// Button should be redrawn
m_bRedraw = true;
return true;
}
// Set Font of Button
bool CRoundButton2::GetFont(LOGFONT* _ptLogFont)
{
if (_ptLogFont == NULL)
return false;
// Store Infos local
memcpy(_ptLogFont, &m_tLogFont, sizeof(LOGFONT));
return true;
}
//! Set Color of Caption
bool CRoundButton2::SetTextColor(tColorScheme* _ptTextColor)
{
if (_ptTextColor == NULL)
return false;
// Store Infos locally
memcpy(&m_tTextColor, _ptTextColor, sizeof(tColorScheme));
// Button should be redrawn
m_bRedraw = true;
return true;
}
//! Get Color of Caption
bool CRoundButton2::GetTextColor(tColorScheme* _ptTextColor)
{
if (_ptTextColor == NULL)
return false;
// Store Infos locally
memcpy(_ptTextColor, &m_tTextColor, sizeof(tColorScheme));
return true;
}
/************************************************************************/
/* Own Drawing-Functions */
/************************************************************************/
//! Generate Bitmaps to hold Buttons
void CRoundButton2::GenButtonBMPs(CDC* _pDC, CRect _rRect)
{
if (m_tBmpBtn.m_hObject != NULL)
m_tBmpBtn.DeleteObject();
m_tBmpBtn.m_hObject = NULL;
// Generate Bitmap
if (m_tBmpBtn.CreateCompatibleBitmap(_pDC, _rRect.Width(), _rRect.Height() * BS_LAST_STATE) == FALSE)
{
m_rBtnSize = CRect(0, 0, 0, 0);
}
else
{
m_rBtnSize = _rRect;
}
}
//! Draw Button-Face
void CRoundButton2::DrawButtonFace(CDC* _pDC)
{
// We need an attached style
if (m_ptRoundButtonStyle == NULL)
return;
// Get Pointer to Bitmap of Masks
CBitmap* pButtonMasks = m_ptRoundButtonStyle->GetButtonEdge(_pDC);
// Create Memory-DC
CDC SourceDC;
SourceDC.CreateCompatibleDC(_pDC);
// Select Working Objects into DCs
HGDIOBJ hOldBmp1 = SourceDC.SelectObject(pButtonMasks);
int nState;
CSize tEdgeSize = m_ptRoundButtonStyle->GetEdgeSize();
CSize tCorrectedEdgeSize;
CSize tMaskSize = m_ptRoundButtonStyle->GetMaskSize();
// Correct Edge-Size for smaller Buttons
tCorrectedEdgeSize.cx = __min(tEdgeSize.cx, __min(m_rBtnSize.Width() / 2, m_rBtnSize.Height() / 2));
tCorrectedEdgeSize.cy = tCorrectedEdgeSize.cx;
for (nState = 0; nState < BS_LAST_STATE; nState++)
{
/************************************************************************/
/* Draw Edges */
/************************************************************************/
// Left-Top
_pDC->StretchBlt(
0,
nState * m_rBtnSize.Height(),
tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
0,
nState * tMaskSize.cy,
tEdgeSize.cx,
tEdgeSize.cy,
SRCCOPY);
// Left-Bottom
_pDC->StretchBlt(
0,
nState * m_rBtnSize.Height() + m_rBtnSize.Height() - tCorrectedEdgeSize.cy,
tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
0,
nState * tMaskSize.cy + tMaskSize.cy - tEdgeSize.cy,
tEdgeSize.cx,
tEdgeSize.cy,
SRCCOPY);
// Right-Top
_pDC->StretchBlt(
m_rBtnSize.Width() - tCorrectedEdgeSize.cx,
nState * m_rBtnSize.Height(),
tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
tMaskSize.cx - tEdgeSize.cx,
nState * tMaskSize.cy,
tEdgeSize.cx,
tEdgeSize.cy,
SRCCOPY);
// Right-Bottom
_pDC->StretchBlt(
m_rBtnSize.Width() - tCorrectedEdgeSize.cx,
nState * m_rBtnSize.Height() + m_rBtnSize.Height() - tCorrectedEdgeSize.cy,
tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
tMaskSize.cx - tEdgeSize.cx,
nState * tMaskSize.cy + tMaskSize.cy - tEdgeSize.cy,
tEdgeSize.cx,
tEdgeSize.cy,
SRCCOPY);
/************************************************************************/
/* Draw Sides */
/************************************************************************/
// Top
_pDC->StretchBlt(
tCorrectedEdgeSize.cx,
nState * m_rBtnSize.Height(),
m_rBtnSize.Width() - 2 * tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
tEdgeSize.cx,
nState * tMaskSize.cy,
1,
tEdgeSize.cy,
SRCCOPY);
// Bottom
_pDC->StretchBlt(
tCorrectedEdgeSize.cx,
nState * m_rBtnSize.Height() + m_rBtnSize.Height() - tCorrectedEdgeSize.cy,
m_rBtnSize.Width() - 2 * tCorrectedEdgeSize.cx,
tCorrectedEdgeSize.cy,
&SourceDC,
tEdgeSize.cx,
nState * tMaskSize.cy + tMaskSize.cy - tEdgeSize
没有合适的资源?快使用搜索试试~ 我知道了~
CRoundButton_demo
共20个文件
h:7个
cpp:6个
ico:1个
4星 · 超过85%的资源 需积分: 3 14 下载量 194 浏览量
2011-12-05
22:05:22
上传
评论
收藏 53KB ZIP 举报
温馨提示
vc6 round button 键字请用空格分隔,最多填写5个。点击右侧我的Tag可快速添加
资源推荐
资源详情
资源评论
收起资源包目录
CRoundButton2_demo.zip (20个子文件)
stdafx.cpp 214B
CRoundButtonDemo.h 586B
res
CRoundButtonDemo.rc2 447B
CRoundButtonDemo.ico 21KB
CRoundButtonDemo.manifest 727B
DebugDialog.cpp 848B
stdafx.h 2KB
RoundButtonStyle.h 5KB
CRoundButtonDemo.rc 7KB
CRoundButtonDemo.exe 60KB
CRoundButtonDemo.sln 921B
CRoundButtonDemoDlg.cpp 11KB
CRoundButtonDemoDlg.h 2KB
resource.h 2KB
RoundButton2.cpp 14KB
CRoundButtonDemo.vcproj 5KB
RoundButton2.h 5KB
CRoundButtonDemo.cpp 2KB
RoundButtonStyle.cpp 11KB
DebugDialog.h 541B
共 20 条
- 1
资源评论
- 北漂的驴子2015-06-04BUTTON效果不错,可参考使用
dl521410
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功