zoukankan      html  css  js  c++  java
  • CFontDialog学习

    void CMfcFontDlgDlg::OnBtnFont() 
    {
        // Show the font dialog with all the default settings.
        CFontDialog dlg;
        dlg.DoModal();
    }
    
    void CMfcFontDlgDlg::OnBtnFontSpecial() 
    {
        // 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);
        // The code fragment creates a font based on the information we got from CFontDialog::m_cf variable.
        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();
        }
    }
    
    void CMfcFontDlgDlg::OnBtnFontProperty() 
    {    
        // Get the characteristics
        CFontDialog dlg;
        if (dlg.DoModal() == IDOK)
        {
            // Get the characteristics of the currently selected font, if any.
            LOGFONT lf;
            dlg.GetCurrentFont(&lf);
            TRACE("Face name of the selected font = %s
    ", lf.lfFaceName);
            // Get the face name of the selected font, if any.
            CString facename = dlg.GetFaceName();
            TRACE("Face name of the selected font = %s
    ", facename);
            // Get the style name of the selected font, if any.
            CString stylename = dlg.GetStyleName();
            TRACE("Style name of the selected font = %s
    ", stylename);
            // Get the size of the selected font, if any.
            int size = dlg.GetSize();
            TRACE("The size of the selected font = %d
    ", size);
            // Get the color of the selected font, if any.
            COLORREF color = dlg.GetColor();
            TRACE("Color of the selected font = %8x
    ", color);
            // Get the weight of the selected font, if any.
            int weight = dlg.GetWeight();
            TRACE("Weight of the selected font = %d
    ", weight);
            // Is the selected font displayed with strikeout?
            BOOL strikeout = dlg.IsStrikeOut();
            TRACE("Is the selected font displayed with strikeout? %d
    ", strikeout);
            // Is the selected font underlined?
            BOOL underline = dlg.IsUnderline();
            TRACE("Is the selected font underlined? %d
    ", underline);
            // Is the selected font bold?
            BOOL bold = dlg.IsBold();
            TRACE("Is the selected font bold? %d
    ", bold);
            // Is the selected font italic?
            BOOL italic = dlg.IsItalic();
            TRACE("Is the selected font italic? %d
    ", italic);
        }    
    }
  • 相关阅读:
    UNIX环境下用C语言写静态库与动态库
    C++异常处理
    php 二位数组按某个键值排序
    微信公众号之 code获取
    微信公众号开发第一步token验证
    Nginx下ThinkPHP5的配置方法详解
    ThinkPHP5 在 LNMP 环境下访问出现 HTTP ERROR 500
    php 通过设置session_name 实现控制同意空间内控制多个项目,还有很多其他应用啦
    git 忽略提交某个指定的文件(不从版本库中删除)
    nginx 配置反向代理 (遇见的问题 :单独服务器 多端口,相当于跨域, 获取不到session)
  • 原文地址:https://www.cnblogs.com/MakeView660/p/7704228.html
Copyright © 2011-2022 走看看