MFC CFont Sample
来源:互联网 发布:java jsoup多线程爬虫 编辑:程序博客网 时间:2024/05/17 06:39
MFC CFont
CFont class encapsulates the functionalities needed to manipulate the Fonts in Windows programming. A font can be created in 4 ways with a CFont class using CreateFont, CreateFontIndirect, CreatePointFont, or CreatePointFontIndirectfunctions. This CFont Samples page tries to give a piece of sample code for all of the above functions.
CFont Sample for using CFont :: CreateFont:
The following CFont sample illustrates how to create a font using CreateFont function of the CFont class.
CClientDC dc(this);
CFont l_font;
l_font.CreateFont(14, 0, 0, 0, FW_NORMAL,
FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");
CFont* l_old_font = dc.SelectObject(&l_font); dc.TextOut(50, 50, "Hello World");
dc.SelectObject(l_old_font);
// Delete the font object.
l_font.DeleteObject();
In the above CFont Sample, the CreateFont function uses all default parameters (either 0 or Default constants), except for the height parameter. If CreateFont is called as above, the MFC framework will select the best fit parameters by itself and create a font accordingly.
CFont Sample for using CFont :: CreateFontIndirect:
This part of CFont sample illustrates the usage of CreateFontIndirect.
CClientDC dc(this);
CFont l_font;
LOGFONT lf;
lf.lfHeight = 12;
strcpy(lf.lfFaceName, "Arial"); // Need a face name "Arial".
l_font.CreateFontIndirect(&lf);
CFont* l_old_font = dc.SelectObject(&l_font);
dc.TextOut(50, 50, "Hello World");
dc.SelectObject(l_old_font);
// Delete the font object.
l_font.DeleteObject();
The LOGFONT is a structure with all members required for the Font object.
CFont Sample for using CFont :: CreatePointFont:
This part of the sample illustrates the use of CreatePointFont for creating a font.
CClientDC dc(this);
CFont l_font;
l_font.CreatePointFont(140,"Times New Roman");
CFont* l_old_font = dc.SelectObject(&l_font);
dc.TextOut(50, 50, "Hello World");
dc.SelectObject(l_old_font);
// Delete the font object.
l_font.DeleteObject();
The first parameter of the CreatePointFont function is the height of the Font in tenths of a point. The return value of thisfunction is non-zero value if successful.
CFont Sample for using CFont :: CreatePointFontIndirect:
CClientDC dc(this);
CFont l_font;
LOGFONT lf;
lf.lfHeight = 120;
strcpy(lf.lfFaceName, "Arial"); // Need a face name "Arial".
l_font.CreatePointFontIndirect(&lf);
CFont* l_old_font = dc.SelectObject(&l_font);
dc.TextOut(50, 60, "Hello World");
dc.SelectObject(l_old_font);
// Delete the font object.
l_font.DeleteObject();
Usually it is better to use either CreatePointFont or CreatePointFontIndirect functions as they reduce the head-ache of thinking about the width, weight and such parameters.
Also, in the above CFont sample the l_font is deleted in the end. It is a good programming practice as advised by Windows Programming manuals to delete the Objects after removing them from the current device context.
- MFC CFont Sample
- MFC之CFont
- [MFC]绘制文本、CFont类
- MFC CFont字体的使用
- CFont
- CFont
- CFont
- CFont::CreateFont(mfc)字体控制
- MFC 中自定义输出字体CFont和获得系统当前默认字体CFont
- 升级MFC到.NET之一:CFont转换为Font
- MFC CFont 设置字体大小 等信息的修改
- (MFC)CFont部分字体无法使用的问题
- MFC中SetFont(CFont *font)方法容易出错点
- TVSKIN源代码阅读日记(五)--- CFONT CLASS (MFC LIB) & LOGFONT STRUCT(GDI)
- C++/MFC-GDI主要对象(Bitmap、CBrush、CFont、CPalette、CPen和CRgn)
- A Sample for WinExec() in MFC
- DD虚拟键鼠 - MFC Sample
- CFont::CreateFont
- 持续
- java 取得汉字拼音
- java获取路径
- 关于算法的时间复杂度
- Java图片缩小后不失真代码
- MFC CFont Sample
- JSP标签起步
- 程序退出的几种方法
- linux 2.6.32 在arm9(s3c2440)平台的移植2 -- Kconfig和Makefile
- radio控制层的和隐藏
- IT外企那点儿事(7):做一个优秀的基层
- win7时代
- Linux Directory
- pku3258(二分)