见笑了:如何更改编辑控件中显示字体的大小?

解决方案 »

  1.   

    当应用程序启动时使用默认字体:
    应该在视类中定义一个数据成员CFont m_Font,再在视类的OnCreate()中加入字体创建代码:
    // Warning: m_font 应该在视类中定义。
    // 初始化字体
    LOGFONT lf;                        // Used to create the CFont.    memset(&lf, 0, sizeof(LOGFONT));   // Clear out structure.
        lf.lfHeight = 90;                  // Request a 90-pixel-high font
        strcpy(lf.lfFaceName, "隶书");    //    with face name
        m_font.CreateFontIndirect(&lf);    // Create the font.
        this->SetFont(&m_font,TRUE);更改字体:
     static CFont font;
        font.CreatePointFont(90, "宋体");  //此外90不同于lf.lfHeight中的90,此处代表9磅,12像素字体,小五或六号字。
        this->SetFont(&font);  //也可以用控件变量名替代this,以更改控件字体
        
        然后可以再增加一个SetFont命令:
        SetFont()
        {
        LOGFONT lf;
            
        memset(&lf,0,sizeof(LOGFONT));//将lf结构清零
        m_Font.GetLogFont(&lf);  //m_Font已在视类中定义;
        CFontDialog dlg(&lf);    if (dlg.DoModal()==IDOK)
         {
         dlg.GetCurrentFont(&lf);
         m_Font.CreatFontIndirect(&lf);
         SendMessage(WM_SETFONT,(WPARAM)(HFONT)m_Font);
         }
        }
      

  2.   

    GetDlgItem(IDC_EDIT1)->SetFont(&m_font)字体变量要求在窗口显示过程中都有效,最好做为类的成员变量