Click here to change the theme.

This is the result of my studies and I cannot gurantee its accuracy but I hope it helps someone. This is quite old and might be outdated.

The following is a summary of what CFrameWnd::LoadFrame does. The parameters are shown in .

  • First it sets CFrameWnd::m_nIDHelp to the nIDResource parameter for use by context-help.
  • Then it gets the resource string with resource id nIDResource.
  • Then it calls the AfxDeferRegisterClass macro to register the window class if it is not already registered.
  • Then LoadFrame calls CFrameWnd::Create(Parameters) which does:
    • loads the menu with resource id of the LoadFrame nIDResource parameter
    • Sets CFrameWnd::m_strTitle to the lpszWindowName parameter
    • Then Create calls CFrameWnd::CreateEx (Parameters) which does:
      • PreCreateWindow
      • AfxHookWindowCreate(this)
      • ::CreateWindowEx(Parameters)
      • AfxUnhookWindowCreate()
  • Sets m_hMenuDefault to the menu for the window
  • Loads the accelerator table with resource id nIDResource
  • if a context was not supplied, it sends a WM_INITIALUPDATE message to all descendant windows

MFC WindowCreate Hook

That does not appear to be much that LoadFrame does; it might appear that a view is never created by LoadFrame. However AfxHookWindowCreate sets a hook that does do more. I do not know the details of how it works but based on the call stack when the view is constructed, the hook results in CFrameWnd::OnCreate being called. I assume this is the mechanism always used to execute OnCreate when a window is created. CFrameWnd::OnCreate calls OnCreateHelper using the LPCREATESTRUCT parameter and the pContext from the LPCREATESTRUCT parameter.

CFrameWnd::OnCreateHelper does the following:

  • Calls CWnd::OnCreate
  • Calls OnCreateClient, which, if a context with a new view class is supplied, calls CreateView (and that is where the view is created) with the context and an id of AFX_IDW_PANE_FIRST
  • Sends (using PostMessage) a WM_SETMESSAGESTRING message to set the status bar message to the string with a resource id of AFX_IDS_IDLEMESSAGE
  • Calls RecalcLayout

Hosted by