Creating the OutLookRichEdit Control

Environment: VC6 SP4, 2000.

Follow these 10 easy steps to build the OutLookRichEdit control:

  1. Insert a rich edit control into the dialog.
  2. Call AfxInitRichEdit() in the InitInstance of the App class or in InitDialog.
  3. If it does not exist, copy OutLookRichEdit.cpp and OutLookRichEdit.h to the project directory.
  4. Click the menu choice Project-Add to Project-Files and select the above-copied files to add the wrapper class to your project.
  5. Import the hand cursor into the resource and rename it "IDC_LINK".
  6. Use Classwizard to add a member variable of the rich edit control (CRichEditCtrl).
  7. Include the OutLookRichEdit.h file in the dialog's header file and change the declaration of rich edit member variable, as in
  8. CRichEditCtrl    m_ctrlText1;
    
    to
    COutLookRichEdit m_ctrlText1;
    
  9. In InitDialog(), add the following code.
  10. 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.

  11. Use ClassWizard to map OnNotify of the dialog and write the corresponding implementation code in .cpp file, like:
  12. 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);
    }
    
  13. 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


Comments

  • how can i add a new line like chatting line scrolling..

    Posted by Legacy on 07/28/2003 12:00am

    Originally posted by: min_hoae_kim

    Could you please tell me how can I add a new line(like chatting) using SetRawHyperText function?

    Reply
  • How to keep the link destnation when I change the text?

    Posted by Legacy on 06/06/2003 12:00am

    Originally 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 .
    Whold you like to give me an advice or fix it ?
    Thanks

    Reply
  • Solution to support chinese character

    Posted by Legacy on 04/25/2003 12:00am

    Originally 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!

    Reply
  • Re - Scroll Fix

    Posted by Legacy on 04/14/2003 12:00am

    Originally posted by: Madhu B Nair

    Thank you Reptile, Thank you so much.

    Reply
  • Scroll Fix

    Posted by Legacy on 04/13/2003 12:00am

    Originally posted by: Reptile

    There are small bugs in OnLButtonDown and OnMouseMove, which cause incorrect hyperlink detection, when rich edit window is scrolled. We should mention current scroll position, for example, in this way:
    
    

    Instead of

    //...
    if(IsPointInsideALink(point,linkInfo))
    {
    //...

    write

    //...
    CSize sOffset(GetScrollPos(SB_HORZ),
    GetScrollPos(SB_VERT));

    if(IsPointInsideALink(point + sOffset,linkInfo))
    {
    //...

    Reply
  • CFM_LINK flag

    Posted by Legacy on 02/10/2003 12:00am

    Originally 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:00am

    Originally 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.
    I have one doubt that is it possible to merge the functionality of a richedit and tree control? plz answer me.

    Reply
  • Re-How to add a new line ...

    Posted by Legacy on 01/19/2003 12:00am

    Originally 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
    COutLookRichEdit.

    Reply
  • How to add new line?

    Posted by Legacy on 01/14/2003 12:00am

    Originally posted by: Kien Bui

    Hi,

    Very interesting!!!
    Could you please tell me how can I add a new line using SetRawHyperText function?

    Thanks
    -Kien Bui

    Reply
  • Good work, but you can use a CHtmlView

    Posted by Legacy on 12/30/2002 12:00am

    Originally 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
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds