Virtual Developer Workshop: Containerized Development with Docker

If you are using a CRichEditView derivative, you have built in support for three different word wrap modes. The three modes are:

WrapNone Indicates no automatic word wrapping
WrapToWindow Indicates word wrapping based on the width of the window
WrapToTargetDevice Indicates word wrapping based on the characteristics of the target device

To change the mode you have to assign one of these values to the m_nWordWrap member and then call the WrapChanged() member function. If you don't call the WrapChanged() function the control window is not updated.

	// Code to use with CRichEditView
	// Turn word wrap on
	m_nWordWrap = WrapToWindow;

If you are using the CRichEditCtrl class or a class derived from it, you have neither the m_nWordWrap member variable nor the WrapChanged() member functions. In this case you have to use the SetTargetDevice() function. Although the SetTargetDevice() function is documented, the first two usage shown below isn't, but it is used by MFC itself.
	// Code to use with CRichEditCtrl
	// To turn word wrap off
	SetTargetDevice(NULL, 1);

	// To turn word wrap on - based on window width
	SetTargetDevice(NULL, 0);

	// To turn word wrap on - based on target device (e.g. printer)
	// m_dcTarget is the device context, m_lineWidth is the line width 
	SetTargetDevice(m_dcTarget, m_lineWidth);


  • YES! Can make it wrap in windows and dialog boxes now, no MFC

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

    Originally posted by: Ben

    THANK YOU! I am not using MFC and I have a floating resizable window with a rich text edit control it. I simply could not figure out how to make it wrap words until I read this section. The documentation did not suggest anything obvious. Did not think the target device was the right option to use. Anyway, this turns on word wrap on and should work in a dialog window too:

    SendMessage(hwndRichEditWindow, EM_SETTARGETDEVICE, 0, 0);


    SendMessage(GetDlgItem(hDlg, IDC_RichEdit1), EM_SETTARGETDEVICE, 0, 0);

    Oh, you may need this include to do this:

    #include <richedit.h>

  • To make CRichEditCtrl wrap correctly in a dialog

    Posted by Legacy on 06/10/2002 07:00am

    Originally posted by: Jon Schneider

    1.) Map a CRichEditCtrl variable to your control.
    2.) Call SetTargetDevice(NULL,0) as the article describes.
    3.) Do not forget to change the controls styles! You must set the control to be "multiline" and (most likely you will prefer) "want return" or the above call will not result in the line wrapping you desire!

  • How to make the CRichEditCtrl Wrap correctly in chinese characters

    Posted by Legacy on 01/12/2000 08:00am

    Originally posted by: Philip

    I would like to use it to display chinese big 5 and GB code.
    Even, I set the character format to chinese character, it still cannot wrap correctly. What shall I do?

  • CRichEditCtrl wrap

    Posted by Legacy on 01/06/2000 08:00am

    Originally posted by: Paul Saccasyn

    I would like to have m_lineWidth expressed in number of characters of my CRichEditCtrl.
    How do I know the width of a character of the currently used font ?
    In which unit is m_lineWidth expressed ?

  • Wrapping and Paragraph Format Conflict

    Posted by Legacy on 04/06/1999 07:00am

    Originally posted by: Rizwan Zubairy

    How to change the wrapping in rich edit control when I use right align paragraph formatting?

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date