当我第一次将Rich Edit控件放在资源窗体上的时候,发现程序根本就不能运行。后来才找到原因,原来Rich Edit 控件是Ole类型的控件。在加载Rich Edit 控件的时候,必须进行初始化。代码如下:
BOOLCTestApp::InitInstance(){
}
用法:
1.设置edit只读属性
2.判断edit中光标状态并得到选中内容(richedit同样适用)
3.在edit最后添加字符串
4.随输入自动滚动到最后一行(richedit同样适用)
5.如何限制edit输入指定字符
6.如何使用richedit
7.如何使用richedit2.0 or richedit3.0
8.改变richedit指定区域的颜色及字体
9.设置行间距(只适用于richedit2.0)
10.richedit插入位图
Q220844:How to insert a bitmap into an RTF document using the RichEdit control in Visual C++ 6.0
http://support.microsoft.com/default.aspx?scid=kb;en-us;220844
http://www.codeguru.com/Cpp/controls/richedit/article.php/c2417/
http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383/
11.richedit插入gif动画
http://www.codeproject.com/richedit/AnimatedEmoticon.asp
12.richedit嵌入ole对象
http://support.microsoft.com/kb/141549/en-us
13.使richedit选中内容只读
http://www.codeguru.com/cpp/controls/richedit/article.php/c2401/
14.打印richedit
http://www.protext.com/MFC/RichEdit3.htm
15.richeidt用于聊天消息窗口
http://www.vckbase.com/document/viewdoc/?id=1087
http://www.codeproject.com/richedit/chatrichedit.asp
http://www.codeguru.com/Cpp/controls/richedit/article.php/c2395/
16.解决richedit的EN_SETFOCUS和EN_KILLFOCUS无响应的问题
http://support.microsoft.com/kb/181664/en-us
17.richedit拼写检查
http://www.codeproject.com/com/AutoSpellCheck.asp
18.改变edit背景色
Q117778:How to change the background color of an MFC edit control
http://support.microsoft.com/kb/117778/en-us
19.当edit控件的父窗口属性是带标题栏WS_CAPTION和子窗口WS_CHILD时,不能设置焦点SetFocus
Q230587:PRB: Can't Set Focus to an Edit Control When its Parent Is an Inactive Captioned Child Window
http://support.microsoft.com/kb/230587/en-us
20. 在Edit中回车时,会退出对话框
选中Edit的风格Want Return。
MSDN的解释如下:
ES_WANTRETURN
21. 动态创建的edit没有边框的问题
22. 一个能显示RTF,ole(包括gif, wmv,excel ,ppt)的例子
http://www.codeproject.com/richedit/COleRichEditCtrl.asp
转自
http://blog.csdn.net/lixiaosan/archive/2006/04/06/652795.aspx
Environment: VC6 SP4, 2000.
Follow these 10 easy steps to build the OutLookRichEdit control:
- Insert a rich edit control into the dialog.
- Call AfxInitRichEdit() in the InitInstance of the App class or in InitDialog.
- If it does not exist, copy OutLookRichEdit.cpp and OutLookRichEdit.h to the project directory.
- Click the menu choice Project-Add to Project-Files and select the above-copied files to add the wrapper class to your project.
- Import the hand cursor into the resource and rename it "IDC_LINK".
- Use Classwizard to add a member variable of the rich edit control (CRichEditCtrl).
-
Include the OutLookRichEdit.h file in the dialog's header file and change the declaration of rich edit member variable, as in
CRichEditCtrl m_ctrlText1;
toCOutLookRichEdit m_ctrlText1;
-
In InitDialog(), add the following code.
m_ctrlText1.SetRawHyperText(_T("Click <%$here$#100#%> to see the about box."));
At this level, if you build the project and run it, you can see the rich edit control with linked text, but nothing would happen if you clicked on the link.
To Show a dialog while the link is clicked, you have to add some more code in the dialog class. Before that, have a closer look at the preceding code and hypertext syntax. The link text is enclosed between the "$" symbols and the corresponding dialog's resource value 100 (About Box), enclosed in "#" symbols.
You can find the #define values of dialogs in the resource.h file.
-
Use ClassWizard to map OnNotify of the dialog and write the corresponding implementation code in .cpp file, like:
BOOL CDEMODlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { NMHDR* pNmHdr = (NMHDR*) lParam; if(IDC_RICHEDIT1 == pNmHdr->idFrom){ switch(pNmHdr->code) { caseIDD_ABOUTBOX: CAboutDlg oDlg; oDlg.DoModal (); break; } } returnCDialog::OnNotify(wParam, lParam, pResult); }
- Now, build and run the project. It is recommended that you set the read-only attribute to the rich edit control.
Downloads
Download demo project - 23 Kb
Download source - 6 Kb
在RichEdit中插入Bitmap
COleDataSource src;
STGMEDIUM sm;
sm.tymed=TYMED_GDI;
sm.hBitmap=hbmp;
sm.pUnkForRelease=NULL;
src.CacheData(CF_BITMAP, &sm);
LPDATAOBJECT lpDataObject =
(LPDATAOBJECT)src.GetInterface(&IID_IDataObject);
pRichEditOle->ImportDataObject(lpDataObject, 0, NULL);
lpDataObject->Release();
字体设置代码
最后添加字体变换函数:
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判断是否选择了内容
BOOL bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (bSelect)
{
}
else
{
}
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
}
在RichEdit中实现超链接
在RichEdit中实现超链接 |
责任编辑:admin 在CBuilder上制作 更新日期:2005-8-6 |
首先在Form上放置一个RichEdit。 在窗体的构造函数中添加以下代码: __fastcall TMainForm::TMainForm(TComponent* Owner) { } 重载窗体的WndProc 1。在.h中添加: 2。在.cpp中添加: //--------------------------------------------------------------------------- void __fastcall TMainForm::WndProc(Messages::TMessage &Message) { |