如何只改变编辑框的字体而不改变对话框的字体.
CFont *font;
font.Create();
m_edit.SetFont(font);
这样怎么不行出现非法操作.
应该怎样写代码呢?

解决方案 »

  1.   

    可以把edit强制转化成Cwnd,然后在得到它的dc(GetDC),然后不就想怎么办都可以了么.
      

  2.   

    CFont *pFont= new CFont;
    pFont->CreateFont (height, // Height
                         width,  // Width
                         0,                      // Escapement
                         0,                      // Orientation
                         FW_BOLD,                // Font Weigth
                         FALSE,                  // Italic?
                         FALSE,                  // Underlined?
                         FALSE,                  // Strike out?
                         DEFAULT_CHARSET,       // Character set
                         OUT_DEFAULT_PRECIS,      // Font precision
                         CLIP_DEFAULT_PRECIS,     // Clip precision 
                         PROOF_QUALITY ,          // Font apperance quality
                         FF_SWISS,               // Font pitch and family,
                         strFontName);         // Font face name
                     
             m_edit.SetFont(pFont);
      

  3.   

    to   han012(阿毛)
    我就是这么写的,不行.
      

  4.   

    你和阿毛的不一样,关键要new
      

  5.   

    m_edit.SetFont(font);
    什么时候用的?这时edit窗口是否存在?
      

  6.   

    其中m_font是一个CFont的成员变量  CButton*  pButton = (CButton*)GetDlgItem(IDC_BUTTON1);
      CFont*    pFont = pButton->GetFont();
      LOGFONT   lf;  pFont->GetLogFont(&lf);  lf.lfHeight += 2;  m_font.Detach();
      m_font.CreateFontIndirect(&lf);  pButton->SetFont(&m_font);
    有几点要注意
    1)前面4-5行代码我是从系统取得字体后进行改变的,你完全可以用CreateFont来创建自己的新字体
    2)如果你的m_font要多次调用CreateFontIndirect,那么记住每次调用之前一定要detach将原先的字体handle分离掉,否则会出错。
      

  7.   

    对不起,没看清你用的是编辑框,将CButton* pButton改成CEdit* pEdit就可以了。