我创建了一个MDI,在DrawBackground(CDC *pDC)里面写了一些字然后想通过一个设置对话框,来设置字体。一旦选择了一种字体,屏幕上原来的字就变成那种字体。所以我就在设置对话框里的一个按钮来响应一个函数,用CFontDialog类创建字体选择对话框,并创建了CFont类对象m_Fontvoid CDlgDisplay::OnChooseText()
{
CFontDialog dlg;
dlg.DoModol();
m_Font.CreateFontIndirect(dlg.m_cf.lpLogFont);
}然后想在绘图函数中显示,现在View类里面定义了CFont类对象m_font,
void CTestView::OnDisplay()
{
CDlgDisplay dlg;
if(IDOK==dlg.DoModol())
 {
    m_font=dlg.m_Font;//这行出错,说不能用等号
 }
...
...
DrawBackground(pDC);//在绘制函数里用m_font来写字
...
}编译时,提示错误不能用=,‘Operator ='function is unavaliable.怎么解决呢?谢谢

解决方案 »

  1.   

    The CFont class encapsulates a Windows graphics device interface (GDI) font and provides member functions for manipulating the font. To use a CFont object, construct a CFont object and attach a Windows font to it with CreateFont, CreateFontIndirect, CreatePointFont, or CreatePointFontIndirect, and then use the object’s member functions to manipulate the font.
      

  2.   

    void CTestView::OnDisplay() 

    CDlgDisplay dlg; 
    if(IDOK==dlg.DoModol()) 

        //m_font=dlg.m_Font;//这行出错,说不能用等号 
    //CFont没有重载+操作符
        m_Font.CreateFontIndirect(dlg.m_cf.lpLogFont); } 
      

  3.   

    HFONT m_hfont
    m_hfont = m_Font.CreateFontIndirect(dlg.m_cf.lpLogFont); //用的时候
    CFont* pfont = CFont::FromHandle(m_hfont);
      

  4.   

    HFONT m_hfont 
    同意楼上的,用HFONT把创建的CFont对象保存起来,然后在使用保存的数据就OK了
      

  5.   

    谢谢诶,你说的有道理不过这样的话就不能用m.Font.CreateFontIndirect了,因为这个事CFont类的函数,返回值为0或者非零,而不是句柄
    必须使用SDK函数
    m_hfont = ::CreateFontIndirect(dlg.m_cf.lpLogFont); 
    才行