Setting ES_MULTILINE of a CEditView derived class

December 5, 2008

CEditView class provides functionality of a Windows edit control to MFC applications. If ES_MULTILINE style is set, the edit control shows as many lines as possible to display the embedded text. Otherwise the whole text string is shown on the first line and if required, horizontal scrollbar is also shown.

ES_MULTILINE is one of those edit control styles which can not be changed if an instance of the class is already created. Basically there is no easy way to turn this style on and off once the object has been created. If your class is derived from CEditView and you want to turn on this style, override the PreCreateWindow method of the base class and modify the style field to set ES_MULTILINE.

BOOL CPreView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style |= ES_MULTILINE | ES_AUTOVSCROLL;
return CEditView::PreCreateWindow(cs);
}

Since derived class implementation is called before the base class implementation, the style is set before the object is created. This method can be used to set other styles also.