刚才为实现CRichEdit的透明派生了一个新类,然后在这个新类中实现了一个setFocus事件,
在setFocus事件中
加入以下代码
long style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
style |= WS_EX_TRANSPARENT;
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
从而实现了CrichEdit的透明,可是当里面的内容过多出现滚动条时(当设为自动滚动时即没有滚动条时没事),拉动滚动条时里面的字体都变黑了!
不知道各位遇到过这种情况没有?
请指教!谢谢
在setFocus事件中
加入以下代码
long style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
style |= WS_EX_TRANSPARENT;
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
从而实现了CrichEdit的透明,可是当里面的内容过多出现滚动条时(当设为自动滚动时即没有滚动条时没事),拉动滚动条时里面的字体都变黑了!
不知道各位遇到过这种情况没有?
请指教!谢谢
例:
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);
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);
}是不是不能在这里刷新,若不是的话在哪儿合适呢?写出具体的那几行代码吗?谢谢!
试试了,好像没有这个类。是不是只有VC++.net才有?
RECT rt
this->GetClientRect(&rt);
this->GetParent->InvalidateRect(&rt);
this->GetClientRect(&rt);
this->GetParent()->InvalidateRect(&rt);
this-> GetClientRect(&rt);
this-> GetParent()-> InvalidateRect(&rt);
把上面代码放到CRR的OnPaint()里后,里面的内容确显示不出来了。2.把下面的代码放到主窗口的OnPaint()中后,
却发现如下错误:
error C2227: left of '->InvalidateRect' must point to class/struct/union那应当把这段代码放到哪儿?
谢谢,麻烦你了!
放到OnPaint()中时,里面的文字就显示不出来了
// 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
}
我试了试您说的方法,怎么还不行呢?
麻烦您帮忙再看看
这行去掉,换成
CRichEdit::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();后,运行时主窗口却自动消失了。
这又是怎么回事呢?不好意思,这么晚了还麻烦您。
调基类函数,我写错了。
void CRR::OnPaint()
{
CRect rt;
this-> GetClientRect(&rt);
this-> GetParent()-> InvalidateRect(&rt);
CRichEditCtrl::OnPaint();
//CPaintDC dc(this); // device context for painting}
文字可以显示了,但还是老毛病,拉动滚动条时里面的字变得一团黑。
不好意思,教研室快关门了,我得回宿舍了
麻烦你了,有什么问题明天我再发贴
{
RECT rt;
this->GetClientRect(&rt);
this->ClientToScreen(&rt);
CWnd* parent = this->GetParent();
parent->ScreenToClient(&rt);
parent->InvalidateRect(&rt);
CRichEditCtrl::OnPaint();
}
是不是我自己的源程序有问题??我就用了一个按钮,点击之后
m_r1.SetWindowText("计算机学院!");(m_r1是用用CRR m_r1初始化后的)
很简单的一个实验程序。
这个要有用到我们现在要做的一个项目里,没想到从这儿卡住了,呵