MFC封装类:CFontDialog

核心代码如下:

 1 void CGraphicView::OnFont()
 2 {
 3     CFontDialog dlg;
 4     if( IDOK == dlg.DoModal() )
 5     {
 6         if( m_font.m_hObject )    // 如果m_font对象已经和某个字体资源相关联,要先释放这个资源,之后才能和新的资源进行关联,否则会报错
 7             m_font.DeleteObject();
 8         m_font.CreateFontIndirectW( dlg.m_cf.lpLogFont );
 9         m_strFontName = dlg.m_cf.lpLogFont->lfFaceName;
10         Invalidate();  // 使窗口无效,就会调用OnDraw函数实现重绘,在OnDraw函数中实现重绘操作;
11     }
12 }

效果如下:

posted on 2014-03-20 13:21  可笑痴狂  阅读(4952)  评论(0编辑  收藏  举报