Creating the OutLookRichEdit Control
Posted
by Madhu B Nair
on December 30th, 2002
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
- In InitDialog(), add the following code.
- Use ClassWizard to map OnNotify of the dialog and write the corresponding implementation code in .cpp file, like:
- Now, build and run the project. It is recommended that you set the read-only attribute to the rich edit control.
CRichEditCtrl m_ctrlText1;to
COutLookRichEdit m_ctrlText1;
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.
BOOL CDEMODlg::OnNotify(WPARAM wParam,
LPARAM lParam,
LRESULT* pResult)
{
NMHDR* pNmHdr = (NMHDR*) lParam;
if(IDC_RICHEDIT1 == pNmHdr->idFrom){
switch(pNmHdr->code)
{
case IDD_ABOUTBOX:
CAboutDlg oDlg;
oDlg.DoModal ();
break;
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
Downloads
Download demo project - 23 KbDownload source - 6 Kb

Comments
how can i add a new line like chatting line scrolling..
Posted by Legacy on 07/28/2003 12:00amOriginally posted by: min_hoae_kim
Could you please tell me how can I add a new line(like chatting) using SetRawHyperText function?
ReplyHow to keep the link destnation when I change the text?
Posted by Legacy on 06/06/2003 12:00amOriginally posted by: Woolf Yang
Thank you for your work.But,if I change the text ,for example insert some other text before the linked text,then the mouse can't click on the linked text .
ReplyWhold you like to give me an advice or fix it ?
Thanks
Solution to support chinese character
Posted by Legacy on 04/25/2003 12:00amOriginally posted by: yiweihua
Madhu B Nair's work is very much appriciated. Thank him.
I found a very easy way to support Chinese character.
To change the RTF_SKELTON definition:
Original:
//#define RTF_SKELTON _T("{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\fswiss MS Sans Serif;}{\\f1\\froman\\fcharset2 Symbol;}{\\f2\\froman Times New Roman;}{\\f3\\fswiss Arial;}}{\\colortbl\\red0\\green0\\blue0;\\red0\\green0\\blue255;}\\deflang1033\\pard\\plain\\f2\\fs20 <@RAW@>}");
modify font define
change f2\\froman Times New Roman to f2\\f<font supports character shown>
such as (in china) f2\\f宋体. it's ok
#define RTF_SKELTON _T("{\\rtf1\\unicode\\deff0\\deftab720{\\fonttbl{\\f0\\fswiss MS Sans Serif;}{\\f1\\froman\\fcharset2 Symbol;}{\\f2\\f宋体;}{\\f3\\fswiss Arial;}}{\\colortbl\\red0\\green0\\blue0;\\red0\\green0\\blue255;}\\deflang1033\\pard\\plain\\f2\\fs20 <@RAW@>}");
Good luck!
Thank you all!
ReplyRe - Scroll Fix
Posted by Legacy on 04/14/2003 12:00amOriginally posted by: Madhu B Nair
Thank you Reptile, Thank you so much.
Reply
Scroll Fix
Posted by Legacy on 04/13/2003 12:00amOriginally posted by: Reptile
Reply
CFM_LINK flag
Posted by Legacy on 02/10/2003 12:00amOriginally posted by: object
There is CFM_LINK flag in CHARFORMAT2.
If clicked, you receive EN_LINK notify.
Reply
wow great!!!
Posted by Legacy on 01/30/2003 12:00amOriginally posted by: sanjay siva
it's really great to know that richedit is having such flexibility and i appreciate mr Madhu B Nair on his work.
ReplyI have one doubt that is it possible to merge the functionality of a richedit and tree control? plz answer me.
Re-How to add a new line ...
Posted by Legacy on 01/19/2003 12:00amOriginally posted by: Madhu B Nair
Dear Kien ,
It is as simple as adding \n in printf. What you have to do is simply add
\par just after the last word of line. The \par is a rtf directive for new
line. The SetRawHyperText function allows you to add such rich edit magic to
format the text content of COutLookRichEdit. For more information please
visit " CAutoRichEditCtrl - automate rich edit formatting and RTF handling -
Jeremy Iverson "
Let us see how to add new line to following text -
"Click here to continue
and Click here to exit"
"Click <%$here$#100#%> to continue\\par and Click <%$here$#101#%> to exit"
I think this will help you. Feel free to contact me whenever you stuck with
ReplyCOutLookRichEdit.
How to add new line?
Posted by Legacy on 01/14/2003 12:00amOriginally posted by: Kien Bui
Hi,
Very interesting!!!
Could you please tell me how can I add a new line using SetRawHyperText function?
Thanks
Reply-Kien Bui
Good work, but you can use a CHtmlView
Posted by Legacy on 12/30/2002 12:00amOriginally posted by: JEFF ZHANG
Since the main purpose is to highlight and redirect, a CHtmlView implented inside a dialog will be better. Besides RichEdit and HtmlView are all memory glutton.
Reply