All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
visual c++中CFontDialog对话框

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/9 22:38:52 Browse times: 381 Comment times: 0

visual c++中CFontDialog对话框


Head photo

Go homepage
Upload pictures
Write articles

visual c++中CFontDialog对话框

CFontDialog对话框
CFontDialog类对象可以提供一个选择不同字体的对话框,如图1所示。

图1 CFontDialog对话框
CFontDialog类中常用的成员函数如表1所示。

表1 CFontDialog类中常用的成员函数
函 数 名
说 明
GetCurrentFont
返回用户选择的字体
GetFaceName
返回用户在对话框中设置的字体名称
GetSize
返回用户在对话框中设置的字体大小
GetColor
返回用户在对话框中设置的字体颜色
IsStrikeOut
用户在对话框中设置的字体是否带有删除线
IsUnderline
用户在对话框中设置的字体是否带有下划线
IsBold
用户在对话框中设置的字体是否加粗显示
IsItalic
用户在对话框中设置的字体是否加斜显示
GetCurrentFont是常使用的成员函数,它可以返回一个LPLOGFONT结构指针,这个结构记录了用户在对话框中所选择的字体的名称、大小、颜色等信息。
下面例子中,用户可以在窗口中任意位置单击鼠标,系统便会弹出“CfontDialog”对话框,读者可以尽情设置字体的属性。关闭“CfontDialog”对话框后,在用户单击鼠标处出现利用所选择字体显示的字体名称,如图2所示。

图2 CFontDialog实例对话框
程序代码如下:
void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDC* pDC=this->GetDC();
CFontDialog dlg;
dlg.DoModal();
CFont Font;
LOGFONT LogFont;
dlg.GetCurrentFont(&LogFont);
Font.CreateFontIndirect(&LogFont);
COLORREF FontColor;
FontColor=dlg.GetColor();
pDC->SetBkMode(TRANSPARENT); //设置背景透明
pDC->SetTextColor(FontColor);
pDC->SelectObject(&Font);
pDC->TextOut(point.x,point.y,dlg.GetFaceName());
CDialog::OnLButtonDown(nFlags, point);
}





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.