信息: 更正 SetFont() 函数,在 MFC 的使用 修改字体
2013-12-20 11:17
274 查看
概要
指定控件中的字体的 SetFont() 成员函数 CWnd 类的更改。在基于 Windows 的应用程序中正常工作的此函数,则必须确保后指定的控件已被破坏,SetFont() 调用中指定的 CFont 对象不销毁直到。
回到顶端 |提供反馈
在 SetFont() 接受一个 CFont 对象作为参数 ; 该控件使用指定的字体来显示其文本。若要将 WM_SETFONT 消息发送到该控件与对应于 CFont 对象字体句柄实现 SetFont() 函数。
应用程序可以删除只在特定的情况下一个 WM_SETFONT 消息中指定字体 ; 这些相同的限制将应用于 CFont 对象 SetFont() 调用中指定。
专门,请勿后已销毁控件将 CWnd 销毁指定的 CFont 对象之前。Windows 不会复制 SetFont() 调用中指定的字体。如果字体被销毁控件将被破坏之前,则会出现不可预知的结果。
例如对于应用程序用来更改的字体对话框使用 SetFont() 时, 应用程序应不销毁 CFont 对象,直到后它已破坏对话框。请在 CFont 对象而不是在类中函数之一进行字体局部变量的派生的对话框类的成员变量。这是最佳的方法,以确保对象存在对话框中的生存期内将 CFont。当应用程序将销毁对话框时,对话框框类析构函数将自动调用 CFont 析构函数删除字体句柄。
若要在对话框中指定的任何控件字体在最佳时间是在 OnInitDialog() 成员函数中。
下面的代码演示如何从 CModalDialog 派生对话框类和使用 SetFont() 成员函数:
指定控件中的字体的 SetFont() 成员函数 CWnd 类的更改。在基于 Windows 的应用程序中正常工作的此函数,则必须确保后指定的控件已被破坏,SetFont() 调用中指定的 CFont 对象不销毁直到。
回到顶端 |提供反馈
更多信息
在 SetFont() 接受一个 CFont 对象作为参数 ; 该控件使用指定的字体来显示其文本。若要将 WM_SETFONT 消息发送到该控件与对应于 CFont 对象字体句柄实现 SetFont() 函数。应用程序可以删除只在特定的情况下一个 WM_SETFONT 消息中指定字体 ; 这些相同的限制将应用于 CFont 对象 SetFont() 调用中指定。
专门,请勿后已销毁控件将 CWnd 销毁指定的 CFont 对象之前。Windows 不会复制 SetFont() 调用中指定的字体。如果字体被销毁控件将被破坏之前,则会出现不可预知的结果。
例如对于应用程序用来更改的字体对话框使用 SetFont() 时, 应用程序应不销毁 CFont 对象,直到后它已破坏对话框。请在 CFont 对象而不是在类中函数之一进行字体局部变量的派生的对话框类的成员变量。这是最佳的方法,以确保对象存在对话框中的生存期内将 CFont。当应用程序将销毁对话框时,对话框框类析构函数将自动调用 CFont 析构函数删除字体句柄。
若要在对话框中指定的任何控件字体在最佳时间是在 OnInitDialog() 成员函数中。
下面的代码演示如何从 CModalDialog 派生对话框类和使用 SetFont() 成员函数:
示例代码
/* * Compiler options needed: None */ class CMyAboutBox : public CDialog { CFont m_font; public: // Constructor -- This code assumes a dialog box // template named "ABOUTDLG" in the application's .RC file. CMyAboutBox(CWnd* pParentWnd = NULL) : CModalDialog("ABOUTDLG", pParentWnd) {}; BOOL OnInitDialog(); }; // OnInitDialog() function -- Called after Windows creates // the dialog box but before it is painted on the screen. BOOL CMyAboutBox::OnInitDialog() { LOGFONT lf; // Used to create the CFont. CDialog::OnInitDialog(); // Call default ::OnInitDialog memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure. lf.lfHeight = 20; // Request a 20-pixel-high font strcpy(lf.lfFaceName, "Arial"); // with face name "Arial". //修正 lstrcpy(lf.lfFaceName,_T("Arial"));
m_font.CreateFontIndirect(&lf); // Create the font. // Use the font to paint a control. This code assumes // a control named IDC_TEXT1 in the dialog box. GetDlgItem(IDC_TEXT1)->SetFont(&m_font); return TRUE; }
相关文章推荐
- 在 MFC 中的 SetFont() 函数的正确使用
- GUI程序如何使用控制台输出调试信息[zz][MFC调用win32窗口显示调试信息,使用AllocConsole 函数 ]
- 如何修改栈结构统计每个DLL的函数使用信息
- MFC调用win32窗口显示调试信息,使用AllocConsole 函数
- [Unity3D]使用OnGUI函数显示状态栏并且使用触发器修改玩家当前信息
- MFC调用win32窗口显示调试信息,使用AllocConsole 函数
- MFC CFont 设置字体大小 等信息的修改
- MFC调用win32窗口显示调试信息,使用AllocConsole 函数
- MFC 编辑框 派生对话框类和使用 SetFont() 成员函数
- MFC中OnInitDialog()函数的使用和使用SetWindowText()修改对话框的名称
- ASP.NET 使用CustomValidator调用js函数动态修改验证TextBox的正则表达式,无刷新
- MFC只修改字体的大小,无需重新设置字体类型
- 在MFC程序中使用控制台输出打印信息
- 在昨天作业的基础上添加 :删除按钮,修改并保存按钮 和 添加按钮。完成这些按钮所对应的功能/新建页面DataXML,使用GridView显示book.xm中的图书信息
- SetupDiGetClassDevs-使用SetupDi系列函数进行设备信息的管理
- 守护进程使用syslog函数打印信息(基于ARM-Linux)
- 用JS实现input中的file标签的样式(当要修改file标签的字体样式时使用)
- 在CComboBox组合框控件中 使用AddString()函数修改下拉列表项却出现乱序
- c# API使用GetVolumeInformation函数获取硬盘信息
- Rock And Roll & Goth 目录 (2005.03.22/ 整理和使用ShitMp3 修改MP3信息)