BmpCaptionBackground.cpp
上传用户:zhoushen
上传日期:2022-06-15
资源大小:84k
文件大小:2k
- /////////////////////////////////////////////////////////////////
- // Example of customising CCaptionBackground to pain a bitmap
- // as the caption background.
- //
- // Just derive from CCaptionBackground and override the Paint method.
- //
- // Construct CCaptionBmpPainter passing the path of the bmp file
- // to be displayed as the active caption background, and a BOOL
- // value to indicate whether to stretch the bitmap to fit the
- // caption (it will stretch by default if not specified).
- //
- // Author: Dave Lorde (dlorde@cix.compulink.co.uk)
- //
- // Copyright January 2000
- //
- #include "stdafx.h"
- #include "BmpCaptionBackground.h"
- CBmpCaptionBackground::CBmpCaptionBackground(const char* bmpPath, BOOL stretch)
- :m_Path(bmpPath), m_Stretch(stretch), m_Valid(false)
- {
- SetBitmap(m_Path);
- }
- CBmpCaptionBackground::CBmpCaptionBackground(const CBmpCaptionBackground& bcb)
- :m_Path(bcb.m_Path), m_Stretch(bcb.m_Stretch), m_Valid(false)
- {
- SetBitmap(m_Path);
- }
- boolean CBmpCaptionBackground::SetBitmap(const char* bmpPath)
- {
- m_Valid = m_Dib.Load(m_Path);
- return IsValid();
- }
- void CBmpCaptionBackground::SetStretch(boolean stretch)
- {
- m_Stretch = stretch;
- }
- boolean CBmpCaptionBackground::IsValid() const
- {
- return m_Valid;
- }
- CString CBmpCaptionBackground::GetPath() const
- {
- return m_Path;
- }
- void CBmpCaptionBackground::Paint(CDC* pDC, CSize paintArea, BOOL active)
- {
- if (active && m_Valid)
- PaintBitmap(pDC, paintArea);
- else
- CCaptionBackground::Paint(pDC, paintArea, active);
- }
- void CBmpCaptionBackground::PaintBitmap(CDC* pDC, CSize paintArea)
- {
- CRect rectDest(0, 0, paintArea.cx, paintArea.cy);
- if (m_Stretch)
- m_Dib.Draw(*pDC, &rectDest, 0);
- else
- m_Dib.Draw(pDC);
- }