⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttoncolor.cpp

📁 在程序中添加一个颜色拾取的按钮
💻 CPP
字号:
/* 
 *  Copyright 2007, cgsir.com, Inc.
 *  作者:李英江
 *  日期:2007.12
 *  修改:
 *  说明:颜色拾取
 */

// ButtonColor.cpp : implementation file
//

#include "stdafx.h"
#include "TestBC.h"
#include "ButtonColor.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CButtonColor

CButtonColor::CButtonColor()
{
	m_bgColor = RGB(255, 0, 0);
}

CButtonColor::~CButtonColor()
{
}


BEGIN_MESSAGE_MAP(CButtonColor, CButton)
	//{{AFX_MSG_MAP(CButtonColor)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CButtonColor message handlers

void CButtonColor::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your code to draw the specified item
	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	// 画按钮背景色
	CBrush cb;
	cb.CreateSolidBrush(GetBGColor());
	CRect rc= lpDrawItemStruct->rcItem;
	pDC->FillRect(&rc, &cb);
	
	// 画按钮边框
	CBrush cbFrame;
	cbFrame.CreateSolidBrush(RGB(255,255,255));
	pDC->FrameRect(&rc, &cbFrame);
}

COLORREF CButtonColor::GetBGColor()
{
	return m_bgColor;
}

BOOL CButtonColor::Attach(const UINT nID, CWnd *pParent, COLORREF bgColor)
{
	if (!SubclassDlgItem(nID, pParent)) {
		return FALSE;
	}
	
	m_bgColor = bgColor;

	return TRUE;
}

BOOL CButtonColor::SetBGColor(COLORREF bgColor)
{
	m_bgColor = bgColor;
	InvalidateRect(NULL);
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -