请知情者指点:关于实现Rich Editl里的disabled属性的功能。 在线等,立结! 如何实现Rich Editl里的disabled属性的功能,即不能选中,没有光标,但是字体不变灰色在CRichEditCtrl类里没找到合适的函数,想问问经验丰富的人们,是否可以用CWnd的函数来实现这个功能。或者用属性也可以。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 EnableWindow来手动把这个控件来disable掉 但是EnableWindow之后,和disabled效果是一样的,字体变灰色了 手动disabled是不是还要进行其他的辅助设置,可是我看enblewindows函数没有什么特别需要设置的地方啊 那就继承CRichEditCtrl , 映射 WM_CHAR删除 CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags); 哈哈,striking(硬撑者)方法独特~,应该是可以的。 自己重载CRichEditCtrl类,增加一个自定义的成员函数,该函数实现让OnChar是否起作用就OK了。 void CRichEditCtrlEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags){// CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);} 首先感谢各位指点:)我已经按照重载类的思路做了,而且也屏蔽了OnChar函数,但是还是达不到效果目前效果是:可以选中显示字体,而且选中后不能消除这个选中状态。继续请教。。 ReadOnly后,可以选中,但不能更改。消除选中状态没问题。关键是阻止光标进入。在ONLBUTTON上做做文章看看。前阵子我也碰到这个问题。希望READONLY后,光标不能进入。不过,这个效果不重要。我做了个右键菜单的RICHEDIT。class CInPlaceRichEdit : public CRichEditCtrl{// Constructionpublic: // CInPlaceRichEdit(CDiagramEntity *pOwner, CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID, // int nRow, int nColumn, CString sInitText, UINT nFirstChar); CInPlaceRichEdit();// Attributespublic: // Operationspublic: //void EndEdit(); //void SetLogFont(LOGFONT &lgft); //void SerCaretForCell(); void SetLineSpace(int LineSpace); BOOL MyCanUndo(); void ShowLineSpace(); void SetPf( PARAFORMAT2 pf );// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CInPlaceRichEdit) public: virtual BOOL PreTranslateMessage(MSG* pMsg); protected: virtual void PostNcDestroy(); //}}AFX_VIRTUAL // Implementationpublic: virtual ~CInPlaceRichEdit(); // Generated message map functionsprotected: //{{AFX_MSG(CInPlaceRichEdit) afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnSetFocus(CWnd* pNewWnd); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnVscroll(); afx_msg void OnSetfocus(); afx_msg void OnEditCopy(); afx_msg void OnEditPaste(); afx_msg void OnEditCut(); afx_msg void OnEditUndo(); afx_msg void OnEditSelectAll(); afx_msg void OnEditDelete(); afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI); afx_msg void OnRButtonDown(UINT nFlags, CPoint point); afx_msg void OnChange(); afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); void CInPlaceRichEdit::OnRButtonDown(UINT nFlags, CPoint point) { TRACE("OnRButtonDown"); //只读不显示菜单 if(!(GetStyle() & ES_READONLY)) { CMenu mnu; //ClientToScreen(&point); //GetParent()->ScreenToClient (&point); ::GetCursorPos(&point); mnu.LoadMenu(IDR_MENURICHEDITCTRL); //设置各种使能 //int tempretu; //刚进入 不能撤消 if( MyCanUndo() ) { mnu.EnableMenuItem(IDD_RICH_UNDO,MF_ENABLED ); } else { mnu.EnableMenuItem(IDD_RICH_UNDO,MF_GRAYED ); } //是否能全选 CString tempcaption; GetWindowText(tempcaption); if(tempcaption.IsEmpty()) { mnu.EnableMenuItem(IDD_RICH_SELECTALL,MF_GRAYED ); } else { mnu.EnableMenuItem(IDD_RICH_SELECTALL,MF_ENABLED ); } //是否能粘贴 if( CanPaste() ) { mnu.EnableMenuItem(IDD_RICH_PASTE,MF_ENABLED ); } else { mnu.EnableMenuItem(IDD_RICH_PASTE,MF_GRAYED ); } //是否有选中 来判断 是否能 剪切复制删除 long tempstart = 0,tempend =0 ; GetSel(tempstart,tempend); if (tempstart ==tempend ) { mnu.EnableMenuItem(IDD_RICH_COPY,MF_GRAYED ); mnu.EnableMenuItem(IDD_RICH_CUT,MF_GRAYED ); mnu.EnableMenuItem(IDD_RICH_DELETE,MF_GRAYED ); } else { mnu.EnableMenuItem(IDD_RICH_COPY,MF_ENABLED ); mnu.EnableMenuItem(IDD_RICH_CUT,MF_ENABLED ); mnu.EnableMenuItem(IDD_RICH_DELETE,MF_ENABLED ); } //mnu.GetSubMenu(1)->CheckMenuItem(IDD_RICH_COPY,MF_CHECKED); mnu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,this); CRichEditCtrl::OnRButtonDown(nFlags, point); }} 这个我拿下来分析一下,现在我想知道的是,当我屏蔽了onchar函数时,我的rich edit的多行显示功能没有了为什么呢? 是否在屏蔽onchar函数的同时需要设置其他的功能呢? 依然没有头绪中...阻止光标进入,似乎可以hidecaret();就是无法消除选中状态,最主要的是,多行显示没有了。setwindowtext之后,只显示回车前第一行文字。 那是因为 自动换行需要你手工去做。光标问题可以考虑 LOCKWINDOW //解决某行单个字符出现乱码 //解决不按回车符时 输多行内容后提交的内容有部分隐藏的问题 CString strfail,title; strLine = ""; GetWindowText(title); //char buf[100]; // Dump every line of text of the edit control. if( !(title.IsEmpty()) ) { //CRect temprect = rect; CSize tempsize; LONG linewidth,lineheight; //总共只有一行 if(1==nLineCount) { strText = title; strLine = strText; } else { for (i=0;i < nLineCount;i++) { int len = LineLength(LineIndex(i));//(m_pRichEdit->LineIndex(i)); { strText = title.Left(len); //strLine += strText; //是否只剩一行 if( title.GetLength() > len ) { if(title.GetAt(len)=='\r') { //手工加入了回车换行 title = title.Right(title.GetLength()-len-2); //若为空行 打印空行 //if(len==0) // strText ="\r\n"; strLine += strText+"\r\n"; } else { //自动换行 title = title.Right(title.GetLength()-len); strLine += strText+"\r\n"; } } else { strLine += title; } } } } } //定义一个字符类型变量 CString strName = _T(""); m_MyEdit.SetWindowText(_T("")); Invalidate(); for(UINT i = 0; i < svec.size(); ++i) { strName = strName + svec[i] + _T("\n"); } m_MyEdit.SetWindowText(strName);这是我控制换行显示的方式在用原有的CRichEditCtrl时候,是有效的但是,继承了这个类,这样就无效了 打印文件的路径抓取方法 问个xml解析结点的问题 P2P编程疑问 请教,在多文档应用程序中,若使主窗口初始化使显示背景图,代码应该加在哪啊??? 消息信使(10)在线等待 关于按扭的消息处理 今天买了两本书,大家看看如何。 enter键消息重载 在win7 64位下面 一个最简单的问题,进来的有分 请问怎么样关闭箝入ocx的网页(在delphi)(这种问题求教,我对不起老板啊) 请高手推荐com书籍! 求助,关于汇编代码的效率问题
自己重载CRichEditCtrl类,增加一个自定义的成员函数,该函数实现让OnChar是否起作用就OK了。
{
// CRichEditCtrl::OnChar(nChar, nRepCnt, nFlags);
}
我已经按照重载类的思路做了,而且也屏蔽了OnChar函数,但是还是达不到效果
目前效果是:可以选中显示字体,而且选中后不能消除这个选中状态。
继续请教。。
关键是阻止光标进入。在ONLBUTTON上做做文章看看。
前阵子我也碰到这个问题。希望READONLY后,光标不能进入。
不过,这个效果不重要。我做了个右键菜单的RICHEDIT。
class CInPlaceRichEdit : public CRichEditCtrl
{
// Construction
public:
// CInPlaceRichEdit(CDiagramEntity *pOwner, CWnd* pParent, CRect& rect, DWORD dwStyle, UINT nID,
// int nRow, int nColumn, CString sInitText, UINT nFirstChar);
CInPlaceRichEdit();
// Attributes
public:
// Operations
public:
//void EndEdit();
//void SetLogFont(LOGFONT &lgft);
//void SerCaretForCell();
void SetLineSpace(int LineSpace);
BOOL MyCanUndo();
void ShowLineSpace();
void SetPf( PARAFORMAT2 pf );
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInPlaceRichEdit)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CInPlaceRichEdit();
// Generated message map functions
protected:
//{{AFX_MSG(CInPlaceRichEdit)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnSetFocus(CWnd* pNewWnd);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnVscroll();
afx_msg void OnSetfocus();
afx_msg void OnEditCopy();
afx_msg void OnEditPaste();
afx_msg void OnEditCut();
afx_msg void OnEditUndo();
afx_msg void OnEditSelectAll();
afx_msg void OnEditDelete();
afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnChange();
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
{
TRACE("OnRButtonDown");
//只读不显示菜单
if(!(GetStyle() & ES_READONLY))
{
CMenu mnu;
//ClientToScreen(&point);
//GetParent()->ScreenToClient (&point);
::GetCursorPos(&point);
mnu.LoadMenu(IDR_MENURICHEDITCTRL); //设置各种使能
//int tempretu; //刚进入 不能撤消
if( MyCanUndo() )
{
mnu.EnableMenuItem(IDD_RICH_UNDO,MF_ENABLED );
}
else
{
mnu.EnableMenuItem(IDD_RICH_UNDO,MF_GRAYED );
} //是否能全选
CString tempcaption;
GetWindowText(tempcaption);
if(tempcaption.IsEmpty())
{
mnu.EnableMenuItem(IDD_RICH_SELECTALL,MF_GRAYED );
}
else
{
mnu.EnableMenuItem(IDD_RICH_SELECTALL,MF_ENABLED );
}
//是否能粘贴
if( CanPaste() )
{
mnu.EnableMenuItem(IDD_RICH_PASTE,MF_ENABLED );
}
else
{
mnu.EnableMenuItem(IDD_RICH_PASTE,MF_GRAYED );
}
//是否有选中 来判断 是否能 剪切复制删除
long tempstart = 0,tempend =0 ;
GetSel(tempstart,tempend);
if (tempstart ==tempend ) {
mnu.EnableMenuItem(IDD_RICH_COPY,MF_GRAYED );
mnu.EnableMenuItem(IDD_RICH_CUT,MF_GRAYED );
mnu.EnableMenuItem(IDD_RICH_DELETE,MF_GRAYED );
}
else
{
mnu.EnableMenuItem(IDD_RICH_COPY,MF_ENABLED );
mnu.EnableMenuItem(IDD_RICH_CUT,MF_ENABLED );
mnu.EnableMenuItem(IDD_RICH_DELETE,MF_ENABLED );
}
//mnu.GetSubMenu(1)->CheckMenuItem(IDD_RICH_COPY,MF_CHECKED); mnu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,this); CRichEditCtrl::OnRButtonDown(nFlags, point);
}
}
阻止光标进入,似乎可以hidecaret();
就是无法消除选中状态,最主要的是,多行显示没有了。setwindowtext之后,只显示回车前第一行文字。
光标问题可以考虑 LOCKWINDOW
CString strfail,title;
strLine = "";
GetWindowText(title);
//char buf[100];
// Dump every line of text of the edit control.
if( !(title.IsEmpty()) )
{
//CRect temprect = rect;
CSize tempsize;
LONG linewidth,lineheight; //总共只有一行
if(1==nLineCount)
{
strText = title;
strLine = strText;
}
else
{ for (i=0;i < nLineCount;i++)
{
int len = LineLength(LineIndex(i));//(m_pRichEdit->LineIndex(i)); { strText = title.Left(len);
//strLine += strText;
//是否只剩一行
if( title.GetLength() > len )
{
if(title.GetAt(len)=='\r')
{
//手工加入了回车换行
title = title.Right(title.GetLength()-len-2);
//若为空行 打印空行
//if(len==0)
// strText ="\r\n";
strLine += strText+"\r\n";
}
else
{
//自动换行
title = title.Right(title.GetLength()-len);
strLine += strText+"\r\n";
}
}
else
{
strLine += title;
}
}
}
}
}
CString strName = _T("");
m_MyEdit.SetWindowText(_T(""));
Invalidate();
for(UINT i = 0; i < svec.size(); ++i)
{
strName = strName + svec[i] + _T("\n");
}
m_MyEdit.SetWindowText(strName);这是我控制换行显示的方式
在用原有的CRichEditCtrl时候,是有效的
但是,继承了这个类,这样就无效了