控件:Rich_Edit2.0使⽤⽅法
资料:
⼀:直接看Rich Edit 2.0的属性。
⼆:查看MSDN
三:⽹络资料。
回答者
VC_Edit_Control_VC中Edit Control控件的⽤法
简介摘要:; } 1.设置edit只读属性⽅法⼀:m_edit1.SetReadOnly(TRUE); ⽅法⼆:::SendMessage(m _edit1.m_hWnd,
EM_SETREADONLY, TRUE, 0); 2.判断edit中光标状态并得到选中内容(richedit同样适⽤)
; }
1.设置[she zhi]edit只读[zhi du]属性[shu xing][zhi du shu xing]
⽅法[fang fa]⼀:m_edit1.SetReadOnly(TRUE);
⽅法[fang fa]⼆:::SendMessage(m_edit1.m_hWnd, EM_SETREADONLY, TRUE, 0);
2.判断edit中光标[guang biao]状态[zhuang tai]并得到选中内容(richedit同样适⽤)
int nStart, nEnd;
CString strTemp;
m_edit1.GetSel(nStart, nEnd);
if(nStart == nEnd)
strTemp.Format(_T(" 光标[guang biao]在%d" ), nStart);
AfxMessageBox(strTemp);
else
//得到edit选中的内容
m_edit1.GetWindowText(strTemp);
strTemp = strTemp.Mid(nStart) - strTemp.Mid(nEnd);
AfxMessageBox(strTemp);
注:GetSel后,如果nStart和nEnd,表明光标[guang biao]处于某个位置[wei zhi](直观来看就是光标[guang biao]在闪动);如果nStart和nEnd不相等,表明⽤户[yong hu]在edit中选中了⼀段内容。
3.在edit最后添加字符[zi fu]串[zi fu chuan]
CString str;
m_edit1.SetSel(-1, -1);
m_edit1.ReplaceSel(str);
4.随输⼊[shu ru]⾃动滚动到最后⼀⾏(richedit同样适⽤)
⽅法[fang fa]⼀:(摘⾃msdn)
// The pointer to my edit.
extern CEdit* pmyEdit;
int nFirstVisible = pmyEdit-> GetFirstVisibleLine();
// Scroll the edit control so that the first visible line
// is the first line of text.
if (nFirstVisible > 0)
pmyEdit-> LineScroll(-nFirstVisible, 0);
⽅法[fang fa]⼆:m_richedit.PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
5.如何限制edit输⼊[shu ru]指定字符[zi fu]
可以从CEdit派⽣[pai sheng]⼀个类,添加WM_CHAR消息[xiao xi]映射[ying she]。下⾯⼀个例⼦实现了限定输⼊[shu ru]16进制字符[zi fu]的功能。
void CMyHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
if ( (nChar > = 0 && nChar < = 9) ||
(nChar > = a & & nChar < = f) ||
(nChar > = A && nChar < = F) ||
nChar == VK_BACK ||
nChar == VK_DELETE) //msdn的virtual key
CEdit::OnChar(nChar, nRepCnt, nFlags);
6.如何使⽤richedit
添加AfxInitRichEdit();
CxxxApp::InitInstance()
AfxInitRichEdit();
.............
AfxInitRichEdit()功能:装载RichEdit 1.0 Control (RICHED32.DLL).
7.如何使⽤richedit2.0 or richedit3.0
使⽤原因:由于RichEdit2.0A⾃动为宽字符[zi fu](WideChar),所以它可以解决中⽂[zhong wen]乱码以及⼀些汉字问题[wen ti]
⽅法[fang fa]⼀:(msdn上的做法,适⽤于[yong yu]⽤www.doczj/doc/55cda82e453610661ed9f4f5.html 及以后版本创建的⼯程)
To update rich edit controls in existing Visual C++ applications t o version 2.0,
open the .RC file as text, change the class name of each rich e dit control from " RICHEDIT" to " RichEdit20a" .
Then replace the call to AfxInitRichEdit with AfxInitRichEdit2.
⽅法[fang fa]⼆:以对话框[dui hua kuang]为例:
(1) 增加⼀全局变量[bian liang][quan ju bian liang] HMODULE hMod;
(2) 在CxxxApp::InitInstance()中添加⼀句hMod = LoadLibrary(_T(" rich ed20.dll" ));
在CxxxApp::ExitInstance()中添加⼀句FreeLibrary(hMod);
(3) 在对话框[dui hua kuang]上放⼀个richedit,⽂本[wen ben]⽅式打开.rc⽂件[wen jian]修改[xiu gai]该richedit控件的类名" RICHEDIT" to " RichEdit20a" .
(4) 在对话框[dui hua kuang]头⽂件[wen jian]添加CRichEditCtrl m_ richedit;
在OnInitDialog中添加m_richedit.SubclassDlgItem(IDC_RICHEDI T1, this);
8.改变richedit指定区域[qu yu]的颜⾊及字体[zi ti]
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));控件的使用
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
CFM_ITALIC | CFM_SIZE | CFM_UND ERLINE;
cf.dwEffects = 0;
cf.yHeight = 12*12; //⽂字[wen zi]⾼度
strcpy(cf.szFaceName ,_T(" ⾪书" )); //设置[she zhi]字体[zi ti]
m_richedit1.SetSel(1, 5); //设置[she zhi]处理区域[qu yu]
m_richedit1.SetSelectionCharFormat(cf);
9.设置[she zhi]⾏间距(只适⽤于[yong yu]richedit2.0)
PARAFORMAT2 pf;
pf2.cbSize = sizeof(PARAFORMAT2);
pf2.dwMask = PFM_LINESPACING | PFM_SPACEAFTER;
pf2.dyLineSpacing = 200;
pf2.bLineSpacingRule = 4;
m_richedit.SetParaFormat(pf2);
10.richedit插⼊位图[wei tu]
Q220844:How to insert a bitmap into an RTF document using the RichEdit control i n Visual C++ 6.0
www.doczj/doc/55cda82e453610661ed9f4f5.html /default.asp x?scid=kb; en-us; 220844
www.doczj/doc/55cda82e453610661ed9f4f5.html /Cpp/controls/richedit/article.PHP/c2417/
www.doczj/doc/55cda82e453610661ed9f4f5.html /Cpp/controls/richedit/article.php/c5383/
11.richedit插⼊gif动画[dong hua]
www.doczj/doc/55cda82e453610661ed9f4f5.html /richedit/AnimatedEmoticon.asp
12.richedit嵌⼊ole对象[dui xiang]
www.doczj/doc/55cda82e453610661ed9f4f5.html /kb/141549/en-us
13.使richedit选中内容只读[zhi du]
www.doczj/doc/55cda82e453610661ed9f4f5.html /cpp/controls/richedit/article.php/c2401/
14.打印richedit
www.doczj/doc/55cda82e453610661ed9f4f5.html /MFC/RichEdit3.htm
15.richeidt⽤于[yong yu]聊天[liao tian]消息[xiao xi]窗⼝[chuang kou]
www.doczj/doc/55cda82e453610661ed9f4f5.html /document/viewdoc/?id=1087
www.doczj/doc/55cda82e453610661ed9f4f5.html /richedit/chatrichedit.asp
www.doczj/doc/55cda82e453610661ed9f4f5.html /Cpp/controls/richedit/article.php/c2395/
16.解决richedit的EN_SETFOCUS和EN_KILLFOCUS⽆响应[xiang ying]的问题[wen ti]
www.doczj/doc/55cda82e453610661ed9f4f5.html /kb/181664/en-us
17.richedit拼写检查
www.doczj/doc/55cda82e453610661ed9f4f5.html /com/AutoSpellCheck.asp
18.改变edit背景⾊[bei jing se]
Q117778:How to change the background color of an MFC edit control
www.doczj/doc/55cda82e453610661ed9f4f5.html /kb/117778/en-us
19.当edit控件的⽗窗⼝[chuang kou]属性[shu xing]是带标题栏WS_CAPTION和⼦窗⼝[c huang kou][zi chuang
kou]WS_CHILD时,不能设置[she zhi]焦点SetFocus
Q230587:PRB: Cant Set Focus to an Edit Control When its Parent Is an Inactive Ca ptioned Child Window
www.doczj/doc/55cda82e453610661ed9f4f5.html /kb/230587/en-us
20. 在Edit中回车时,会退出[tui chu]对话框[dui hua kuang]
选中Edit的风格Want Return。
MSDN的解释[jie shi]如下:
ES_WANTRETURN Specifies that a carriage return be inserted when the user pres ses the ENTER key while entering text into a multiple-line edit control in a dialog b ox. Without this style, pressing the ENTER key has the same effect as pressing the dialog boxs default pushbutton. This style has no effect on a single-line edit contro l.
21. 动态[dong tai]创建的edit没有边框[bian kuang]的问题[wen ti]
m_edit.Create(....);
m_edit.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);
22. ⼀个能显⽰[xian shi]RTF,ole(包括gif,wmv,excel ,ppt)的例⼦
www.doczj/doc/55cda82e453610661ed9f4f5.html /richedit/COleRichEditCtrl.asp
如何在RichEdit中实现上标下标
正⽂:
近来有好多朋友问如何在RichEdit中实现上标下标,查了好多资料都没到。今天⽆意间在Delphi区闲逛,看到⼀份实现上下标的⽂章,于是整理成CB语⾔的贴出来。
以下代码已测试通过。在Form中放置⼀个RichEdit,两个Button,完整代码如下:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。