我想把一个动态生成的控件改成“宋体”,9号字,该怎么做????

解决方案 »

  1.   

    CFont font;
    font.createfont(...)
    pCtrl->SetFont(&font)
      

  2.   

    LOGFONT logfont;
           CFont *pfont = m_ctrShowMessage.GetFont();
           pfont->GetLogFont( &logfont );
           logfont.lfHeight =logfont.lfHeight * 1.5;
           logfont.lfWidth  = logfont.lfWidth * 1.5;
           logfont.?="宋体";//属性自己查一下
           CFont font;
           font.CreateFontIndirect(&logfont);
           m_ctrShowMessage.SetFont(&font);
      

  3.   

    bjyst2008(追风) 
           logfont.lfHeight =logfont.lfHeight * 1.5;
           logfont.lfWidth  = logfont.lfWidth * 1.5;
    你怎么知道大小要乘1.5倍呢??
      

  4.   

    用你的logfont.lfFaceName="宋体";报错。
     error C2440: '=' : cannot convert from 'char [5]' to 'char [32]'
    改用strcpy通过。不过实际显示效果不对啊,我就是想把控件的字改成跟菜单里的中文一样,怎么弄???
      

  5.   

    想把控件的字改成跟菜单里的中文一样,那更简单
    HFONT hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
    SendMessage(hWnd,WM_SETFONT,(WPARAM)hfont,MAKELPARAM(TRUE,0));
    hWnd为控件句柄
      

  6.   

    ringphone(临风)error C2660: 'SendMessageA' : function does not take 4 parameters
      

  7.   

    ringphone(临风)
    error C2660: 'SendMessageA' : function does not take 4 parameters
      

  8.   

    ::SendMessage(hWnd,WM_SETFONT,(WPARAM)hfont,MAKELPARAM(TRUE,0));
      

  9.   

    HFONT hFont;
    hFont = CreateFont(-9, 0, 0, 0, 400, 0, 0, 0, ANSI_CHARSET,
    OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,  DEFAULT_QUALITY,
    DEFAULT_PITCH || FF_DONTCARE, "宋体");
    SendMessage(hWnd,WM_SETFONT,(DWORD)hFont,TRUE);
      

  10.   

    xiaogengcn(风) 用你这个字变的很小啊,不对吧
      

  11.   

    再试一下这个把,我试了完全可以
          LOGFONT logfont;
           CFont *pfont = m_ctrShowMessage.GetFont();
           pfont->GetLogFont( &logfont );
           logfont.lfHeight =-12;//9号字
           
           strcpy(logfont.lffacename,"宋体");//属性自己查一下
           static CFont font;
            font.deleteobject();
           font.CreateFontIndirect(&logfont);
           m_ctrShowMessage.SetFont(&font);
      

  12.   

    CFont font;
    font.createfont(...)
    pCtrl->SetFont(&font)
      

  13.   

    LOGFONT m_lpMainFontRec;
    HDC hDC = GetDC(hWnd);//你想要几号字,把size替换为相应数字
    m_lpMainFontRec.lfHeight = -MulDiv(size,GetDeviceCaps(hDC,LOGPIXELSY),72);
    ReleaseDC(m_hWnd,hDC);
        m_lpMainFontRec.lfWidth = 0;
       m_lpMainFontRec.lfEscapement = 0;
        m_lpMainFontRec.lfOrientation = 0;
       m_lpMainFontRec.lfWeight = FW_NORMAL;
       m_lpMainFontRec.lfItalic = FALSE;
    m_lpMainFontRec.lfUnderline = FALSE;
       m_lpMainFontRec.lfStrikeOut = FALSE;
       m_lpMainFontRec.lfCharSet = DEFAULT_CHARSET;
        m_lpMainFontRec.lfOutPrecision = OUT_DEFAULT_PRECIS;
       m_lpMainFontRec.lfClipPrecision = CLIP_DEFAULT_PRECIS;
        m_lpMainFontRec.lfQuality = PROOF_QUALITY;
       m_lpMainFontRec.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
    //szFontname是你要的字体,如"宋体"
    strcpy(m_lpMainFontRec.lfFaceName,szFontname);
       
    HFONT m_font = CreateFontIndirect(&m_lpMainFontRec);
    SendMessage(hWnd,WM_SETFONT,(WPARAM)m_hfont,MAKELPARAM(TRUE,0));以上为纯API,所以编译时报参数不对的错误请在函数前加::
      

  14.   

    CFont font;
    font.createfont(...)
    pEdit->SetFont(&font)
    BOOL CreateFont( 
                     int nHeight,           //字体的高度
                     int nWidth,            //字体的宽度
                     int nEscapement,       //字体显示的角度
                     int nOrientation,      //字体的角度
                     int nWeight,           //字体的磅数
                     BYTE bItalic,          //斜体字体
                     BYTE bUnderline,       //带下划线的字体
                     BYTE cStrikeOut,       //带删除线的字体
                     BYTE nCharSet,         //所需的字符集
                     BYTE nOutPrecision,    //输出的精度
                     BYTE nClipPrecision,   //裁减的精度 
                     BYTE nQuality,         //逻辑字体与输出设备的实际
                                            //字体之间的精度
                     BYTE nPitchAndFamily,  //字体间距和字体集
                     LPCTSTR lpszFacename   //字体名称
                   );
      

  15.   

    m_Font.CreateFont(9, 0, 0, 0, FW_NORMAL, 0, 0, 0,
    DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
    DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
    _T("宋体"));pCtrl->SetFont(&m_Font);来晚了一点。根据长期应用的经验,置字宽为 0 指定字高很容易实现汉字“八号”到“初号”字体,而置字高为 0 或两者均不为 0 则要麻烦得多。9 号字就是“小六”号字。
      

  16.   

    enum FontSize
    {
        Eight     = 6,
        LessSix   = 9,     Six   = 10,
        LessFive  = 12,    Five  = 14,
        LessFour  = 16,    Four  = 18,
        LessThree = 20,    Three = 21,
        LessTwo   = 24,    Two   = 29,
        LessOne   = 32,    One   = 34,
        LessZero  = 48,    Zero  = 56
    };