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

📄 fontsview.cpp

📁 这些源代码
💻 CPP
字号:
// FontsView.cpp : implementation of the CFontsView class
//

#include "stdafx.h"
#include "Fonts.h"

#include "FontsDoc.h"
#include "FontsView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFontsView

IMPLEMENT_DYNCREATE(CFontsView, CListView)

BEGIN_MESSAGE_MAP(CFontsView, CListView)
	//{{AFX_MSG_MAP(CFontsView)
	ON_WM_DESTROY()
	ON_COMMAND(ID_LIST_LARGEICON, OnListLargeicon)
	ON_COMMAND(ID_LIST_LIST, OnListList)
	ON_COMMAND(ID_LIST_REPORT, OnListReport)
	ON_COMMAND(ID_LIST_SMALLICON, OnListSmallicon)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontsView construction/destruction

CFontsView::CFontsView()
{
	// TODO: add construction code here

}

CFontsView::~CFontsView()
{
}

BOOL CFontsView::PreCreateWindow(CREATESTRUCT& cs)
{
	cs.style &= ~LVS_TYPEMASK;
	cs.style |= LVS_ICON | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_NOCOLUMNHEADER;

	return CListView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFontsView drawing

void CFontsView::OnDraw(CDC* pDC)
{
	CFontsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CFontsView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();

	LV_COLUMN	lc;
	CRect rc;
	GetClientRect (&rc);
	memset (&lc, '\0', sizeof (LV_COLUMN));
	lc.mask = LVCF_WIDTH;
	lc.cx = rc.right;
	lc.iSubItem = 0;
	GetListCtrl().InsertColumn (0, &lc);

	if (m_SmallImages.m_hImageList == NULL)
		m_SmallImages.Create (16, 16, ILC_MASK, 2, 2);
	if (m_LargeImages.m_hImageList == NULL)
		m_LargeImages.Create (32, 32, ILC_MASK, 2, 2);
	HICON hIcon = AfxGetApp()->LoadIcon (IDI_TRUETYPEFONTS);
	m_SmallImages.Add (hIcon);
	m_LargeImages.Add (hIcon);
	DeleteObject (hIcon);
	hIcon = AfxGetApp()->LoadIcon (IDI_PRINTERFONTS);
	m_SmallImages.Add (hIcon);
	m_LargeImages.Add (hIcon);
	DeleteObject (hIcon);
	GetListCtrl().SetImageList (&m_SmallImages, LVSIL_SMALL);
	GetListCtrl().SetImageList (&m_LargeImages, LVSIL_NORMAL);
	CWindowDC dc (this);
	::EnumFontFamilies ((HDC) dc, NULL, (FONTENUMPROC) AddFontName, (LPARAM) this);

}

/////////////////////////////////////////////////////////////////////////////
// CFontsView printing

BOOL CFontsView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CFontsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CFontsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CFontsView diagnostics

#ifdef _DEBUG
void CFontsView::AssertValid() const
{
	CListView::AssertValid();
}

void CFontsView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

CFontsDoc* CFontsView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFontsDoc)));
	return (CFontsDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFontsView message handlers

int CALLBACK CFontsView::AddFontName(ENUMLOGFONT *lpelfe, NEWTEXTMETRIC *lpntme, int FontType, LPARAM lParam)
{
static int nItem = 0;

	CFontsView *fv = (CFontsView *) lParam;
	CListCtrl &FontList = fv->GetListCtrl();
	LV_ITEM lvi;
	memset (&lvi, '\0', sizeof (LV_ITEM));
	lvi.iItem = nItem++;
	lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_INDENT;
//	lvi.iIndent = 3;
	lvi.iIndent = 0;
	switch (FontType)
	{
		case TRUETYPE_FONTTYPE:
			lvi.iImage = 0;
			break;
		case RASTER_FONTTYPE:
		case DEVICE_FONTTYPE:
		default:
			lvi.iImage = 1;
			break;
	}
	lvi.pszText = lpelfe->elfLogFont.lfFaceName;
	lvi.iSubItem = 0;
	FontList.InsertItem (&lvi);
	return (TRUE);
}

void CFontsView::OnDestroy() 
{
	CListView::OnDestroy();
	m_SmallImages.DeleteImageList ();
	m_LargeImages.DeleteImageList ();
}

void CFontsView::OnListLargeicon() 
{
	GetListCtrl().ModifyStyle (LVS_SMALLICON | LVS_LIST | LVS_REPORT, LVS_ICON, TRUE);
}

void CFontsView::OnListList() 
{
	GetListCtrl().ModifyStyle (LVS_SMALLICON | LVS_REPORT | LVS_ICON, LVS_LIST, TRUE);
}

void CFontsView::OnListReport() 
{
	GetListCtrl().ModifyStyle (LVS_SMALLICON | LVS_LIST | LVS_ICON, LVS_REPORT, TRUE);
}

void CFontsView::OnListSmallicon() 
{
	GetListCtrl().ModifyStyle (LVS_REPORT | LVS_LIST | LVS_ICON, LVS_SMALLICON, TRUE);
}

⌨️ 快捷键说明

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