创建字体(可以创建一个2号的大字体),然后GetDlgItem(IDC_YOUREDIT)->SetFont(&font);

解决方案 »

  1.   

    to EA:那样设置成2号字体,会很有意思
    :)
      

  2.   

    同意 panda_w(好想睡啊!) 的
      

  3.   

    就是先创建一个字体,如:
    CFont textFont;
    textFont.CreateFont(100,100,0,0,700,FALSE,FALSE,0,
    /*ANSI_CHARSET*/1,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
    DEFAULT_PITCH|FF_SWISS,"楷体_GB2312");
    然后把你需要设置字体的那个控件的字体设置为此字体:
       GetDlgItem(IDC_YOUREDIT)->SetFont(&textFont); 
    或者m_message.SetFont(&textFont);
      

  4.   

    头文件先定义字体:
    CFont textFont;
    OnInitDialog()函数中
    假如你的文本编辑框是IDC_TEXT(一定不要设成IDC_STATIC)
    加入以下语句:textFont.CreateFont(100,100,0,0,700,FALSE,FALSE,0,
    /*ANSI_CHARSET*/1,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
    DEFAULT_PITCH¦FF_SWISS,"楷体_GB2312");
    //然后把你需要设置字体的那个控件的字体设置为此字体:
      GetDlgItem(IDC_TEXT)->SetFont(&textFont); 
    在Dialog的OnDestroy函数中释放:
    textFont.DeleteObject();
      

  5.   

    看了一下你的代码。你的m_cfont不能声明为局部变量,而应该声明为类的成员变量。
    你可以在OnInitDialog之前初始化m_cfont,然后使用m_cfont设置控件的字体。注意设置了新的字体之后控件的大小不会变化,你可能需要改变控件的大小以适应新的字体。CFont的析构函数会自动帮你做清除工作。下面是WM_SETFONT的说明
    Dialog boxes do not support DS_SETFONT. Applications can set the font for their controls manually. The WM_SETFONT message applies to all controls, not just those in dialog boxes. The best time for the owner of a dialog box control to set the font of the control is when it receives the WM_INITDIALOG message. The application should call the DeleteObject function to delete the font when it is no longer needed; for example, after it destroys the control. The size of the control does not change as a result of receiving this message. To avoid clipping text that does not fit within the boundaries of the control, the application should correct the size of the control window before it sets the font. When a dialog box uses the DS_SETFONT style to set the text in its controls, the system sends the WM_SETFONT message to the dialog box procedure before it creates the controls. An application can create a dialog box that contains the DS_SETFONT style by calling any of the following functions: 
      

  6.   

    我已经把m_cfont声明为我的CBTreeView类的成员变量,但在这个类中我找不到OnInitDialog()函数!我说了我的主窗口是急于对话框的,而且我是想只改变主窗口中文本编辑框的的字体。你可以在OnInitDialog之前初始化m_cfont,然后使用m_cfont设置控件的字体。///////////////////////////我如果不在OnInitDialog中初始化m_cfont,我要在哪里初始化m_cfont呢?我试了在OnInitUpdate()中初始化,发现可以改变字体,但一打开文件就出错!
      

  7.   

    你的代码基本没有问题,但是SetFont的时机有问题。在CDialog::OnInitDialog和CFormView::OnInitUpdate()之后,才能使用控件的与窗口有关的函数,比如SetFont。
    把你的FormView的构造函数中的SetFont去掉就可以了。
    修改过的代码已经运行成功。
      

  8.   

    很抱歉,还是不行,我还是不明白,
     m_cfont.CreateFont(
       30,                        // nHeight
       15,                        // nWidth
       0,                         // nEscapement
       0,                         // nOrientation
       FW_NORMAL,                 // nWeight
       FALSE,                     // bItalic
       FALSE,                     // bUnderline
       0,                         // cStrikeOut
       ANSI_CHARSET, // DEFAULT_CHARSET,            // nCharSet
       OUT_DEFAULT_PRECIS,        // nOutPrecision
       CLIP_DEFAULT_PRECIS,       // nClipPrecision
       DEFAULT_QUALITY,           // nQuality
       DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
       "Arial");                 // lpszFacename这段代码摆在哪里?是不是我的CBTreeView类中的OnInitUpdate()函数还是CBTreeView类中的的构造函数?
    m_yearbox.SetFont (&m_cfont); 
    m_monthbox.SetFont (&m_cfont); 
    m_daybox.SetFont (&m_cfont); 
    m_nyearbox.SetFont (&m_cfont); 
    m_nmonthbox.SetFont (&m_cfont); 
    m_ndaybox.SetFont (&m_cfont); 
    这段代码摆在哪里?是OnInitUpdate()函数?
    //设置当前日期
    CTime t = CTime::GetCurrentTime();
    m_year=t.GetYear();
    m_month=t.GetMonth();
    m_day=t.GetDay();
    //设置还书日期
        if(m_month==12)
    {
    m_nyear=m_year+1;
    m_nmonth=1;
    }//else
    else   {
    m_nmonth=m_month+1;
    m_nyear=m_year;
    }//else
    m_nday=m_day;
    这段代码摆在哪里?是我的CBTreeView类中的OnInitUpdate()函数还是CBTreeView类中的的构造函数?我希望设置字体后,打开我的btree.dat不会出错,蒋大哥试过了吗?我试过设置字体成功的,但就是遇到打开btree.dat文件出错的问题。蒋大哥如果调试成功了,请把工程发回给我好吗?顺便指出改动的地方和原因,谢谢!
      

  9.   

    对于SDI程序,OnInitUpdate可能调用多次(在每次打开文档的时候)。判断一下
    在OnInitUpdate中:
    if(HFONT(m_cfont)){
    //初始化m_cfont
    }
      

  10.   

    错了,是
    if(!HFONT(m_cfont)){
      

  11.   

    ^_^^_^^_^^_^^_^^_^^_^^_^,谢蒋大哥指点!!原来“对于SDI程序,
    OnInitUpdate可能调用多次(在每次打开文档的时候)”,我又学会了一点知识。很抱歉没有分加给蒋大哥了,下次补上!
    同时也感谢其他给位朋友的帮助!