Click here to Skip to main content
15,881,898 members
Articles / Desktop Programming / MFC

Font Properties Property Page

Rate me:
Please Sign up or sign in to vote.
3.54/5 (7 votes)
4 Oct 20045 min read 46K   2.6K   20  
Adding the functionality of the ChooseFont() function to a property sheet
#if !defined(AFX_FONTPROPERTIESDIALOG_H__AE4FE5EB_F974_4AE9_8EBE_E80C4979242B__INCLUDED_)
#define AFX_FONTPROPERTIESDIALOG_H__AE4FE5EB_F974_4AE9_8EBE_E80C4979242B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FontPropertiesDialog.h : header file
//

#define FPD_DISPLAY_ALL     0xFFF00000
#define FPD_DISPLAY_SCRIPT  0x80000000
#define FPD_DISPLAY_EFFECTS 0x40000000

/////////////////////////////////////////////////////////////////////////////
// CFontPropertiesDialog dialog

class CFontPropertiesDialog : public CDialog
{
	// Owner drawn preview window
	class CPreviewButton : public CButton
	{
	public:
		virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
		void SetColors(COLORREF clrText, COLORREF clrBkGnd)
			{ m_clrText = clrText; m_clrBkGnd = clrBkGnd; }

		afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	protected:
		COLORREF m_clrText, m_clrBkGnd;
		DECLARE_MESSAGE_MAP()
	};
	// Owner drawn combo box for font face names
	class CFontCombo : public CComboBox
	{
	public:
		void Init(int nStaticHeight, int nItemHeight, DWORD dwEnumFlags);
		virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
		virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
		virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
	protected:
		CImageList m_img;
		int m_nItemHeight;
		DWORD m_dwEnumFlags;
	};
public:
// Construction
	CFontPropertiesDialog(CWnd* pParent = NULL);   // standard constructor


	// The following enumeration flags can be used in any combination in Create:
	// RASTER_FONTTYPE, DEVICE_FONTTYPE, TRUETYPE_FONTTYPE
	// In addition, display element flags may be combined here aswell:
	// FPD_DISPLAY_SCRIPT, FPD_DISPLAY_EFFECTS or FPD_DISPLAY_ALL
	BOOL Create(DWORD dwEnumFlags = -1, CWnd* pParentWnd = NULL);

// Dialog Data
	//{{AFX_DATA(CFontPropertiesDialog)
	enum { IDD = IDD_FONTPROPERTIES_DIALOG };
	CComboBox	m_wndScript;
	CButton	m_wndStrikeoutCheck;
	CButton	m_wndUnderlineCheck;
	CComboBox	m_wndFontStyle;
	CComboBox	m_wndFontSize;
	CFontCombo	m_wndFontFace;
	//}}AFX_DATA
	CPreviewButton m_wndPreview;

	void SetLogFont(const LOGFONT *lpLogFont);
	const LOGFONT& GetLogFont() { m_font.GetLogFont(&m_lf); return m_lf; }

	void SetTextColor(COLORREF clr) { m_clrPreviewText = clr; }
	COLORREF GetTextColor() const { return m_clrPreviewText; }

	void SetBkGndColor(COLORREF clr) { m_clrPreviewBkGnd = clr; }

	DWORD GetEnumFlags() const { return m_dwEnumFlags; }

	enum EnumType
	{
		FontFace,
		FontSize,
		FontStyle,
		FontScript
	} m_et;

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFontPropertiesDialog)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual void LayOutControls();
	void AddUnreportedStyles(LOGFONT* lplf);
	void UpdatePreview();
	void InitFontFaceEdit();
	CFont m_font;
	LOGFONT m_lf;
	COLORREF m_clrPreviewText;
	COLORREF m_clrPreviewBkGnd;
	CString m_strLastSetSize;
	CString m_strLastSetStyle;

	DWORD m_dwEnumFlags;

	// Generated message map functions
	//{{AFX_MSG(CFontPropertiesDialog)
	virtual BOOL OnInitDialog();
	afx_msg void OnFontButton();
	afx_msg void OnSelchangeFontfaceList();
	afx_msg void OnSelchangeFontStyleList();
	afx_msg void OnSelchangeFontSizeList();
	afx_msg void OnStrikeoutCheck();
	afx_msg void OnUnderlineCheck();
	afx_msg void OnEditchangeFontSizeList();
	afx_msg void OnEditchangeFontStyleList();
	afx_msg void OnEditchangeFontFaceList();
	afx_msg void OnSelchangeScriptCombo();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FONTPROPERTIESDIALOG_H__AE4FE5EB_F974_4AE9_8EBE_E80C4979242B__INCLUDED_)

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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

Comments and Discussions