Click here to Skip to main content
15,879,535 members
Articles / Multimedia / GDI

Custom Captions (Including Multi-line Captions)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
15 Jul 2000CPOL 240K   6.8K   63  
Simple customised Window captions, including multi-line captions
#ifndef _SINGLELINECAPTION_H
#define _SINGLELINECAPTION_H

////////////////////////////////////////////////////////////////
//
// class CSingleLineCaption
//
// 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 single line caption layouts.
// 
//   If you are drawing custom caption buttons, you must handle WM_NCLBUTTONDOWN & co.
//   yourself. CSingleLineCaption 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 "Caption.h"

// forward declarations
class CCaptionBackground;
class CCaptionTextAttributes;


class AFX_EXT_CLASS CSingleLineCaption : public CCaption 
{
public:
 	CSingleLineCaption();

	BOOL Install(CWnd* pWnd);
	void SetIcon(HICON hIcon = 0);	 // For dialogs

protected:
	HICON m_hIcon;

	DECLARE_DYNAMIC(CSingleLineCaption);

	// Helpers
	//
	int	GetIconWidth();

	// Override these in derived classes if necessary
	//
	virtual int	PaintIcon(CDC* pDC = 0);

	// 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 BOOL	OnNcActivate	(BOOL bActive);
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions