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

钩子与API截获

开发平台:

Visual C++

  1. #ifndef _CAPTION_H
  2. #define _CAPTION_H
  3. ////////////////////////////////////////////////////////////////
  4. //
  5. // class CCaption
  6. //
  7. // Generic caption painter. Handles WM_NCPAINT, WM_NCACTIVATE, etc. to
  8. // handle drawing custom captions. To use it:
  9. //
  10. // - call Install from your frame's OnCreate function. 
  11. // - Set a custom CaptionBackground if desired
  12. // - Set custom TextAttributes if required
  13. //
  14. //  Derive from this class for custom caption layouts.
  15. // 
  16. //   If you are drawing custom caption buttons, you must handle WM_NCLBUTTONDOWN & co.
  17. //   yourself. CCaption does not handle the mouse for custom caption buttons. 
  18. //
  19. // Author: Dave Lorde (dlorde@cix.compulink.co.uk)
  20. //
  21. //          Copyright January 2000
  22. //
  23. // - loosely based on a 1997 Microsoft Systems Journal
  24. //            C++ Q&A article by Paul DiLascia. 
  25. //
  26. ////////////////////////////////////////////////////////////////
  27. //
  28. #include "Subclass.h"
  29. // forward declarations
  30. class CCaptionBackground;
  31. class CCaptionTextAttributes;
  32. class AFX_EXT_CLASS CCaption : public CSubclassWnd 
  33. {
  34. public:
  35.   CCaption();
  36. virtual ~CCaption();
  37. BOOL Install (CFrameWnd* pFrameWnd);
  38. void Uninstall ();
  39. void SetBackground (CCaptionBackground* pBackground);
  40. void SetTextAttributes (CCaptionTextAttributes* pTextAttributes);
  41. CCaptionBackground* GetBackground ();
  42. CCaptionTextAttributes* GetTextAttributes ();
  43. virtual void Refresh();
  44.  
  45. protected:
  46. CBitmap m_bmCaption[2]; // bitmaps for active/inactive captions 
  47. CSize m_szCaption; // size of caption rectangle
  48. BOOL m_bActive; // active/inactive state
  49. CCaptionBackground* m_pBackground;
  50. CCaptionTextAttributes* m_pTextAttributes;
  51. DECLARE_DYNAMIC(CCaption);
  52. // Helpers
  53. //
  54. void Invalidate ();
  55. CSize GetFrameSize () const;
  56. int GetLuminosity (COLORREF color) const;
  57. int GetIconWidth ();
  58. int GetButtonsWidth ();
  59. COLORREF GetTextColor (BOOL bActive);
  60. // Override these in derived classes if necessary
  61. //
  62. virtual void PaintCaption();
  63. virtual void PaintBitmap (CDC* pDC);
  64. virtual void PaintBackground (CDC* pDC);
  65. virtual int PaintIcon (CDC* pDC = 0);
  66. virtual int PaintButtons (CDC* pDC = 0);
  67. virtual void PaintText (CDC* pDC);
  68. virtual void PaintLowerBorder(CDC* pDC);
  69. virtual CRect GetCaptionRect ();
  70. virtual CFont* GetFont (BOOL bActive);
  71. virtual CRect GetTextRect ();
  72. // Paul DiLascia says:
  73. // "These are similar to, but NOT the same as the equivalent CWnd fns. Don't
  74. // override unless you're a guru, and even THEN I wouldn't recommend it."
  75. virtual LRESULT WindowProc (UINT msg, WPARAM wp, LPARAM lp);
  76. virtual void OnNcPaint (HRGN hUpdateRgn);
  77. virtual BOOL OnNcActivate (BOOL bActive);
  78. virtual void OnSetText (LPCTSTR lpText);
  79. virtual void OnColorChange ();
  80. };
  81. #endif