Click here to Skip to main content
15,886,756 members
Articles / Desktop Programming / MFC

XMonoFontDialog - Customizing CFontDialog Part II: Selecting Monospaced Fonts

Rate me:
Please Sign up or sign in to vote.
4.88/5 (19 votes)
22 Oct 2008CPOL8 min read 34.2K   724   20  
XMonoFontDialog is a CFontDialog clone that is customized for selecting monospaced fonts. A custom label has been added to the dialog that informs the user when a monospaced font is selected in the combobox, and bold typeface is used to highlight monospaced fonts in the combobox list.
// XMonoFontListCombo.h
//
// Author:  Hans Dietrich
//          hdietrich@gmail.com
//
// License:
//     This software is released into the public domain.  You are free to use
//     it in any way you like, except that you may not sell this source code.
//
//     This software is provided "as is" with no expressed or implied warranty.
//     I accept no liability for any damage or loss of business that this 
//     software may cause.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef XMONOFONTLISTCOMBO_H
#define XMONOFONTLISTCOMBO_H

#include "XMonoFontListComboEdit.h"

//=============================================================================
class CXMonoFontListCombo : public CComboBox
//=============================================================================
{
// Construction
public:
	CXMonoFontListCombo();
	virtual ~CXMonoFontListCombo();

// Attributes
public:
	CDC *		m_pDC;
	DWORD		m_dwFontFilter;
	CXMonoFontListComboEdit	m_edit;

	CXMonoFontListCombo&	SetBold(BOOL bBold)
							{
								if (IsWindow(m_edit.m_hWnd))
								{
									m_edit.SetBold(bBold);
									m_edit.RedrawWindow();
								}
								return *this;
							}
	CXMonoFontListCombo&	SetFont(LOGFONT& lf);
	CXMonoFontListCombo&	SetFontFilter(DWORD dwFontFilter) 
							{ m_dwFontFilter = dwFontFilter; return *this; }
	CXMonoFontListCombo&	ShowMonospacedAsBold(BOOL bShow) 
							{ m_bShowMonospacedAsBold = bShow; return *this; }

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CXMonoFontListCombo)
public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
	virtual void PreSubclassWindow();
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
protected:
	CImageList	m_FontType;	
	CFont		m_BoldFont;
	BOOL		m_bShowMonospacedAsBold;
	LOGFONT		m_lfInitial;
	LOGFONT		m_lfCurrent;
	int			m_CurIndex;

	void CreateFontTypeImages();

	// Generated message map functions
protected:
	//{{AFX_MSG(CXMonoFontListCombo)
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

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

#endif //XMONOFONTLISTCOMBO_H

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
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions