WEB开发网
开发学院软件开发VC 一个简单字体察看器的实现 阅读

一个简单字体察看器的实现

 2010-07-11 20:44:29 来源:WEB开发网   
核心提示:注意在 Group Box 内部有一个 Static Text 和 Group Box 内部一样大,用来显示文字,一个简单字体察看器的实现(2),为控件添加变量: 对象 名称 类别 类型

注意在 Group Box 内部有一个 Static Text 和 Group Box 内部一样大,用来显示文字。

为控件添加变量:

对象 名称 类别 类型
IDC_DISPLAY m_ctlDisplay

m_strDiaplay
Control

Value
Cstatic

CString
IDC_LFONTS m_ctlFontList

m_strFontName
Control

Value
ClistBox

CString
IDC_EENTERED m_strSampText Value CString

为 IDC_EEXIT 添加事件代码:(注:斜体部分为输入内容):

void CFontsViewDlg::OnBnClickedBexit()
{
   // TODO: 在此添加控件通知处理程序代码
   OnOK();
}

好了,到此为止,基本的框架已经建好了,下一步需要建立字体列表。首先要添加回调函数来获得每个字体列表:

// FontsViewDlg.h : 头文件
//
#pragma once
#include "afxwin.h"
int CALLBACK MyEnumFontProc(ENUMLOGFONTEX* lpelf,NEWTEXTMETRICEX* lpntm,DWORD nFontType,long lParam);

然后再向FontsViewDlg.cpp中添加回调函数的定义:

int CALLBACK MyEnumFontProc(ENUMLOGFONTEX* lpelf,NEWTEXTMETRICEX* lpntm,DWORD nFontType,long lParam)
{
   CFontsViewDlg* pWnd=(CFontsViewDlg*) lParam;
   if(pWnd)
   {
     pWnd->m_ctlFontList.AddString(lpelf->elfLogFont.lfFaceName);
     return 1;
   }
   return 0;
}

我们还要构建一个函数来获取操作系统中的字体列表:选择Class View面板,选择CfontsViewDlg类,添加函数,函数名设为FillFontList,访问类型Private。

void CFontsViewDlg::FillFontList(void)
{
   int iCurCount;
   CString strCurFont;
   CString strPrevFont="";
   LOGFONT lf;
   lf.lfCharSet=DEFAULT_CHARSET;
   lf.lfFaceName[0]=NULL;
   lf.lfPitchAndFamily=0;
   m_ctlFontList.ResetContent();
   CClientDC dc(this);
   ::EnumFontFamiliesEx((HDC) dc,&lf,(FONTENUMPROC) MyEnumFontProc,(LPARAM) this,0);
   for (iCurCount=m_ctlFontList.GetCount();iCurCount > 0;iCurCount--)
   {
     m_ctlFontList.GetText((iCurCount-1),strCurFont);
     if (strCurFont==strPrevFont)
     {
       m_ctlFontList.DeleteString((iCurCount-1));
     }
     else
     {
       strPrevFont=strCurFont;
     }
   }
}

上一页  1 2 3 4  下一页

Tags:一个 简单 字体

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接