Creating MDI application for the First time!

Im having 2Views, 2Docs and 2childframes
I also got 2 menu-items hooked to 2 different forms (say one Form for persons'details and another Form for company's details). How can i invoke these forms? (Ive got the Form's Id message-maps to the menu), but what code invoke the form??
Something like: OpenDocumentFile(NULL)
I havnt got a clue and im lost to begin with!!
coldestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi coldest,

Creating a new document is done via CDocumentTemplate::CreateNewDocument().
i.e.:

class CMyApp:: public CWinApp {
....
 CMultiDocTemplate *m_pFormTemplate1;
 CMultiDocTemplate *m_pFormTemplate2;
....
};

CMyApp::InitInstance(...)
{
....
m_pFormTemplate1 = new CMultiDocTemplate(
            IDR_FORM1,
            RUNTIME_CLASS(CForm1Doc),
            RUNTIME_CLASS(CForm1Frame),
            RUNTIME_CLASS(CForm1View)
);
AddDocTemplate(m_pFormTemplate1);
m_pFormTemplate2 = new CMultiDocTemplate(
            IDR_FORM2,
            RUNTIME_CLASS(CForm2Doc),
            RUNTIME_CLASS(CForm2Frame),
            RUNTIME_CLASS(CForm2View)
);
AddDocTemplate(m_pFormTemplate2);
....
}

CMyApp::OnAddForm1Doc() // message handler for menu
{
 m_pFormTemplate1->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}

CMyApp::OnAddForm2Doc() // message handler for menu
{
 m_pFormTemplate2->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}

hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
inprasCommented:
Here is a sample code to add templates
      pDocTemplate5 = new CMultiDocTemplate(
            IDR_STATUSVIEW,
            RUNTIME_CLASS(CAppsDoc),
            RUNTIME_CLASS(CChildFrm4), // custom MDI child frame
            RUNTIME_CLASS(CStatusView));

      pDocTemplate6 = new CMultiDocTemplate(
            IDR_STATISTICSVIEW,
            RUNTIME_CLASS(CAppDoc),
            RUNTIME_CLASS(CChildFrm5), // custom MDI child frame
            RUNTIME_CLASS(CStatisticsView));

------------------------------------------
this is how U a document
      CString strDocName;
      CDocTemplate* pSelectedTemplate;
      POSITION pos = GetFirstDocTemplatePosition();
      while(pos != NULL)
      {
            pSelectedTemplate = (CDocTemplate*)GetNextDocTemplate(pos);
            ASSERT(pSelectedTemplate != NULL);
            ASSERT(pSelectedTemplate -> IsKindOf(RUNTIME_CLASS(CDocTemplate)));
            pSelectedTemplate -> GetDocString(strDocName, CDocTemplate :: docName);
            if (strDocName == str)
            {
                  pSelectedTemplate -> OpenDocumentFile(NULL);
                  return TRUE;
            }
      }
0
coldestAuthor Commented:
Thanks a lot zoppo and inpras,
Dear zoppo, I've still got this tiny problem: I cannot invoke my second form using menu!!

-------------This is your fragment---  
CMyApp::OnAddForm2Doc() // message handler for menu
{
 m_pFormTemplate2->CreateNewDocument(); // create a new document with a view and a child frame
 ...
}
------------------------
and I've tried it and nothing is happend!
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ZoppoCommented:
Sorry, forgot to mention following:

the frame is by default created invisible and OnInitialUpdate of the new child is not called. To do this correct do following:

CMyApp::OnAddForm2Doc() // message handler for menu
{
CDocument *pDoc = m_pFormTemplate2->CreateNewDocument();
CFrameWnd *pNewFrame = m_pFormTemplate2->CreateNewFrame( pDoc, NULL );
pFormTemplate2->InitialUpdateFrame( pNewFrame, pDoc, TRUE );
....
}

hope this work now,

ZOPPO
0
coldestAuthor Commented:
Sorry Zoppo, it didnt work and im even more confused!!
It crashes. When i debugged it, on the second line: CreateNewFrame(...)..
it takes me to the Create() function:

//virtual override of CWnd::Create
BOOL CFormView::Create(...)
{
 ......
 //dialog template must exist and be    //invisible with WS_CHILD

ASSERT(FALSE)//invalid dialog template  
              // name

 .....
}


any ideal?

Let me tell you about my classes:

(CChildFrame, CMainFrame, CMDIprogApp)

Two sets of doc,view,frame:

(CMDIprogDoc,CMDIprogView,CMDIprogFrame)
(Cprog2Doc  ,Cprog2View  ,Cprog2Frame)

views base class is     CFormView
frames base class is    CMDIChildWnd
ducs base calss is      CDocument

am i doing something wrong? or could you send me a sample please....

thanks a lot zoppo
yours
coldest
0
ZoppoCommented:
please send me your e-mail to zoppo@cdsgmbh.de, then I'll send you a sample project...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.