资源简介
1. 修改了失去焦点不能刷新的问题
2. 添加获取焦点失去焦点按钮字体颜色变化
代码片段和文件信息
//implement
// RgnButton.cpp : 实现文件
//
#include “stdafx.h“
#include “RgnButton.h“
// CRgnButton
IMPLEMENT_DYNAMIC(CRgnButton CButton)
CRgnButton::CRgnButton()
: m_bCheck(false) m_bBtnDown(false) m_bTrack(false)
m_DrawMode(DRAW_STRETCH)
m_hClipRgn(NULL) m_nFocusRectMargin(0)
{
m_cTextColor = GetSysColor(COLOR_BTNTEXT);
}
CRgnButton::~CRgnButton()
{
if (m_hClipRgn)
Deleteobject(m_hClipRgn);
}
BEGIN_MESSAGE_MAP(CRgnButton CButton)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDBLCLK()
ON_WM_KILLFOCUS()
// ON_CONTROL_REFLECT_EX(BN_CLICKED &CRgnButton::OnBnClicked)
ON_WM_KEYDOWN()
ON_MESSAGE(WM_MOUSELEAVE onmouseleave)
ON_MESSAGE(WM_CXSHADE_RADIO OnRadioInfo)
ON_MESSAGE(BM_SETCHECK OnBMSetCheck)
ON_MESSAGE(BM_GETCHECK OnBMGetCheck)
END_MESSAGE_MAP()
// CRgnButton 消息处理程序
void CRgnButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct);
//Check if the button state is not in inconsistent mode...
POINT mouse_position;
if ((m_bBtnDown) && (::GetCapture() == m_hWnd) && (::GetCursorPos(&mouse_position))) {
if (::WindowFromPoint(mouse_position) == m_hWnd) {
if ((GetState() & BST_PUSHED) != BST_PUSHED) {
SetState(TRUE);
return;
}
}
else {
if ((GetState() & BST_PUSHED) == BST_PUSHED) {
SetState(FALSE);
return;
}
}
}
CString strCaption;
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc = lpDrawItemStruct->rcItem;
int cx = rc.Width();
int cy = rc.Height();
// get text box position
RECT tr = { rc.left + m_nFocusRectMargin + 2 rc.top rc.right - m_nFocusRectMargin - 2 rc.bottom };
GetWindowText(strCaption); // get button text
pDC->SetBkMode(TRANSPARENT);
// Select the correct skin
if (lpDrawItemStruct->itemState & ODS_DISABLED) { // DISABLED BUTTON
if (m_bDisable.m_hobject == NULL)
// no skin selected for disabled state -> standard button
pDC->FillSolidRect(&rc GetSysColor(COLOR_BTNFACE));
else // paint the skin
DrawBitmap(pDC m_bDisable rc m_DrawMode);
// if needed draw the standard 3D rectangular border
if (m_bHasBorder)
pDC->DrawEdge(&rc EDGE_RAISED BF_RECT);
// paint the etched button text
pDC->SetTextColor(GetSysColor(COLOR_3DHILIGHT));
pDC->DrawText(strCaption &tr DT_SINGLELINE | DT_VCENTER | DT_CENTER);
pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
OffsetRect(&tr -1 -1);
pDC->DrawText(strCaption &tr DT_SINGLELINE | DT_VCENTER | DT_CENTER);
}
else { // SELECTED (DOWN) BUTTON
if ((lpDrawItemStruct->itemState & ODS_SELECTED) || m_bCheck) {
if (m_bDown.m_hobject == NULL) // no skin selected for selected state -> standard button
pDC->FillSolidRect(&rc GetSysColor(COLOR_BTNFACE));
else { // paint the skin
DrawBitmap(pDC m_bDown rc m_DrawMode);
评论
共有 条评论