怎样更改CEdit的字体和背景色??
另外,别的控件都是用同样的方法么?
怎样想对话框或控件中插入图片为背景?

解决方案 »

  1.   

    CWnd::GetFont()
    CWnd::SetFont()
    可以吗?
    加图片要在erasebackground里做吧。
      

  2.   

    更改CEdit的字体和背景色需要从CEdit派生一个类,在消息映射表中加入ON_WM_CTLCOLOR_REFLECT(),
    然后声明并实现下面的成员函数:
    // in CMyEdit.h
    afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);// in CMyedit.cpp
    // 消息处理程序,在每次OnDraw调用之前调用
    HBRUSH CMyedit::CtlColor(CDC* pDC, UINT nCtlColor){
      // TODO: 在此添加命令处理程序代码或调用父类的处理函数
      static CFont m_font;
      if (!(HFONT)m_font) {
        // 第一次运行,在这里创建你需要的字体
        LOGFONT lf;
        GetFont()->GetObject(sizeof(lf), &lf);
        strcpy(lf.lfFaceName ,"黑体");
        m_font.CreateFontIndirect(&lf);
      }  pDC->SelectObject(&m_font);
      pDC->SetTextColor(RGB(0,0,255));  // blue
      pDC->SetBkMode(TRANSPARENT);  return ((HBRUSH)::GetStockObject(DEFAULT_PALETTE));
    }
      

  3.   

    其它控件也是类似,不过更改字体好像还可以用CEdit的一个成员函数SetFont,我没有试过。
      

  4.   

    一般通过自己派生 CEdit 来实现。
    重载 CEdit 的消息 =WM_CTLCOLOR
    加上成员变量:
    CBrush br;修改构造函数为:CMyEdit::CMyEdit()
    {
    br.CreateSolidBrush( RGB(192,192,192) );
    }重载:HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
    // TODO: Change any attributes of the DC here
    pDC->SetBkMode( TRANSPARENT );
    pDC->SetTextColor( RGB(255,0,0) );

    return br;

    // TODO: Return a non-NULL brush if the parent's handler should not be called
    //return NULL;
    }对于其他控间,有些相同,如 CStatic, 有些稍有不同,如 CButton
    对于对话框添加背景,我所知道的,有两种方式:
    1是重写 Dialog 的 WM_PAINT 消息,绘制你自己的图片。
    2是为对话框加一个一样大小的 STATIC ,然后设置属性 Bitmap, 选中你自己的图片。
      

  5.   

    修改字体可以直接通过 SetFont 来实现。
      

  6.   

    怎样改变编辑框和静态文本控件中的文本颜色 
     
    HBRUSH m_hbrush1=CreateSolidBrush(RGB(195,195,146)); 
    HBRUSH m_hbrush2=CreateSolidBrush(RGB(245,245,220)); 
    重载OnCtlColor,在里面判断nCtlColor的类型,下面有段代码,其中m_hbrush1和m_hbrush2是HBRUSH的成员变量,要在OnInitialDialog之中赋值
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here
    if(nCtlColor==CTLCOLOR_DLG) return m_hbrush1;
    if (nCtlColor == CTLCOLOR_STATIC)
    {
    pDC->SetTextColor(RGB(10,10,100));
    pDC->SetBkColor(RGB(195,195,146));
    return m_hbrush1;
    }if (nCtlColor == CTLCOLOR_EDIT)
    {
    pDC->SetBkColor(RGB(245,245,220)); 
    return m_hbrush2;
    }
    if (nCtlColor == CTLCOLOR_LISTBOX)
    {
    pDC->SetBkColor(RGB(245,245,220));
    return m_hbrush2;
    }
    // TODO: Return a different brush if the default is not desired
    return hbr; 
    至于在控件中放入图片,需重载控件类,在这里说不清楚给你个源码你自己看吧,要吗,给我留言并写下e_mail
      

  7.   

    CFont 怎么用!!???
    由例子么??
    谢谢 !?
      

  8.   

    我做了一个程序,显示透明的CStatic,CEdit,CButton.即上述控件的背景色随主窗体的背景色改变而改变。要源代码的,留下地址