Changing word wrap mode

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >


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;
	WrapChanged();

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);



Comments

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

    Posted by Legacy on 12/28/2003 12: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);

    or

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

    Oh, you may need this include to do this:

    #include <richedit.h>

    Reply
  • To make CRichEditCtrl wrap correctly in a dialog

    Posted by Legacy on 06/10/2002 12: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!

    Reply
  • How to make the CRichEditCtrl Wrap correctly in chinese characters

    Posted by Legacy on 01/12/2000 12: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?

    Reply
  • CRichEditCtrl wrap

    Posted by Legacy on 01/06/2000 12: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 ?

    Reply
  • Wrapping and Paragraph Format Conflict

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

    Originally posted by: Rizwan Zubairy

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

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

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