Caption.h
上传用户:zhoushen
上传日期:2022-06-15
资源大小:84k
文件大小:3k
- #ifndef _CAPTION_H
- #define _CAPTION_H
- ////////////////////////////////////////////////////////////////
- //
- // class CCaption
- //
- // Generic caption painter. Handles WM_NCPAINT, WM_NCACTIVATE, etc. to
- // handle drawing custom captions. To use it:
- //
- // - call Install from your frame's OnCreate function.
- // - Set a custom CaptionBackground if desired
- // - Set custom TextAttributes if required
- //
- // Derive from this class for custom caption layouts.
- //
- // If you are drawing custom caption buttons, you must handle WM_NCLBUTTONDOWN & co.
- // yourself. CCaption does not handle the mouse for custom caption buttons.
- //
- // Author: Dave Lorde (dlorde@cix.compulink.co.uk)
- //
- // Copyright January 2000
- //
- // - based on a 1997 Microsoft Systems Journal
- // C++ Q&A article by Paul DiLascia.
- //
- ////////////////////////////////////////////////////////////////
- //
- #include "Subclass.h"
- // forward declarations
- class CCaptionBackground;
- class CCaptionTextAttributes;
- class AFX_EXT_CLASS CCaption : public CSubclassWnd
- {
- public:
- BOOL Install (CFrameWnd* pFrameWnd);
- void Uninstall ();
- void SetBackground (CCaptionBackground* pBackground);
- void SetTextAttributes (CCaptionTextAttributes* pTextAttributes);
-
- CCaptionBackground* GetBackground ();
- CCaptionTextAttributes* GetTextAttributes ();
- virtual void Refresh();
-
- protected:
- CCaption(); // Protected ctor makes class abstract
- virtual ~CCaption(); // Protected dtor makes class abstract
- CBitmap m_bmCaption[2]; // bitmaps for active/inactive captions
- CSize m_szCaption; // size of caption rectangle
- BOOL m_bActive; // active/inactive state
- HICON m_hIcon;
- CCaptionBackground* m_pBackground;
- CCaptionTextAttributes* m_pTextAttributes;
- DECLARE_DYNAMIC(CCaption);
- // Helpers
- //
- void Invalidate ();
- CSize GetFrameSize () const;
- int GetLuminosity (COLORREF color) const;
- int GetIconWidth ();
- int GetButtonsWidth ();
- COLORREF GetTextColor (BOOL bActive);
- // Override these in derived classes if necessary
- //
- virtual void PaintCaption();
- virtual void PaintBitmap (CDC* pDC);
- virtual void PaintBackground (CDC* pDC);
- virtual int PaintIcon (CDC* pDC = 0);
- virtual int PaintButtons (CDC* pDC = 0);
- virtual void PaintText (CDC* pDC);
- virtual void PaintLowerBorder(CDC* pDC);
- virtual CRect GetCaptionRect ();
- virtual CFont* GetFont (BOOL bActive);
- virtual CRect GetTextRect ();
- // Paul DiLascia says:
- // "These are similar to, but NOT the same as the equivalent CWnd fns. Don't
- // override unless you're a guru, and even THEN I wouldn't recommend it."
- virtual LRESULT WindowProc (UINT msg, WPARAM wp, LPARAM lp);
- virtual void OnNcPaint (HRGN hUpdateRgn);
- virtual BOOL OnNcActivate (BOOL bActive);
- virtual void OnSetText (LPCTSTR lpText);
- virtual void OnColorChange ();
- };
- #endif