⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontviewdlg.cpp

📁 这些源代码
💻 CPP
字号:
// FontViewDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FontView.h"
#include "FontViewDlg.h"

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

struct FONTDATA
	{
	CString 		strFont;
	CComboBoxEx*	FontBox;
	CFontViewDlg*	Papa;
	};

/////////////////////////////////////////////////////////////////////////////
// CFontViewDlg dialog


CFontViewDlg::CFontViewDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFontViewDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFontViewDlg)
	m_FontViewChar = _T("");
	m_FontList = _T("");
	m_MouseDecimal = _T("");
	m_MouseHex = _T("");
	m_MouseOctal = _T("");
	m_AbcA = _T("");
	m_AbcB = _T("");
	m_AbcC = _T("");
	m_AbcfA = _T("");
	m_AbcfB = _T("");
	m_AbcfC = _T("");
	m_FloatWidth = _T("");
	m_IntWidth = _T("");
	//}}AFX_DATA_INIT
	m_strFont = _T("Times New Roman");
	m_Title.Empty ();
	m_chCurrent = 0;
}

CFontViewDlg::~CFontViewDlg()
{
}

void CFontViewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFontViewDlg)
	DDX_Control(pDX, IDC_STATIC_SAMPLETEXT, m_SampleText);
	DDX_Control(pDX, IDC_COMBO_FONTS, m_FontBox);
	DDX_Control(pDX, IDC_EDIT_FONTVIEW, m_FontView);
	DDX_Control(pDX, IDC_STATIC_FONTVIEWCHAR, m_MouseSelWin);
	DDX_Text(pDX, IDC_STATIC_FONTVIEWCHAR, m_FontViewChar);
	DDX_CBString(pDX, IDC_COMBO_FONTS, m_FontList);
	DDX_Text(pDX, IDC_STATIC_MOUSEDECIMAL, m_MouseDecimal);
	DDX_Text(pDX, IDC_STATIC_MOUSEHEX, m_MouseHex);
	DDX_Text(pDX, IDC_STATIC_MOUSEOCTAL, m_MouseOctal);
	DDX_Text(pDX, IDC_METRIC_ABCA, m_AbcA);
	DDX_Text(pDX, IDC_METRIC_ABCB, m_AbcB);
	DDX_Text(pDX, IDC_METRIC_ABCC, m_AbcC);
	DDX_Text(pDX, IDC_METRIC_ABCFA, m_AbcfA);
	DDX_Text(pDX, IDC_METRIC_ABCFB, m_AbcfB);
	DDX_Text(pDX, IDC_METRIC_ABCFC, m_AbcfC);
	DDX_Text(pDX, IDC_METRIC_FLOATWIDTH, m_FloatWidth);
	DDX_Text(pDX, IDC_METRIC_INTEGERWIDTH, m_IntWidth);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFontViewDlg, CDialog)
	//{{AFX_MSG_MAP(CFontViewDlg)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_CBN_SELCHANGE(IDC_COMBO_FONTS, OnSelchangeComboFonts)
	ON_NOTIFY(CBEN_GETDISPINFO, IDC_COMBO_FONTS, OnGetdispinfoComboFonts)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_USER+40, OnUser)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontViewDlg message handlers

