📄 fontex.cpp
字号:
// FontEx.cpp: implementation of the CFontEx class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "drawcli.h"
#include "FontEx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
BOOL CALLBACK AFX_EXPORT
CFontEx::EnumFontFamiliesCallBack(ENUMLOGFONTEX* pelf,
NEWTEXTMETRICEX* /*lpntm*/,
int FontType, LPVOID pThis)
{
CString k=pelf->elfLogFont.lfFaceName;
CFontEx *pFont=(CFontEx *)pThis;
// recherche d'une fonte specifique
if(pFont->m_strFontName!="" &&
pFont->m_strFontName!=pelf->elfLogFont.lfFaceName) return(1);
if(pFont->m_strFontFullName!="")
if(pFont->m_strFontFullName!=pelf->elfFullName) return(1);
if(pFont->m_strFontFullName=="")
if(pelf->elfFullName!=pFont->m_strFontName) return(1);
memmove(pFont->m_pCurrentLogFont,&pelf->elfLogFont,sizeof(LOGFONT));
pFont->m_bFind=true;
return(0);
}
CDC *CFontEx::CreateScreenDC(void)
{
static CDC *pDC=NULL;
HDC hDC;
hDC = ::GetDC(NULL);
pDC = CDC::FromHandle(hDC);
return (pDC);
}
bool CFontEx::GetFont(int nNbPoints,
const char *szFontName,
const char *szFontFullName /*=""*/,
CDC *pDC /*=NULL*/)
{
//
return GetCFont(*this,
nNbPoints,
szFontName,
szFontFullName,
pDC);
}
bool CFontEx::GetCFont(CFont &refCFont,
int nNbPoints,
const char *szFontName,
const char *szFontFullName /*=""*/,
CDC *pDC /*=NULL*/)
{
//
LOGFONT lf;
if(refCFont.m_hObject) refCFont.DeleteObject();
if(GetFont(&lf,nNbPoints,szFontName,szFontFullName,pDC))
return (refCFont.CreateFontIndirect(&lf)==TRUE);
return false;
}
bool CFontEx::GetFont(LOGFONT *plogfont,
int nbpoints,
const char *szFontName,
const char *szFontFullName /*=""*/,
CDC *pDC /*=NULL*/)
{
bool bAutoDC=false;
nbpoints*=10;
m_strFontName=szFontName;
m_strFontFullName=szFontFullName;
m_pCurrentLogFont=plogfont;
m_bFind=false;
if(pDC==NULL)
{
pDC=CreateScreenDC();
bAutoDC=true;
}
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfCharSet = DEFAULT_CHARSET;
if(!m_strFontName.IsEmpty())
strcpy(lf.lfFaceName,m_strFontName);
else m_strFontName="Courier New";
::EnumFontFamiliesEx(pDC->m_hDC, &lf,
(FONTENUMPROC) CFontEx::EnumFontFamiliesCallBack,
(LPARAM)this ,0);
if(m_bFind)
{
plogfont->lfHeight =-MulDiv(nbpoints,pDC->GetDeviceCaps(LOGPIXELSY),72);
plogfont->lfHeight/=10;
if(nbpoints<0) plogfont->lfHeight=abs(plogfont->lfHeight);
plogfont->lfWidth=0;
}
if(bAutoDC) pDC->DeleteDC();
return(m_bFind);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -