首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC设立LOGFONT后字体没有变化

2013-04-09 
VC设置LOGFONT后字体没有变化OnCreate:m_strFont.Format(%s,FontWantedByUser(font_index))LOGFONT lf

VC设置LOGFONT后字体没有变化


OnCreate:
m_strFont.Format("%s",FontWantedByUser(font_index));

LOGFONT lf;
pElement->GetLogFont(&lf);
_tcscpy(lf.lfFaceName, m_strFont);

pElement->SetFont(&lf);

void CxStatic::SetFont(LOGFONT *pLogFont, BOOL bRedraw /*= TRUE*/)
{
ASSERT(pLogFont);
if (!pLogFont)
return;

if (m_font.GetSafeHandle())
m_font.DeleteObject();

LOGFONT lf = *pLogFont;

m_font.CreateFontIndirect(&lf);

if (bRedraw)
RedrawWindow();
}

m_strFont如果是宋体或者隶体方正舒体等中文字体都没有问题,有几个英文字体如Batang,PMingLiU等,可以正常显示,但是换成Arial或者Times New Roman等大多数英文字体,就完全没有变化,debug跟了一下,发现LOGFONT的设置也没有问题,lfFaceName等参数也是正常的,请问这是什么原因?

我特意新建了一个dlg的程序,看了一下,也是一样。我在其他电脑上也试过,很多英文字体都没有变化

CDC *dc = this->GetDC();
CFont* pFont = dc->GetCurrentFont();
LOGFONT logFont ;
pFont->GetLogFont(&logFont);
strncpy(logFont.lfFaceName,"Arial",LF_FACESIZE-1);
logFont.lfFaceName[LF_FACESIZE-1]=0;
logFont.lfHeight = -32;
HFONT hFont = CreateFontIndirect(&logFont); 
dc->SelectObject(hFont);
dc->TextOut(100,100,"bbbbbbb");

[解决办法]
放全局变量 看看

热点排行