colorbtn.h

来自「C++编程实践与技巧一书各章节的源码」· C头文件 代码 · 共 49 行

H
49
字号
#ifndef __COLORBTN_H__
#define __COLORBTN_H__

/////////////////////////////////////////////////////////////////////////////
// colorBtn.h : header file for the CColorButton class

class CColorButton : public CButton
{
DECLARE_DYNAMIC(CColorButton)
public:
	CColorButton(); 
	virtual ~CColorButton(); 
/*
函数Attach用于对一个现存的按钮设置颜色
其中参数nID要设置颜色的按钮ID
pParent是按钮的父窗口句柄
BGColor是按钮背景颜色,即按钮本身颜色
FGColor是前景颜色,即按钮文本颜色
DisabledColor是按钮无效时的前景颜色
nBevel是按钮斜面值
*/
	BOOL Attach(const UINT nID, CWnd* pParent, 
		const COLORREF BGColor = RGB(192, 192, 192),		// 灰色按钮
		const COLORREF FGColor = RGB(1, 1, 1),				// 黑色字体 
		const COLORREF DisabledColor = RGB(128, 128, 128),	// 暗灰色无效文本
		const UINT nBevel = 2
	);

	
protected:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
	void DrawFrame(CDC *DC, CRect R, int Inset);
	void DrawFilledRect(CDC *DC, CRect R, COLORREF color);
	void DrawLine(CDC *DC, CRect EndPoints, COLORREF color);
	void DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color);
	void DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor);

	COLORREF GetFGColor() { return m_fg; }	
	COLORREF GetBGColor() { return m_bg; }
    COLORREF GetDisabledColor() { return m_disabled; }
	UINT GetBevel() { return m_bevel; }

private:
	COLORREF m_fg, m_bg, m_disabled;
	UINT m_bevel;

};
#endif 

⌨️ 快捷键说明

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