VC中如何将CFontDialog的值赋值给CFont
现在有个程序,用CFontDialog对话框选择字体,然后用LOGFONT接收字体,在把字体信息赋值给CFont类的一个对象,求代码,求大侠指导...
现在有个程序,用CFontDialog对话框选择字体,然后用LOGFONT接收字体,在把字体信息赋值给CFont类的一个对象,求代码,求大侠指导
展开
3个回答
展开全部
参考以下代码:
VC:CFontDialog(CClientDC 、GetDeviceCaps()、memset、LOGFONT、memcpy、CFont、SelectObject() 、IsStrikeOut())
//CFontDialog( LPLOGFONT lplfInitial = NULL, DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );
// Show the font dialog with 12 point "Times New Roman" as the
// selected font.
/* LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
CClientDC dc(this);
lf.lfHeight = -MulDiv(12, dc.GetDeviceCaps(LOGPIXELSY), 72);
strcpy(lf.lfFaceName, "Times New Roman");
CFontDialog dlg(&lf);
dlg.DoModal();*/
/*
CFontDialog dlg;
if (dlg.DoModal() == IDOK)
{
// Create the font using the selected font from CFontDialog.
LOGFONT lf;
memcpy(&lf, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
CFont font;
VERIFY(font.CreateFontIndirect(&lf));
// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);
// Done with the font. Delete the font object.
font.DeleteObject();
}*/
CString fontmessage="";
CFontDialog dlg;
if( IDOK==dlg.DoModal())
{
fontmessage="字体名称:";
fontmessage+=dlg.GetFaceName();
if(1==dlg.IsStrikeOut())
fontmessage+="字体有删除线";
else
fontmessage+="字体没有删除线";
if(1==dlg.IsUnderline())
fontmessage+="字体有下划线";
else
fontmessage+="字体没有下划线";
if(1==dlg.IsBold())
fontmessage+="字体被加粗";
else
fontmessage+="字体没有被加粗";
if(1==dlg.IsItalic())
fontmessage+="字体是斜体";
else
fontmessage+="字体不是斜体";
AfxMessageBox(fontmessage);
}
VC:CFontDialog(CClientDC 、GetDeviceCaps()、memset、LOGFONT、memcpy、CFont、SelectObject() 、IsStrikeOut())
//CFontDialog( LPLOGFONT lplfInitial = NULL, DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS, CDC* pdcPrinter = NULL, CWnd* pParentWnd = NULL );
// Show the font dialog with 12 point "Times New Roman" as the
// selected font.
/* LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
CClientDC dc(this);
lf.lfHeight = -MulDiv(12, dc.GetDeviceCaps(LOGPIXELSY), 72);
strcpy(lf.lfFaceName, "Times New Roman");
CFontDialog dlg(&lf);
dlg.DoModal();*/
/*
CFontDialog dlg;
if (dlg.DoModal() == IDOK)
{
// Create the font using the selected font from CFontDialog.
LOGFONT lf;
memcpy(&lf, dlg.m_cf.lpLogFont, sizeof(LOGFONT));
CFont font;
VERIFY(font.CreateFontIndirect(&lf));
// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);
// Done with the font. Delete the font object.
font.DeleteObject();
}*/
CString fontmessage="";
CFontDialog dlg;
if( IDOK==dlg.DoModal())
{
fontmessage="字体名称:";
fontmessage+=dlg.GetFaceName();
if(1==dlg.IsStrikeOut())
fontmessage+="字体有删除线";
else
fontmessage+="字体没有删除线";
if(1==dlg.IsUnderline())
fontmessage+="字体有下划线";
else
fontmessage+="字体没有下划线";
if(1==dlg.IsBold())
fontmessage+="字体被加粗";
else
fontmessage+="字体没有被加粗";
if(1==dlg.IsItalic())
fontmessage+="字体是斜体";
else
fontmessage+="字体不是斜体";
AfxMessageBox(fontmessage);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CFontDialog dlg;
LOGFONT lf;
if (dlg.DoModal() == IDOK)
{
dlg.GetCurrentFont(&lf);
HFONT hfont = ::CreateFontIndirect(&lf);
// Convert the HFONT to CFont*.
CFont* pfont = CFont::FromHandle(hfont);
// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(pfont);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);
// Done with the font. Delete the font object.
::DeleteObject(hfont);
}
LOGFONT lf;
if (dlg.DoModal() == IDOK)
{
dlg.GetCurrentFont(&lf);
HFONT hfont = ::CreateFontIndirect(&lf);
// Convert the HFONT to CFont*.
CFont* pfont = CFont::FromHandle(hfont);
// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(pfont);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);
// Done with the font. Delete the font object.
::DeleteObject(hfont);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那个结构体里也有字体等信息的你查MSDN CFontDialog m_cf它的内容中一定有的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询