Example #1
0
CFormView * CExample10Dlg::CreateFormViewOnTheFly()
{
  CCreateContext  ctx;
  // memebers we do not use, so set them to null
  ctx.m_pNewViewClass = RUNTIME_CLASS(CTestView);
  ctx.m_pNewDocTemplate = NULL;
  ctx.m_pLastView = NULL;
  ctx.m_pCurrentFrame = NULL;

  CFrameWnd * pFrameWnd = (CFrameWnd*) this;
  CFormView * pView = (CFormView *) pFrameWnd->CreateView(&ctx);
  if (pView->GetSafeHwnd() == NULL )
  {
    AfxMessageBox(_T("Failed to create view."));
    pView = NULL;
    return NULL;
  }
  // After a view is created, resize that to
  // have the same size as the dialog.
  
  CRect rc(0, 0, 0, 0);
  GetDlgItem(IDC_STATIC_MARKER)->GetWindowRect(&rc);
  ScreenToClient( &rc );
  pView->MoveWindow(rc);

  pView->OnInitialUpdate();
  pView->ShowWindow(SW_NORMAL);

  return pView;
}