Setting ES_MULTILINE of a CEditView derived class

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: