修改button背景颜色

上传人:mg****85 文档编号:34843578 上传时间:2018-03-02 格式:DOC 页数:11 大小:53.50KB
返回 下载 相关 举报
修改button背景颜色_第1页
第1页 / 共11页
修改button背景颜色_第2页
第2页 / 共11页
修改button背景颜色_第3页
第3页 / 共11页
修改button背景颜色_第4页
第4页 / 共11页
修改button背景颜色_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《修改button背景颜色》由会员分享,可在线阅读,更多相关《修改button背景颜色(11页珍藏版)》请在金锄头文库上搜索。

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, 0); const COLORREF DKYELLOW = RGB(128, 12

2、8, 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 DKG

3、REEN = 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

4、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

5、, 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

6、, 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: C

7、OLORREF 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) CColo

8、rButton:CColorButton() #if (_MFC_VER hDC); UINT state = lpDIS- itemState; CRect focusRect, btnRect; focusRect.CopyRect( btnRect.CopyRect( focusRect.left += 4; focusRect.right -= 4; focusRect.top += 4; focusRect.bottom -= 4; const int bufSize = 512; TCHAR bufferbufSize; GetWindowText(buffer, bufSize)

9、; DrawFilledRect(pDC, btnRect, GetBGColor(); DrawFrame(pDC, btnRect, GetBevel(); DrawButtonText(pDC, btnRect, buffer, GetFGColor(); if (state if (state DrawFrame(pDC, btnRect, -1); DrawButtonText(pDC, btnRect, buffer, GetFGColor(); DrawFocusRect(lpDIS- hDC, (LPRECT) else if (state void CColorButton:

10、DrawFrame(CDC *DC, CRect R, int Inset) COLORREF dark, light, tlColor, brColor; int i, m, width; width = (Inset 1) ) DrawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, RGB(1, 1, 1);/ Across bottom DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, RGB(1, 1, 1); / Down right else D

11、rawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, brColor); / Across bottom DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, brColor); / Down right InflateRect(R, -1, -1); void CColorButton:DrawFilledRect(CDC *DC, CRect R, COLORREF color) CBrush B; B.CreateSolidBrush(color); DC

12、- FillRect(R, void CColorButton:DrawLine(CDC *DC, CRect EndPoints, COLORREF color) CPen newPen; newPen.CreatePen(PS_SOLID, 1, color); CPen *oldPen = DC- SelectObject( DC- MoveTo(EndPoints.left, EndPoints.top); DC- LineTo(EndPoints.right, EndPoints.bottom); DC- SelectObject(oldPen); newPen.DeleteObject();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号