Help and Support
 

powered byLive Search

PRB: PreCreateWindow() Not Called for CFormView

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:131989
Last Review:November 21, 2006
Revision:3.1
This article was previously published under Q131989

SYMPTOMS

PreCreateWindow() for a CFormView derived class does not get called by the MFC framework during the creation process of a formview.

Back to the top

CAUSE

This is by design. During the creation of the view, the view's Create() function is called by the framework. This then calls CWnd::Create for all the views except CFormView. The CFormView class has its own Create, which calls ::CreateDialog to create the view. CWnd::Create has a call to PreCreateWindow while CFormView::Create does not. As a result, PreCreateWindow( ) for a CFormView derived class does not get called.

Back to the top

RESOLUTION

To change the initial size and location, override the frame window's PreCreateWindow(). To make other changes, override the virtual function, CFormView::Create().

Back to the top

STATUS

This behavior is by design.

Back to the top

MORE INFORMATION

PreCreateWindow() is generally used to alter the default values of the CREATESTRUCT structure before the window is created. This structure contains fields that determine the initial size, location, style, and class among other properties for the window. For CView derived objects, the size, location, and some of the style bits have no effect when modified. In general, the encapsulating frame window's PreCreateWindow() should be overridden and used instead. However, if you need to change the view's CREATESTRUCT, you can override PreCreateWindow() for the view, except for the CFormView (and CRecordView) class.

CFormView (and CRecordView) uses the dialog template to initialize most of its window properties. As a result, CFormView::Create() calls ::CreateDialog(), passing it the dialog template resource as one of its parameters. CView, CEditView, and CScrollView call CWnd::Create() which calls CWnd::CreateEx() where the CREATESTRUCT structure is filled and PreCreateWindow() is called before ::CreateWindowEx().

Typically, there is very little flexibility in changing the default construction parameters for a CFormView after the creation process has started. Some of the parameters that can be modified by PreCreateWindow for other views, like the class name, are ignored in the case of CFormView. See the implementation of CFormView::Create in the Viewform.cpp file for more details.

NOTE: Starting with MFC version 4.0, included with Visual C++ version 4.0, CFormView::Create() calls its PreCreateWindow() to get the prefered extended style. This is done before the modeless dialog is created.

Back to the top

REFERENCES

For more information, please see the MFC source library and Online Books.

Back to the top


APPLIES TO
Microsoft Foundation Class Library 4.2, when used with:
  Microsoft Visual C++ 1.0 Professional Edition
  Microsoft Visual C++ 1.5 Professional Edition
  Microsoft Visual C++ 1.51
  Microsoft Visual C++ 1.52 Professional Edition
  Microsoft Visual C++ 1.0 Professional Edition
  Microsoft Visual C++ 2.0 Professional Edition
  Microsoft Visual C++ 2.1

Back to the top

Keywords: 
kbprb KB131989

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.