Attributes of main frame of a doc view/dialog based application can be described in CREATESTRUCT structure. Each memeber of this structure holds the corresponding attributes of a frame window.

typedef struct tagCREATESTRUCT {
    LPVOID      lpCreateParams; /* Create param */
    HINSTANCE   hInstance;      /* Application instance */
    HMENU       hMenu;          /* Handle to menu */
    HWND        hwndParent;     /* Parent Window */
    int         cy;             /* Height */
    int         cx;             /* Width */
    int         y;              /* Y position */
    int         x;              /* X position */
    LONG        style;          /* Window styles */
    LPCSTR      lpszName;       /* Window name */
    LPCSTR      lpszClass;      /* Class name (fixed) */
    DWORD       dwExStyle;      /* Extended style */

PreCreateWindow event

DOC view framework creates CFrameWnd object after that calls PreCreateWindow() event. Verious frame attibutes can be changed in this event. Here is an example of altering style,position and height width of the window.

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    /* Call the base-class version */
   if( !CFrameWnd::PreCreateWindow(cs) )
      return FALSE;

    /* Create a window without min/max buttons or sizable border */ = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;

    /* Size the window to 1/3 screen size and center it */ = ::GetSystemMetrics(SM_CYSCREEN) / 3; = ::GetSystemMetrics(SM_CXSCREEN) / 3; 
    cs.= (( * 3) - / 2; 
    cs.= (( * 3) - / 2;

   return TRUE;

Here is the call stack of PreCreateWindow() from MFC framework.


OnCreate() event

OnCreate() event is an window event triggered by WM_CREATE message. Base function CFrameWnd::OnCreate() is called with same CREATESTRUCT pointer which is already altered in PreCreateWindow(). This is the actual creation of the frame window.

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
  return 0;

Here is the call stack of OnCreate() from MFC framework.


About our authors: Team EQA

Further readings

Where is WinMain() function in MFC application ?

MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.

What is the utility of CWinApp class?

This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...

Basic steps in Win32 GUI Application with source code.

Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.

What is a Window CallBack procedure and what is its utility?

DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.

What are LPARAM and WPARAM in window proc function?

LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.

What are the basic steps of a typical MFC based application?

We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...