如何从CEdit中拿到字体,我想拿到CFont,或是logfont,我现在用getfont是拿不到字体,还有如何拿到CDC?GetDC好像是不行,CPaintDC dc(this)好像也不大对,主要是这两个dc中拿不到CFont。

解决方案 »

  1.   

    CWnd::GetFont  
    CFont* GetFont( ) const;Return ValueA pointer to a CFont that contains the current font. The pointer may be temporary and should not be stored for later use.
      

  2.   

    我的类是继承自CEdit,在 CEDEditBox::OnChar中
              CDC* pDC = this->GetDC();
    CFont* pFont = this->GetFont();
    LOGFONT lf;
    memset(&lf,0,sizeof(LOGFONT));
    pFont->GetLogFont(&lf);这个时候的lf为全0,我当然是拿不到字体阿
      

  3.   

    我最主要的目的是拿到字宽void CEDEditBox::OnPaint()
    {
    CPaintDC dc(this); 
    CFont font;
    font.CreateFontIndirect(&m_lf);//m_lf.lfHeight = 15;
    CFont* pOldFont = dc.SelectObject(&font);
             CSize size = dc.GetTextExtent(str);//str中是有值的
             //这时size 为(0,0);不知道为什么! 拿不到值我就没有办法进行后续工作。
              dc.SelectObject(pOldFont);
    }