【发布时间】:2011-03-18 00:16:32
【问题描述】:
必须关闭所有对话框控件的默认字体的“ClearType”属性。可以通过设置为一个控件做到这一点
logfont.lfQuality = ANTIALIASED_QUALITY
有很多建议如何对模态对话框(http://neelaakash.wordpress.com/2007/12/31/change-default-dialog-font-of-cdialog/ 和其他)执行相同的操作,但对于非模态对话框应该这样做(使用 new 和 Create(...) 方法实例化)。我自己也试过这样做:
覆盖'Create'方法,并修改对话框模板:
BOOL CActivationChildDialogLicenseInfo::Create(UINT nIDTemplate,
CWnd* pParentWnd)
{
CDialogTemplate dlt;
int nResult;
// load dialog template
if (!dlt.Load(MAKEINTRESOURCE(nIDTemplate))) return -1;
// set your own font, for example “Arial”, 10 pts.
dlt.SetFont(L"Arial", 12);
// get pointer to the modified dialog template
LPSTR pdata = (LPSTR)GlobalLock(dlt.m_hTemplate);
// let MFC know that you are using your own template
m_lpszTemplateName = NULL;
InitModalIndirect(pdata);
// display dialog box
nResult = CActivationChildDialog::Create(nIDTemplate, pParentWnd);
// unlock memory object
GlobalUnlock(dlt.m_hTemplate);
return nResult ;
}
似乎这个方法什么都不做(它被称为,我已经通过在里面放置断点进行了检查)。 我试过打电话
nResult = CActivationChildDialog::Create(NULL, pParentWnd);
...但是得到了很多 ASSERT。
我也尝试过覆盖“OnSetFont”方法:
void CActivationChildDialogLicenseInfo::OnSetFont(CFont *pFont)
{
CActivationChildDialog::OnSetFont(pFont);
LOGFONT logfont;
pFont->GetLogFont(&logfont);
LOGFONT logfont2=logfont;
pFont->DeleteObject();
logfont2.lfItalic = true;
logfont2.lfQuality = ANTIALIASED_QUALITY;
pFont->CreateFontIndirect(&logfont2);
}
这会在运行时导致 ASSERT 并导致使用非常大的字体(丢失默认字体设置,不接受新的指定设置)...我不知道为什么。
请告知,如何更改将被所有对话框控件“继承”的默认对话框字体?
非常感谢。
【问题讨论】: