(完整word版)修改BUTTON背景颜色

  • 格式:doc
  • 大小:53.51 KB
  • 文档页数:11

下载文档原格式

  / 11
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//定义色彩

const COLORREF CLOUDBLUE = RGB(128, 184, 223);

const COLORREF WHITE = RGB(255, 255, 255);

const COLORREF BLACK = RGB(1, 1, 1);

const COLORREF DKGRAY = RGB(128, 128, 128);

const COLORREF LTGRAY = RGB(192, 192, 192);

const COLORREF YELLOW = RGB(255, 255, 0);

const COLORREF DKYELLOW = RGB(128, 128, 0);

const COLORREF RED = RGB(255, 0, 0);

const COLORREF DKRED = RGB(128, 0, 0);

const COLORREF BLUE = RGB(0, 0, 255);

const COLORREF DKBLUE = RGB(0, 0, 128);

const COLORREF CYAN = RGB(0, 255, 255);

const COLORREF DKCYAN = RGB(0, 128, 128);

const COLORREF GREEN = RGB(0, 255, 0);

const COLORREF DKGREEN = RGB(0, 128, 0);

const COLORREF MAGENTA = RGB(255, 0, 255);

const COLORREF DKMAGENTA = RGB(128, 0, 128);

//在.h文件定义彩色按钮

CColorButton m_btnUp;

//在.cpp文件调用函数着色

VERIFY(m_btnUp.Attach(IDC_BUTTON1, this, RED, WHITE, DKRED));

//CColorButton 类原型

//colorbtn.h

#ifndef __COLORBTN_H__

#define __COLORBTN_H__

class CColorButton : public CButton

{

DECLARE_DYNAMIC(CColorButton)

public:

CColorButton();

virtual ~CColorButton();

BOOL Attach(const UINT nID, CWnd* pParent,

const COLORREF BGColor = RGB(192, 192, 192), // gray button

const COLORREF FGColor = RGB(1, 1, 1), // black text

const COLORREF DisabledColor = RGB(128, 128, 128), // dark gray disabled text

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

//colorbtn.cpp

#include "stdafx.h "

#include "colorbtn.h "

#ifdef _DEBUG

#undef THIS_FILE

static char BASED_CODE THIS_FILE[] = __FILE__;

#endif

#ifdef CColorButton

#undef CColorButton CColorButton

#endif

IMPLEMENT_DYNAMIC(CColorButton, CButton)

CColorButton::CColorButton()

{

#if (_MFC_VER < 0x0250)

hwndOwner = NULL;

#endif

}

CColorButton::~CColorButton()

{

}

BOOL CColorButton::Attach(const UINT nID, CWnd* pParent, cons t COLORREF BGColor, const COLORREF FGColor, const COLORREF DisabledColor, const UINT nBevel)

{

if (!SubclassDlgItem(nID, pParent))

return FALSE;

m_fg = FGColor;

m_bg = BGColor;

m_disabled = DisabledColor;

m_bevel = nBevel;

return TRUE;

}

void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDIS)

{

CDC* pDC = CDC::FromHandle(lpDIS-> hDC);

UINT state = lpDIS-> itemState;

CRect focusRect, btnRect;

focusRect.CopyRect(&lpDIS-> rcItem);

btnRect.CopyRect(&lpDIS-> rcItem);

focusRect.left += 4;

focusRect.right -= 4;

focusRect.top += 4;

focusRect.bottom -= 4;

const int bufSize = 512;

TCHAR buffer[bufSize];

GetWindowText(buffer, bufSize);

相关主题