资源描述:
《修改button背景颜色》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//定义色彩 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,
2、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 DKC
3、YAN = 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.A
4、ttach(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(cons
5、t 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
6、 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 bo
7、ttom, 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_be
8、vel; } 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 BAS