BOOL CFontViewDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	CClientDC dc (this);
//
//	Set up the image list
	m_pImages.Create (16, 16, ILC_MASK, 2, 2);
	HICON hIcon = AfxGetApp()->LoadIcon (IDI_ICON_TRUETYPE);
	m_pImages.Add (hIcon);
	hIcon = AfxGetApp()->LoadIcon (IDI_ICON_BITFONT);
	m_pImages.Add (hIcon);
	m_FontBox.SetImageList (&m_pImages);

	FONTDATA fd;
	fd.FontBox = &m_FontBox;
	fd.strFont = m_strFont;
	fd.Papa = this;
	::EnumFontFamilies ((HDC) dc, NULL, (FONTENUMPROC) AddFontName, (LPARAM) &fd);

	CString strFont = _T("Times New Roman");
	int nCount = m_FontData.GetCount ();
	POSITION pos = m_FontData.GetHeadPosition ();
	CFontData font = m_FontData.GetHead ();
	for (int n = 0; pos != NULL; ++n)
	{
		font = m_FontData.GetNext (pos);
		COMBOBOXEXITEM cbi;
		memset (&cbi, '\0', sizeof (COMBOBOXEXITEM));
		cbi.iItem = n;
		cbi.mask = CBEIF_IMAGE | CBEIF_TEXT | CBEIF_SELECTEDIMAGE | CBS_SORT;
		cbi.iImage = font.m_nIcon;
		cbi.iSelectedImage = font.m_nIcon;
		cbi.pszText = (char *) (LPCSTR) font.m_strName;
		m_FontBox.InsertItem (&cbi);
		if (!font.m_strName.CompareNoCase (strFont))
			m_FontBox.SetCurSel (n);
	}
	m_FontData.RemoveAll ();

	m_MouseSelWin.SetBkgndColor (0x00ffffff);
	GetWindowText (m_Title);
	RECT rcFontView = {0, 0, 0, 0};
	RECT rcClient = {0, 0, 0, 0};
	CWnd *cwFontView;
	if ((cwFontView = GetDlgItem(IDC_EDIT_FONTVIEW)) != NULL)
	{
		cwFontView->GetWindowRect(&rcFontView);
	}
	GetClientRect (&rcClient);
	m_FontView.SetWindowRect (rcClient, rcFontView);
	m_FontView.SetBkgndColor (0x00ffffff);
	m_SampleText.SetWindowText (_T("The quick red fox jumps over the lazy dog's back. RY testing"));
	SetFont (m_strFont);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}

void CFontViewDlg::SetCurrentSel (UINT sel)
{
	m_FontView.SetCharSelection(sel);
}

void CFontViewDlg::SetMouseChar(UINT ch)
{
	if (!ch)
	{
		m_FontViewChar.Empty ();
	}
	else
	{
		m_MouseOctal.Format ("%o", ch);
		m_MouseDecimal.Format ("%d", ch);
		m_MouseHex.Format ("%X", ch);
		m_FontViewChar = ch;
		if (ch == '&')
			m_FontViewChar += ch;
	}
	UpdateData (false);
}

void CFontViewDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
RECT	r;
POINT	ptPoint;

	m_FontView.GetWindowRect (&r);
	ptPoint.x = point.x;
	ptPoint.y = point.y;
	ClientToScreen(&ptPoint);
	CPoint vPoint (ptPoint);
	ptPoint.x -= r.left;
	ptPoint.y -= r.top;
	CPoint clientPoint (ptPoint);
	CRect cr (r);
	if (cr.PtInRect (vPoint))
		m_FontView.OnLButtonDown (nFlags, clientPoint);
	else
		CDialog::OnLButtonDown(nFlags, point);
}

void CFontViewDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
RECT	r;
POINT	ptPoint;

	m_FontView.GetWindowRect (&r);
	ptPoint.x = point.x;
	ptPoint.y = point.y;
	ClientToScreen(&ptPoint);
	CPoint vPoint (ptPoint);
	ptPoint.x -= r.left;
	ptPoint.y -= r.top;
	CPoint clientPoint (ptPoint);
	CRect cr (r);
	if (cr.PtInRect (vPoint))
		m_FontView.OnMouseMove (nFlags, clientPoint);
	else
	{
		m_FontViewChar = '\0';
		UpdateData (false);
		m_FontView.m_uiMouseSelection = 0;
		CDialog::OnMouseMove(nFlags, point);
	}
}

void CFontViewDlg::SetFont(CString &strFont)
{
	m_fontMouse.DeleteObject ();
	m_fontMouse.CreatePointFont (300, strFont);
	m_fontSample.DeleteObject ();
	m_fontSample.CreatePointFont (110, strFont);
	m_MouseSelWin.SetFont (&m_fontMouse, true);
	m_SampleText.SetFont (&m_fontSample, true);
	CString Title = m_Title + " - " + strFont;
	SetWindowText (Title);
	m_FontView.SetFont (strFont);
	OnUser ((WPARAM) WM_USER+41, (LPARAM) m_chCurrent);
}

