CaptionBackground.cpp
上传用户:zhoushen
上传日期:2022-06-15
资源大小:84k
文件大小:2k
- #include "stdafx.h"
- #include "CaptionBackground.h"
- #include "AutoSelector.h"
- //////////////////
- // Helper to paint rectangle with a color.
- //
- CCaptionBackground::CCaptionBackground()
- :m_ActiveColor(-1), m_InactiveColor(-1)
- {
- }
- CCaptionBackground::CCaptionBackground(const CCaptionBackground& cb)
- :m_ActiveColor(cb.m_ActiveColor), m_InactiveColor(cb.m_InactiveColor)
- {
- }
- void CCaptionBackground::SetCustomColors(const CCaptionBackground& cb)
- {
- SetActiveColor(cb.m_ActiveColor);
- SetInactiveColor(cb.m_InactiveColor);
- }
- void CCaptionBackground::SetCustomColors(COLORREF activeColor, COLORREF inactiveColor)
- {
- SetActiveColor(activeColor);
- SetInactiveColor(inactiveColor);
- }
- void CCaptionBackground::SetActiveColor(COLORREF activeColor)
- {
- m_ActiveColor = activeColor;
- }
- void CCaptionBackground::SetInactiveColor(COLORREF inactiveColor)
- {
- m_InactiveColor = inactiveColor;
- }
- void CCaptionBackground::UseSystemColors()
- {
- UseSystemActiveColor();
- UseSystemInactiveColor();
- }
- void CCaptionBackground::UseSystemActiveColor()
- {
- m_ActiveColor = -1;
- }
- void CCaptionBackground::UseSystemInactiveColor()
- {
- m_InactiveColor = -1;
- }
- boolean CCaptionBackground::IsUsingSystemColors()
- {
- return m_ActiveColor == -1;
- }
- COLORREF CCaptionBackground::GetActiveColor() const
- {
- return m_ActiveColor == -1 ? GetSysColor(COLOR_ACTIVECAPTION) : m_ActiveColor;
- }
- COLORREF CCaptionBackground::GetInactiveColor() const
- {
- return m_InactiveColor == -1 ? GetSysColor(COLOR_INACTIVECAPTION) : m_InactiveColor;
- }
- void CCaptionBackground::Paint(CDC* pDC, CSize paintArea, BOOL active)
- {
- PaintRect(pDC, 0, 0, paintArea.cx, paintArea.cy, active ? GetActiveColor() : GetInactiveColor());
- }
- // Paint the color into the rectangle dimensions on the device context
- void CCaptionBackground::PaintRect(CDC* pDC, int x, int y, int w, int h, COLORREF color)
- {
- CBrush brush(color);
- AutoSelector a(pDC, &brush);
- pDC->PatBlt(x, y, w, h, PATCOPY);
- }