BOOL CREADTEST1Dlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here
SetWindowPos(this,0,0,240,320,SWP_NOZORDER);
m_DlgbmpBackground.LoadBitmap(IDB_BITMAP1);
//改变编辑框中的字体
CFont myfont,*oldfont;
LOGFONT font;
memset(&font,0,sizeof(LOGFONT));
font.lfHeight=30;
font.lfWeight=600;
font.lfItalic=TRUE; myfont.CreateFontIndirect(&font);
m_EXEDIT.SetFont(& myfont);...............................
}
重载编辑框派生类中的OnEraseBkgnd来画文字的下划线。BOOL CEXEDIT::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//初始化DC
pDC->SetTextColor(RGB(0,0,0));
pDC->SelectObject(GetFont());
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
GetClientRect(&m_EditRect); //添加数学本风格
//设置横线之间的间隔
int y=tm.tmHeight+tm.tmExternalLeading;
int i;
//绘制横线
for (i=y;i<m_EditRect.bottom;i+=y)
{
pDC->MoveTo(0,i);
pDC->LineTo(m_EditRect.right,i);
}
。。
}其中m_EXEDIT是我自己写的CEDIT的派生类CEXEDIT的类对象。在派生类对象中我要给编辑框画上类似数学本中的那种文字下面的下划线。
但是在对话框初始化时自定义字体之后,编辑框中的下划线间隔和文字的高度不匹配。
即 y=tm.tmHeight+tm.tmExternalLeading;与font.lfHeight=30;大小之间的差距很大。我改变font.lfHeight的大小,文字大小并没有改变,只是改变了文字光标的大小,我很是郁闷,不知道如何处理。请哪位能够帮帮忙,指点一二。先谢谢大家了!
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here
SetWindowPos(this,0,0,240,320,SWP_NOZORDER);
m_DlgbmpBackground.LoadBitmap(IDB_BITMAP1);
//改变编辑框中的字体
CFont myfont,*oldfont;
LOGFONT font;
memset(&font,0,sizeof(LOGFONT));
font.lfHeight=30;
font.lfWeight=600;
font.lfItalic=TRUE; myfont.CreateFontIndirect(&font);
m_EXEDIT.SetFont(& myfont);...............................
}
重载编辑框派生类中的OnEraseBkgnd来画文字的下划线。BOOL CEXEDIT::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//初始化DC
pDC->SetTextColor(RGB(0,0,0));
pDC->SelectObject(GetFont());
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
GetClientRect(&m_EditRect); //添加数学本风格
//设置横线之间的间隔
int y=tm.tmHeight+tm.tmExternalLeading;
int i;
//绘制横线
for (i=y;i<m_EditRect.bottom;i+=y)
{
pDC->MoveTo(0,i);
pDC->LineTo(m_EditRect.right,i);
}
。。
}其中m_EXEDIT是我自己写的CEDIT的派生类CEXEDIT的类对象。在派生类对象中我要给编辑框画上类似数学本中的那种文字下面的下划线。
但是在对话框初始化时自定义字体之后,编辑框中的下划线间隔和文字的高度不匹配。
即 y=tm.tmHeight+tm.tmExternalLeading;与font.lfHeight=30;大小之间的差距很大。我改变font.lfHeight的大小,文字大小并没有改变,只是改变了文字光标的大小,我很是郁闷,不知道如何处理。请哪位能够帮帮忙,指点一二。先谢谢大家了!
CFont *pfont = m_ctrShowMessage.GetFont();
pfont-> GetLogFont( &logfont );
logfont.lfHeight =logfont.lfHeight * 1.5;
logfont.lfWidth = logfont.lfWidth * 1.5;
CFont font;
font.CreateFontIndirect(&logfont);
m_ctrShowMessage.SetFont(&font);
我觉得问题不应该在这里吧!
你看下这个网址,我以前也遇到过字体大小显示问题,就是看这个解决的,希望能帮助你