void CFontViewDlg::OnUser (WPARAM wparam, LPARAM lparam)
{
	switch (wparam)
	{
		case WM_USER + 40:
			m_FontViewChar = (char) lparam;
			SetMouseChar (lparam);
			UpdateData (false);
			m_MouseSelWin.Invalidate ();
			break;
		case WM_USER + 41:
			if (!lparam)
				break;
			m_chCurrent = (char) lparam;
			m_AbcA.Format ("%d", m_FontView.m_abc[lparam].abcA);
			m_AbcB.Format ("%d", m_FontView.m_abc[lparam].abcB);
			m_AbcC.Format ("%d", m_FontView.m_abc[lparam].abcC);
			m_AbcfA.Format ("%f", m_FontView.m_abcf[lparam].abcfA);
			m_AbcfB.Format ("%f", m_FontView.m_abcf[lparam].abcfB);
			m_AbcfC.Format ("%f", m_FontView.m_abcf[lparam].abcfC);
			m_FloatWidth.Format ("Float Width: %f", m_FontView.m_fWidths[lparam]);
			m_IntWidth.Format ("Integer Width: %d", m_FontView.m_nWidths[lparam]);
			UpdateData (false);
			break;
	}
}

int CALLBACK CFontViewDlg::AddFontName (ENUMLOGFONT *lpelfe, NEWTEXTMETRIC *lpntme, int FontType, LPARAM lParam)
{

static int nItem = 0;

	FONTDATA *fd = (FONTDATA *) lParam;
	CFontData font;
	CFontViewDlg *bar = fd->Papa;
	font.m_strName = lpelfe->elfLogFont.lfFaceName;
	switch (FontType)
	{
		case RASTER_FONTTYPE:
		case DEVICE_FONTTYPE:
			font.m_nIcon = 1;
			break;
		case TRUETYPE_FONTTYPE:
			font.m_nIcon = 0;
			break;
	}
	POSITION pos;
	if (bar->m_FontData.GetCount () == 0)
	{
		bar->m_FontData.AddHead (font);
		return (TRUE);
	}
	pos = bar->m_FontData.GetHeadPosition ();
	CFontData data;
	int nCount = bar->m_FontData.GetCount ();
	data = bar->m_FontData.GetHead ();
	for (int n = 0; n < nCount; ++n)
	{
		int nResult = data.m_strName.CompareNoCase (font.m_strName);
		if (nResult > 0)
			break;
		data = bar->m_FontData.GetNext (pos);
	}
	if (pos == NULL)
	{
		if (font.m_strName.CompareNoCase (data.m_strName) < 0)
            {
				pos = bar->m_FontData.GetTailPosition ();
                bar->m_FontData.InsertBefore (pos, font);
            }
            else
                bar->m_FontData.AddTail (font);
			return (TRUE);
	}
	bar->m_FontData.GetPrev (pos);
	bar->m_FontData.InsertBefore (pos, font);
	return (TRUE);
}

void CFontViewDlg::OnSelchangeComboFonts() 
{
	CString strNewFont;
	int nIndex = m_FontBox.GetCurSel ();
	m_FontBox.GetLBText (nIndex, strNewFont);
	if (strNewFont == m_strFont)
		return;
	m_strFont = strNewFont;
	SetFont (strNewFont);
	PrevDlgCtrl();
}

void CFontViewDlg::OnGetdispinfoComboFonts(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NMCOMBOBOXEX *pData = (NMCOMBOBOXEX *) pNMHDR;
	COMBOBOXEXITEM *pItem = &pData->ceItem;
	if (pItem->mask & CBEIF_TEXT)
	{
		POSITION pos = m_FontData.FindIndex (pItem->iItem);
		CFontData cfd = m_FontData.GetAt (pos);
		::lstrcpy (pItem->pszText, (LPCSTR) cfd.m_strName);
	}
	*pResult = 0;
}

⌨️ 快捷键说明

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