刚才为实现CRichEdit的透明派生了一个新类,然后在这个新类中实现了一个setFocus事件,
在setFocus事件中
加入以下代码
long style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);  
style  |= WS_EX_TRANSPARENT;  
    ::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style); 
从而实现了CrichEdit的透明,可是当里面的内容过多出现滚动条时(当设为自动滚动时即没有滚动条时没事),拉动滚动条时里面的字体都变黑了!
不知道各位遇到过这种情况没有?
请指教!谢谢

解决方案 »

  1.   

    取RichEdit的Client矩形,调父窗口的InvalidateRect来刷新。
      

  2.   

    发送一个EM_SETEVENTMASK消息,指定它对那些消息感兴趣,做出相应处理
    例:
    CRichEditCtrlEx m_Rich;
    BOOL CRichEditCtrlEx::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
    LPCTSTR lpszWindowName, DWORD dwStyle,
    const RECT& rect, CWnd* pParentWnd, UINT nID,
    LPVOID lpParam /* = NULL */)
    {
        CWnd* l_pWnd = this ;
        return l_pWnd->CreateEx(dwExStyle, _T( "RichEdit20A" ), NULL, dwStyle, 
                               rect, pParentWnd, nID, NULL );
    }m_Rich.CreateEx(WS_EX_TRANSPARENT, "RICHEDIT20A", "",
    ES_NOHIDESEL|WS_CHILD|WS_VISIBLE|
    ES_MULTILINE| ES_AUTOVSCROLL|
    WS_BORDER|WS_VSCROLL|WS_TABSTOP, rect, this, IDC_RICH, NULL);
    ::SendMessage(m_Rich, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS|ENM_SCROLLEVENTS|ENM_KEYEVENTS);
      

  3.   

    在CRichEdit的派生类CRR中的OnVscroll中的代码如下(想在这个事件中刷新)
    void CRR::OnVscroll() 
    {
    // TODO: Add your control notification handler code here
    CRect rect;
    this->GetClientRect(&rect);
    CWnd *pWnd = GetDlgItem(IDC_RICHEDIT2);
    if (pWnd)
        pWnd->InvalidateRect(rect);
    }是不是不能在这里刷新,若不是的话在哪儿合适呢?写出具体的那几行代码吗?谢谢!
      

  4.   

    四楼的朋友,你代码中的的CRichEditCtrlEx 在VC6.0中好像不能用吧。
    试试了,好像没有这个类。是不是只有VC++.net才有?
      

  5.   

    调其父窗口的函数刷新。
    RECT rt
    this->GetClientRect(&rt);
    this->GetParent->InvalidateRect(&rt);
      

  6.   

    RECT rt;
    this->GetClientRect(&rt);
    this->GetParent()->InvalidateRect(&rt);
      

  7.   

    谢谢,9楼的朋友,可是1.RECT rt; 
    this-> GetClientRect(&rt); 
    this-> GetParent()-> InvalidateRect(&rt);
    把上面代码放到CRR的OnPaint()里后,里面的内容确显示不出来了。2.把下面的代码放到主窗口的OnPaint()中后,
    却发现如下错误:
    error C2227: left of '->InvalidateRect' must point to class/struct/union那应当把这段代码放到哪儿?
    谢谢,麻烦你了!
      

  8.   

    不能放到主窗口,而应放在你自己绘制的CRichEdit的派生类CRR中去实现。
      

  9.   

    1、我放到其构造函数中运行时出现Debug Assertaion Failed的错误。2、放到OnSetfocus() 和OnVscroll() 中时,还是不行。3、放到OnEraseBkgnd(CDC* pDC) 中行,其背景不断闪烁。那应该放到哪个事件中呢?
      

  10.   

    放到OnPaint()中时,里面的文字就显示出来了
      

  11.   

    不好意思,刚说错了是:
    放到OnPaint()中时,里面的文字就显示不出来了
      

  12.   

    刷新的代码放到CRR::OnPaint中的最前面。
      

  13.   

    下面是CRR.cpp的源码
    // RR.cpp : implementation file
    //#include "stdafx.h"
    #include "TransRich.h"
    #include "RR.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    /////////////////////////////////////////////////////////////////////////////
    // CRR
    CRR::CRR()
    {
    }
    CRR::~CRR()
    {
    }
    BEGIN_MESSAGE_MAP(CRR, CRichEditCtrl)
    //{{AFX_MSG_MAP(CRR)
    ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CRR message handlers
    void CRR::OnSetfocus() 
    {
    long style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);  
    style  |= WS_EX_TRANSPARENT;  
            : :SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style); 
    }void CRR::OnPaint() 
    {
        RECT rt; 
        this-> GetClientRect(&rt); 
        this-> GetParent()-> InvalidateRect(&rt);
        CPaintDC dc(this); // device context for painting

    }
    我试了试您说的方法,怎么还不行呢?
    麻烦您帮忙再看看
      

  14.   

    CPaintDC dc(this); // device context for painting 
    这行去掉,换成
    CRichEdit::OnPaint();
      

  15.   

    改后的代码为:void CRR::OnPaint() 
    {
        CRect rt; 
        this-> GetClientRect(&rt); 
        this-> GetParent()-> InvalidateRect(&rt);
        //CPaintDC dc(this); // device context for painting
       CRichEdit::OnPaint();

    }
    可是编译时却出现如下错误:
    error C2653: 'CRichEdit' : is not a class or namespace name我把CRichEdit::OnPaint();改为CRR::OnPaint();后,运行时主窗口却自动消失了。
    这又是怎么回事呢?不好意思,这么晚了还麻烦您。
      

  16.   

    CRichEditCtrl::OnPaint
    调基类函数,我写错了。
      

  17.   

    换成以下代码还是不行呢
    void CRR::OnPaint() 
    {
        CRect rt; 
      this-> GetClientRect(&rt); 
        this-> GetParent()-> InvalidateRect(&rt);
        CRichEditCtrl::OnPaint();
       //CPaintDC dc(this); // device context for painting}
    文字可以显示了,但还是老毛病,拉动滚动条时里面的字变得一团黑。
    不好意思,教研室快关门了,我得回宿舍了
    麻烦你了,有什么问题明天我再发贴
      

  18.   

    void CRR::OnPaint()
    {
        RECT rt;
        this->GetClientRect(&rt);
        this->ClientToScreen(&rt);
        CWnd* parent = this->GetParent();
        parent->ScreenToClient(&rt);
        parent->InvalidateRect(&rt);
        CRichEditCtrl::OnPaint();
    }
      

  19.   

    不好意思,还是不行,开始时显示不了文字,拉动滚动条时里面的字符可以显示一下,可是随即一闪又没有了。
    是不是我自己的源程序有问题??我就用了一个按钮,点击之后
    m_r1.SetWindowText("计算机学院!");(m_r1是用用CRR m_r1初始化后的)
    很简单的一个实验程序。
    这个要有用到我们现在要做的一个项目里,没想到从这儿卡住了,呵