Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

CFormView in non document/view architecture

Is it possible to use a CFormView derived class in an MDI application without using the document/view architecture.

I have generated a new MDI project with Visual C++ 6.0
and unchecked the 'Document/View architecture support' in the first step of the MFC AppWizard. I wan't only to use CFormView derived classes in my MDI application. I never use the CDocument class.
Avatar of Gandalf32
Gandalf32

You can create a new class derived from CFormView, and overload the CreateWindow member, making it a public function.
Hello,
Yes, it is possible, but you must create the view yourself. I give you a generic view creation function.

// generic view creation function (not in CFrameWnd)
CWnd* CreateNewView(CCreateContext* pContext, CWnd *pParent, CRect& rect, int wID)
{
    CWnd* pWnd = NULL;

    if (pContext != NULL)
    {
            if (pContext->m_pNewViewClass != NULL)
            {
                  pWnd = (CWnd*)pContext->m_pNewViewClass->CreateObject();
                  if (pWnd == NULL)
                  {
                        TRACE1("Error: Dynamic create of view %Fs failed\n",
                              pContext->m_pNewViewClass->m_lpszClassName);
                        return NULL;
                  }
                  ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CWnd)));

                  if (!pWnd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
                        rect, pParent, wID, pContext))
                  {
                        TRACE0("Error: couldn't create view \n");
                        return NULL;
                  }
                  // send initial notification message
                  pWnd->SendMessage(WM_INITIALUPDATE);
            }
    }
    return pWnd;
}

You must have DECLARE_DYNCREATE in your code.

If necessary, I can build a sample.

regards, jean-claude.

Avatar of mike_marquet

ASKER

To jclanz :

How can I use this function to create my CFormView !
Can you build me a sample and send me this sample to
mike.marquet@altavista.net

Thanks.
I will evaluate you later.
To Gandalf32 :

Can you give me an example ?
Hello,

You are right, this function is normaly to build a view without frame (in a dialog). In MDI you have a frame so you can use CreateView() to do this.

I send the sample to your e-mail.

regards, jean-claude.
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why did you grade a "B"? Was there something even more that I should have done?

..B ekiM