同标题,请写出完整代码。多谢了!

解决方案 »

  1.   

    m_static.fontname = "黑体";
    m_static.fontsize = 24;
      

  2.   

    CWnd::SetFont
    void SetFont( CFont* pFont, BOOL bRedraw = TRUE );ParameterspFontSpecifies the new font.bRedrawIf TRUE, redraw the CWnd object.ResSets the window’s current font to the specified font. If bRedraw is TRUE, the window will also be redrawn.
      

  3.   

    错了。应该是:
    CFont font;
    font.CreatePointFont(fontsize*10,fontname);
    m_static.SelectObject(&font);
    CString s;
    m_static.GetWindowText(s);
             m_static.SetWindowText(s);
      

  4.   

    m_font.CreateFont( 20, 0, 0, 0, FW_HEAVY, 0, 0, 0, GB2312_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, "隶书" );
    m_Static.SetFont(&m_font);
      

  5.   

    MyStatic.h:
    class CMyStatic : public CStatic
    {
    // Construction
    public:
    CMyStatic();// Attributes
    public:// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyStatic)
    //}}AFX_VIRTUAL// Implementation
    public:
    BOOL RegisterWindowClass();
    virtual ~CMyStatic(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyStatic)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    private:
    CFont m_Font;
    };MyStatic.cpp:
    CMyStatic::CMyStatic()
    {
    RegisterWindowClass();
    }CMyStatic::~CMyStatic()
    {
    }
    BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
    //{{AFX_MSG_MAP(CMyStatic)
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyStatic message handlersint CMyStatic::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CStatic::OnCreate(lpCreateStruct) == -1)
    return -1;

    VERIFY(m_Font.CreatePointFont(100, "宋体" )); SetFont( &m_Font ); return 0;
    }BOOL CMyStatic::RegisterWindowClass()
    {
    WNDCLASS wndcls; HINSTANCE hInstance; hInstance = AfxGetInstanceHandle(); if ( !GetClassInfo( hInstance, _T( "CMyStatic" ), &wndcls ) )
    {
    GetClassInfo( hInstance, _T( "STATIC" ), &wndcls );
    wndcls.lpszClassName    = _T( "CMyStatic" );        if (!AfxRegisterClass(&wndcls)) {            
                return FALSE;
            }
    } return TRUE;
    }够详细了吧?
    重点是——m_Font的生命周期应该不小于Static的生命周期,否则设置的字体就失效了,所以要将m_Font定义为Static的成员变量。当然你也可以定义为全局变量。