BmpCaptionBackground.cpp
上传用户:kssdz899
上传日期:2007-01-08
资源大小:79k
文件大小:2k
源码类别:

钩子与API截获

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////
  2. // Example of customising CCaptionBackground to pain a bitmap
  3. // as the caption background.
  4. //
  5. // Just derive from CCaptionBackground and override the Paint method.
  6. //
  7. // Construct CCaptionBmpPainter passing the path of the bmp file
  8. // to be displayed as the active caption background, and a BOOL
  9. // value to indicate whether to stretch the bitmap to fit the
  10. // caption (it will stretch by default if not specified).
  11. //
  12. // Author: Dave Lorde (dlorde@cix.compulink.co.uk)
  13. //
  14. //          Copyright January 2000
  15. //
  16. #include "stdafx.h"
  17. #include "BmpCaptionBackground.h"
  18. CBmpCaptionBackground::CBmpCaptionBackground(const char* bmpPath, BOOL stretch)
  19. :m_Path(bmpPath), m_Stretch(stretch), m_Valid(false)
  20. {
  21. SetBitmap(m_Path);
  22. }
  23. CBmpCaptionBackground::CBmpCaptionBackground(const CBmpCaptionBackground& bcb)
  24. :m_Path(bcb.m_Path), m_Stretch(bcb.m_Stretch), m_Valid(false) 
  25. {
  26. SetBitmap(m_Path);
  27. }
  28. boolean CBmpCaptionBackground::SetBitmap(const char* bmpPath)
  29. {
  30. m_Valid = m_Dib.Load(m_Path);
  31. return IsValid();
  32. }
  33. void CBmpCaptionBackground::SetStretch(boolean stretch)
  34. {
  35. m_Stretch = stretch;
  36. }
  37. boolean CBmpCaptionBackground::IsValid() const
  38. {
  39. return m_Valid;
  40. }
  41. CString CBmpCaptionBackground::GetPath() const
  42. {
  43. return m_Path;
  44. }
  45. void CBmpCaptionBackground::Paint(CDC* pDC, CSize paintArea, BOOL active)
  46. {
  47. if (active && m_Valid)
  48. PaintBitmap(pDC, paintArea);
  49. else
  50. CCaptionBackground::Paint(pDC, paintArea, active);
  51. }
  52. void CBmpCaptionBackground::PaintBitmap(CDC* pDC, CSize paintArea)
  53. {
  54. CRect rectDest(0, 0, paintArea.cx, paintArea.cy);
  55. if (m_Stretch)
  56. m_Dib.Draw(*pDC, &rectDest, 0);
  57. else
  58. m_Dib.Draw(pDC);
  59. }