fontcombo.cpp

来自「C++编程100例」· C++ 代码 · 共 62 行

CPP
62
字号
// FontCombo.cpp : implementation file
//

#include "stdafx.h"
#include "FontChoose.h"
#include "FontCombo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFontCombo

CFontCombo::CFontCombo()
{
}

CFontCombo::~CFontCombo()
{
}


BEGIN_MESSAGE_MAP(CFontCombo, CComboBox)
	//{{AFX_MSG_MAP(CFontCombo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontCombo message handlers

void CFontCombo::PreSubclassWindow() 
{
	ProcessFonts();
	CComboBox::PreSubclassWindow();
}
void CFontCombo::ProcessFonts(void)
{
	POSITION pos;
	LOGFONT lf;
	memset( (void *)&lf,0,sizeof(lf) );
	lf.lfCharSet=DEFAULT_CHARSET;

	m_FontList.RemoveAll();
	::EnumFontFamiliesEx( GetParent()->GetDC()->GetSafeHdc(), &lf, (FONTENUMPROC) CFontCombo::EnumFontFamiliesCallBack, (LPARAM) &m_FontList, 0);
	ResetContent();
	for(pos = m_FontList.GetHeadPosition(); pos != NULL;)
		AddString(m_FontList.GetNext(pos));
}

int CALLBACK CFontCombo::EnumFontFamiliesCallBack(ENUMLOGFONT *lpelfe,NEWTEXTMETRIC *lpntme,int FontType,LPARAM lParam)
{
	if( strlen((char*)lpelfe->elfFullName) != 0 )
	{
		CStringList* list = (CStringList*) lParam;
		list->AddTail((char*)lpelfe->elfFullName);
	}
	return 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?